Title: Strings parameters tool containing serialized JSON objects are automatically decoded · Issue #1112 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Strings parameters tool containing serialized JSON objects are automatically decoded · Issue #1112 · modelcontextprotocol/python-sdk
X Title: Strings parameters tool containing serialized JSON objects are automatically decoded · Issue #1112 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description I have a tool function...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1112
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Strings parameters tool containing serialized JSON objects are automatically decoded","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\nI have a tool function in a MCP server that accepts an input parameter (\"data\") of type string (str); if a client uses a serialiazed JSON as content of this parameter it gets the error message:\n\n`Tool call result: meta=None content=[TextContent(type='text', text=\"Error executing tool print_data: 1 validation error for print_dataArguments\\ndata\\n Input should be a valid string [type=string_type, input_value={'message': 'hello'}, input_type=dict]\\n For further information visit https://errors.pydantic.dev/2.11/v/string_type\", annotations=None, meta=None)] structuredContent=None isError=True` \n\nI suspect that somewhere the string is decoded automatically to a dict.\n\nIt is the same behavior with both stdio and streamable-http transports.\n\n### Example Code\n\n```Python\n# server.py\n\nfrom mcp.server.fastmcp import FastMCP\nimport loguru\nimport time\nimport json\n\nmcp = FastMCP(\"test-server\", \"0.0.1\")\n\n\n@mcp.tool()\ndef print_data(data: str) -\u003e str:\n \"\"\"\n Print the data.\n \"\"\"\n loguru.logger.warning(f\"Received data: {data} (type: {type(data)})\")\n return f\"data: {data}\"\n\n\nif __name__ == \"__main__\":\n import sys\n transport = sys.argv[1] if len(sys.argv) \u003e 1 else \"stdio\"\n if transport != \"stdio\" and transport != \"streamable-http\":\n raise ValueError(\"Transport must be 'stdio' or 'streamable-http'\")\n mcp.run(transport=transport)\n\n# stdio_client.py\nfrom mcp import ClientSession, StdioServerParameters, types\nfrom mcp.client.stdio import stdio_client\nimport json\n\nserver_params = StdioServerParameters(\n command=\"python\",\n args=[\"-u\", \"server.py\"],\n env=None,\n)\n\n\nasync def run():\n async with stdio_client(server_params) as (read, write):\n async with ClientSession(read, write) as session:\n await session.initialize()\n args = {\"data\": json.dumps({\"message\": \"hello\"})}\n result = await session.call_tool(\"print_data\", arguments=args)\n print(\"Tool call result:\", result)\n\n\nif __name__ == \"__main__\":\n import asyncio\n asyncio.run(run())\n \n# http_client.py\nfrom mcp.client.streamable_http import streamablehttp_client\nfrom mcp import ClientSession\nimport json\n\nasync def main():\n async with streamablehttp_client(\"http://localhost:8000/mcp\") as (\n read_stream,\n write_stream,\n _,\n ):\n async with ClientSession(read_stream, write_stream) as session:\n await session.initialize()\n args = {\"data\": json.dumps({\"message\": \"hello\"})}\n tool_result = await session.call_tool(\"print_data\", arguments=args)\n print(\"Tool call result:\", tool_result)\n\nif __name__ == \"__main__\":\n import asyncio\n asyncio.run(main())\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\nPython 3.13.5 and 3.12.11\nMCP SDK 1.10.1\n```","author":{"url":"https://github.com/cjg","@type":"Person","name":"cjg"},"datePublished":"2025-07-09T20:13:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1112/python-sdk/issues/1112"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:53715857-2157-6e94-9b85-861bacfc3eb9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9A6:ECA42:57B2B1:76436A:6A61209D |
| html-safe-nonce | 0ca6e6d500be07b222f70e91c9e2087645f8dc35cd81af1c1d1c0800d4f09276 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUE2OkVDQTQyOjU3QjJCMTo3NjQzNkE6NkE2MTIwOUQiLCJ2aXNpdG9yX2lkIjoiODM1ODkwNDc0MjQwNTAyMTg1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 240d17db30d956b2e71e97adbb1709bcde0dc0daa74f3013ec5a1c5f101eb442 |
| hovercard-subject-tag | issue:3217024185 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/1112/issue_layout |
| twitter:image | https://opengraph.githubassets.com/754118b078251e7c6359c645f8ce44740ebc9e35cc92391af786da990d835fcc/modelcontextprotocol/python-sdk/issues/1112 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/754118b078251e7c6359c645f8ce44740ebc9e35cc92391af786da990d835fcc/modelcontextprotocol/python-sdk/issues/1112 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cjg |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d9987c85f924dc5597480f737e023a6e985b0316e672f00513eb4ba440d87ba |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d38dc1dac7b5a5d0788e068e080820de6de90a28 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width