Skip to content

[BUG] MCP Server: Anthropic provider fails with 400 error when temperature not explicitly set #1103

Description

@barweiss45

MCP Server: Anthropic provider fails with 400 error when temperature not explicitly set in config

Description

When using the Anthropic LLM provider without explicitly setting temperature in config.yaml, the API returns a 400 error because None is passed instead of a valid float.

The MCP server's LLMConfig model in mcp_server/src/config/schema.py defaults temperature to None:

temperature: float | None = Field(
    default=None, description='Temperature (optional, defaults to None for reasoning models)'
)

This None value is then passed directly to the Anthropic API, which expects a numeric value.

Error

Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'temperature: Input should be a valid number'}}

Environment

  • graphiti-mcp-server v0.24.3
  • graphiti-core v0.24.3
  • Provider: Anthropic (claude-sonnet-4-5-20250929)

Root Cause

  1. graphiti_core/llm_client/config.py defines a sensible default:
DEFAULT_TEMPERATURE = 1

class LLMConfig:
    def __init__(
        self,
        temperature: float = DEFAULT_TEMPERATURE,  # Works correctly
        ...
    ):
  1. mcp_server/src/config/schema.py (L151-153) overrides this with None:
temperature: float | None = Field(
    default=None, description='Temperature (optional, defaults to None for reasoning models)'
)
  1. mcp_server/src/services/factories.py (L206-212) passes None explicitly, overriding the core default:
llm_config = GraphitiLLMConfig(
    api_key=api_key,
    model=config.model,
    temperature=config.temperature,  # Passes None, overriding core default
    max_tokens=config.max_tokens,
)
return AnthropicClient(config=llm_config)
  1. Anthropic API receives None and returns 400.

Why This Happens

The None default was added to support OpenAI reasoning models (o1, o3, gpt-5) which reject the temperature parameter entirely. However, the implementation is backwards - the edge case (OpenAI reasoning models) drives the default, breaking the normal case (all other providers).

When using graphiti-core directly (without MCP server), the default works correctly because the core's LLMConfig defaults temperature to 1.0.

Workaround

Explicitly set temperature in config.yaml:

llm:
  provider: "anthropic"
  model: "claude-sonnet-4-5-20250929"
  temperature: 1.0

Suggested Fix

The None default exists to support OpenAI reasoning models, but this is the edge case, not the norm. The fix should be:

  1. Change the schema default to 1.0 in mcp_server/src/config/schema.py:
temperature: float | None = Field(
    default=1.0, description='Temperature (optional, set to None for OpenAI reasoning models)'
)
  1. Handle OpenAI reasoning models explicitly in mcp_server/src/services/factories.py OpenAI case - detect reasoning models (o1, o3, gpt-5) and omit temperature for those.

This way:

  • Anthropic/Gemini/Groq work out of the box with sensible default
  • OpenAI reasoning models are handled as the exception they are
  • Users can still override temperature in config if needed

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions