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
graphiti_core/llm_client/config.py defines a sensible default:
DEFAULT_TEMPERATURE = 1
class LLMConfig:
def __init__(
self,
temperature: float = DEFAULT_TEMPERATURE, # Works correctly
...
):
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)'
)
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)
- 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:
- 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)'
)
- 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
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
temperatureinconfig.yaml, the API returns a 400 error becauseNoneis passed instead of a valid float.The MCP server's
LLMConfigmodel inmcp_server/src/config/schema.pydefaults temperature toNone:This
Nonevalue is then passed directly to the Anthropic API, which expects a numeric value.Error
Environment
Root Cause
graphiti_core/llm_client/config.pydefines a sensible default:mcp_server/src/config/schema.py(L151-153) overrides this withNone:mcp_server/src/services/factories.py(L206-212) passesNoneexplicitly, overriding the core default:Noneand returns 400.Why This Happens
The
Nonedefault 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
LLMConfigdefaults temperature to1.0.Workaround
Explicitly set temperature in config.yaml:
Suggested Fix
The
Nonedefault exists to support OpenAI reasoning models, but this is the edge case, not the norm. The fix should be:1.0inmcp_server/src/config/schema.py:mcp_server/src/services/factories.pyOpenAI case - detect reasoning models (o1, o3, gpt-5) and omit temperature for those.This way:
Related
temperatureis not supported with this model. #874 (GPT-5 temperature parameter handling)