Skip to content

Input should be a valid string [type=string_type, input_value=123, input_type=int] #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
w0807c opened this issue Mar 19, 2025 · 9 comments

Comments

@w0807c
Copy link

w0807c commented Mar 19, 2025

MCP Server tools code:
`@mcp.tool(description="查询物流信息")
async def query_logistics(order_id: str) -> str:
"""查询物流信息。当用户需要根据订单号查询物流信息时,调用此工具

Args:
order_id: 订单号
Returns:
物流信息的字符串描述
"""

统一的物流信息数据

tracking_info = [
{"time": "2024-01-20 10:00:00", "status": "包裹已揽收",
"location": "深圳转运中心"},
{"time": "2024-01-20 15:30:00", "status": "运输中", "location": "深圳市"},
{"time": "2024-01-21 09:00:00", "status": "到达目的地",
"location": "北京市"},
{"time": "2024-01-21 14:00:00", "status": "派送中",
"location": "北京市朝阳区"},
{"time": "2024-01-21 16:30:00", "status": "已签收",
"location": "北京市朝阳区三里屯"}
]

格式化物流信息

result = f"物流单号:{order_id}\n\n物流轨迹:\n"
for item in tracking_info:
result += f"[{item['time']}] {item['status']} - {item['location']}\n"

return result
MCP client execute code: self._streams_context = sse_client(url=server_url)
streams = await self._streams_context.aenter()

    self._session_context = ClientSession(*streams)
    self.session: ClientSession = await self._session_context.__aenter__()

    # Initialize
    await self.session.initialize()

    # List available tools to verify connection
    print("Initialized SSE client...")
    print("Listing tools...")
    response = await self.session.list_tools()
    tools = response.tools
    print("\nConnected to server with tools:", [tool.name for tool in tools])

    result = await self.session.call_tool("query_logistics", {"order_id":"123"})
    print("Result of query_logistics tool:", result)`

error info:
Connected to server with tools: ['query_logistics']
Result of add tool: meta=None content=[TextContent(type='text', text='Error executing tool query_logistics: 1 validation error for query_logisticsArguments\norder_id\n Input should be a valid string [type=string_type, input_value=123, input_type=int]\n For further information visit https://errors.pydantic.dev/2.10/v/string_type', annotations=None)] isError=True

@Kludex
Copy link
Member

Kludex commented Mar 19, 2025

Can you please format your code, and try to translate to English? 🙏

@w0807c
Copy link
Author

w0807c commented Mar 20, 2025

Can you please format your code, and try to translate to English? 🙏
MCP SDK version: 1.4.1
MCP server code:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("order-mcp-server", log_level="ERROR")
@mcp.tool(description="Query logistics information")
async def query_logistics(order_id: str) -> str:

  //Search for logistics information. 
  //When users need to query logistics information based on the order number, call this tool
  result="";
  return result

if __name__ == "__main__":
    mcp.run(transport="sse")
```
`
MCP client code:
`    self._session_context = ClientSession(*streams)
    self.session: ClientSession = await self._session_context.__aenter__()

    # Initialize
    await self.session.initialize()

    # List available tools to verify connection
    print("Initialized SSE client...")
    print("Listing tools...")
    response = await self.session.list_tools()
    tools = response.tools
    print("\nConnected to server with tools:", [tool.name for tool in tools])

    result = await self.session.call_tool("query_logistics", {"order_id":"123"})
    print("Result of query_logistics tool:", result)`
`
error info :
`Connected to server with tools: ['query_logistics']
Result of add tool: meta=None content=[TextContent(type='text', text='Error executing tool query_logistics: 1 validation error for query_logisticsArguments\norder_id\n Input should be a valid string [type=string_type, input_value=123, input_type=int]\n For further information visit https://errors.pydantic.dev/2.10/v/string_type', annotations=None)] isError=True
`
Data type conversion error

@daviddoran-stripe
Copy link

This is the same as this issue from the original FastMCP repo:
jlowin/fastmcp#62

It was fixed in FastMCP Dec 5th 2024:
jlowin/fastmcp@07fc104

But it looks like in merging FastMCP into the official Python SDK this fix was lost.

@daviddoran-stripe
Copy link

@w0807c This issue is not fixed in this repository. I recommend reopening the issue, if possible.

@JohnUiterwyk
Copy link

@Kludex are you able to reopen this?

ive been able to replicate this bug as well with 1.5.0

the offending line is here:

if isinstance(pre_parsed, str):

@daviddoran-stripe correctly pointed out the fix was not migrated to the mcp sdk.

@Kludex Kludex reopened this Mar 24, 2025
@cola-93
Copy link

cola-93 commented Mar 25, 2025

Same issue here~

@kafkasl
Copy link
Contributor

kafkasl commented Mar 26, 2025

+1

@kafkasl
Copy link
Contributor

kafkasl commented Mar 27, 2025

I opened a PR

This is the same as this issue from the original FastMCP repo: jlowin/fastmcp#62

It was fixed in FastMCP Dec 5th 2024: jlowin/fastmcp@07fc104

But it looks like in merging FastMCP into the official Python SDK this fix was lost.

I opened a PR with the fix you pointed out. Hopefully it will be merged soon. Sonnet 3.7 is clever enough to escape the strings, but other models fail miserably with this bug.

#384

@dsp-ant
Copy link
Member

dsp-ant commented Mar 27, 2025

fixed

@dsp-ant dsp-ant closed this as completed Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants