-
Notifications
You must be signed in to change notification settings - Fork 980
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
Here is my code:
class DRG_DIP_Verify(BaseModel):
pass
@mcp.tool()
async def DRG_DIP_Tools(json_data:DRG_DIP_Verify):
pass
http_app = mcp.http_app()
if __name__ == "__main__":
uvicorn.run("main:http_app", host="0.0.0.0", port=opt.port, workers=opt.workers)
When I call my mcp server through DIFY or other LLM clients, the LLM most of the time can pass parameters correctly, for example:
"params": {
"json_data": {
"age": 26,
"gend": "男",
"medfeeSumamt": 5000,
"iptDays": 8,
"dscgWay": 1,
"diagCode": "I10.9"
}
}
This matches the fastmcp framework’s parameter definition:
arguments: dict[str, Any] | None = None
Here is the framework source code:
class CallToolRequestParams(RequestParams):
"""Parameters for calling a tool."""
name: str
arguments: dict[str, Any] | None = None
model_config = ConfigDict(extra="allow")
However, sometimes the LLM passes malformed parameters, for example:
"params": {
"\"json_data\": {\"age\": 26,\"gend\": \"男\",\"medfeeSumamt\": 5000, \"iptDays\": 8,\"dscgWay\": 1, \"diagCode\": \"I10.9\"}"
}
At this point, the input parameter does not pass the framework’s arguments validation, and the framework throws an exception, which I can’t catch in my code because it’s thrown directly from the framework layer!
My current workaround is to modify the fastmcp source code like this:
class CallToolRequestParams(RequestParams):
"""Parameters for calling a tool."""
name: str
**arguments: dict[str, Any] | str= None**
model_config = ConfigDict(extra="allow")
fastmcp_env\Lib\site-packages\mcp\types.py
# fastmcp_env\Lib\site-packages\mcp\types.py
class CallToolRequestParams(RequestParams):
"""Parameters for calling a tool."""
name: str
arguments: dict[str, Any] | None = None
model_config = ConfigDict(extra="allow")
Additional Context
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working