Problem Description
Whenever I create an MCP server using fastmcp
, and in my tools when I add a Pydantic model as an argument, Cursor throws an error when it tries to call the tool:
Logs in Cursor:
{
"clientMessage": "Invalid type for parameter 'agent' in tool get_agent_model",
"modelMessage": "Parameter 'agent' must be of type undefined, got object",
"actualError": "Type mismatch for get_agent_model.agent: expected undefined, got object"
}
It seems to try to pass the correct object. I checked the tool call in Cursor logs:
{
"params": {
"case": "mcpParams",
"value": {
"tools": [
{
"name": "get_agent_model",
"description": "\n An AI assistant that helps gather agent details and return the agent model\n \n # Rules\n - Ask the user for the agent name\n - Ask the user for the agent description\n \n Then return the agent model JSON\n\n Args:\n agent: The agent to get the model for\n Returns:\n agent: The agent to get the model for\n ",
"parameters": "{\"agent\":{\"name\":\"RandomAgent\",\"description\":\"An experimental agent designed to explore random data patterns and generate unexpected insights.\"}}",
"serverName": "mcp_test"
}
]
}
}
}
Example Code
Example using Pydantic Model as Input
from mcp.server.fastmcp import FastMCP
from pydantic import BaseModel, Field
mcp = FastMCP("test-mcp")
class Agent(BaseModel):
"""Agent class for managing agent definitions."""
name: str = Field(..., description="Name of the agent")
description: str = Field("", description="Description of the agent")
@mcp.tool()
def get_agent_model(agent: Agent):
"""
An AI assistant that helps gather agent details and return the agent model
# Rules
- Ask the user for the agent name
- Ask the user for the agent description
Then return the agent model JSON
Args:
agent: The agent to get the model for
Returns:
agent: The agent to get the model for
"""
return agent
def main():
mcp.run(transport="stdio")
Example without Using Pydantic Model as Input
I tried using the tool without a Pydantic model as an argument, and it works fine.
@mcp.tool()
def get_agent_model(name: str, description: str):
"""
An AI assistant that helps gather agent details and return the agent model
# Rules
- Ask the user for the agent name
- Ask the user for the agent description
Then return the agent model JSON
Args:
name: The name of the agent
description: The description of the agent
Returns:
agent: The agent to get the model for
"""
return Agent(name=name, description=description)
Question
This works fine in Claude Desktop. Is this a current limitation in Cursor?