mcp-client-cli icon indicating copy to clipboard operation
mcp-client-cli copied to clipboard

Cannot configure llm anthropic

Open marcoeg opened this issue 1 year ago • 3 comments

I have tried the following but without success:

 "llm": {
    "provider": "anthropic",
    "model": "claude-3-7-sonnet-20250219",
    "api_key": "<api-key>,
    "base_url": "https://api.anthropic.com/v1/batches"
  }

Perhaps a documentation issue?

Checked the model name with curl https://api.anthropic.com/v1/models:

 "data": [
    {
      "type": "model",
      "id": "claude-3-7-sonnet-20250219",
      "display_name": "Claude 3.7 Sonnet",
      "created_at": "2025-02-24T00:00:00Z"
    },
    {
      "type": "model",
      "id": "claude-3-5-sonnet-20241022",
      "display_name": "Claude 3.5 Sonnet (New)",
      "created_at": "2024-10-22T00:00:00Z"
    },
...

Supported model providers are: openai, cohere, together, huggingface, mistralai, google_genai, anthropic, bedrock, azure_openai, google_vertexai, groq, ollama, fireworks, bedrock_converse

marcoeg avatar Mar 30 '25 18:03 marcoeg

Tried also other anthropic endpoints such as https://api.anthropic.com/v1/complete.

marcoeg avatar Mar 31 '25 00:03 marcoeg

Not sure if this will help you, but it helped me get both groq and deepseek (via fireworks ai) working. In the cli.py file, in the handle_conversation function, you just delete the default_headers and extra-body portions. Apparently those APIs were not working with the extra headers:

model: BaseChatModel = init_chat_model( model=app_config.llm.model, model_provider=app_config.llm.provider, api_key=app_config.llm.api_key, temperature=app_config.llm.temperature, base_url=app_config.llm.base_url, default_headers={ "X-Title": "mcp-client-cli", "HTTP-Referer": "https://github.com/adhikasp/mcp-client-cli", }, extra_body=extra_body )

So it looks like this:

model: BaseChatModel = init_chat_model( model=app_config.llm.model, model_provider=app_config.llm.provider, api_key=app_config.llm.api_key, temperature=app_config.llm.temperature, base_url=app_config.llm.base_url )

jessemcg avatar Apr 12 '25 13:04 jessemcg

If your error is related to Error: can only concatenate str (not "list") to str Navigate to /mcp_client_cli/output.py Around line 93, change something like:

  # before
   self.last_message += content
   # after
   if isinstance(content, list):
       self.last_message += "".join([c.get("text", "") if isinstance(c, dict) else str(c) for c in content])
   else:
       self.last_message += content

this same config can be used

"llm": {
    "provider": "anthropic",
    "model": "claude-sonnet-4-6",
    "api_key": "<key>,
    "temperature": 0.7
    },

tharakak26-del avatar Feb 24 '26 07:02 tharakak26-del