René's URL Explorer Experiment


Title: A tool returning a non-finite float fails on the client with an error naming the tool · Issue #3341 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: A tool returning a non-finite float fails on the client with an error naming the tool · Issue #3341 · modelcontextprotocol/python-sdk

X Title: A tool returning a non-finite float fails on the client with an error naming the tool · Issue #3341 · modelcontextprotocol/python-sdk

Description: Initial Checks I confirm that I'm using the newest release of my line (verified on 2.0.0) I confirm that I searched for my issue before opening this issue Release line 2.x (current stable). Also reproduces on 1.29.0. Bug description A to...

Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (verified on 2.0.0) I confirm that I searched for my issue before opening this issue Release line 2.x (current stable). Also re...

X Description: Initial Checks I confirm that I'm using the newest release of my line (verified on 2.0.0) I confirm that I searched for my issue before opening this issue Release line 2.x (current stable). Als...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3341

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"A tool returning a non-finite float fails on the client with an error naming the tool","articleBody":"## Initial Checks\n\n- [x] I confirm that I'm using the newest release of my line (verified on 2.0.0)\n- [x] I confirm that I searched for my issue before opening this issue\n\n## Release line\n\n`2.x (current stable)`. Also reproduces on 1.29.0.\n\n## Bug description\n\nA tool returning a non-finite float fails on the client with an error that names\nthe tool. `float(\"inf\")`, `float(\"-inf\")` and `float(\"nan\")` all reproduce it. A\nfinite float is fine.\n\nThe handler returned an ordinary Python float. The value that fails validation is\nproduced by the SDK's own outbound serialization.\n\n## Steps to reproduce\n\n```python\nimport anyio\nfrom mcp.client import Client\nfrom mcp.server.mcpserver import MCPServer\n\nserver = MCPServer(\"probe\")\n\n\n@server.tool()\ndef ratio(a: float, b: float) -> float:\n    \"\"\"Divide a by b.\"\"\"\n    return a / b if b else float(\"inf\")\n\n\nasync def main() -> None:\n    async with Client(server) as client:\n        print(await client.call_tool(\"ratio\", {\"a\": 1.0, \"b\": 2.0}))\n        print(await client.call_tool(\"ratio\", {\"a\": 1.0, \"b\": 0.0}))\n\n\nanyio.run(main)\n```\n\n## Actual behaviour\n\nThe first call returns `structured_content={'result': 0.5}`. The second raises:\n\n```text\nRuntimeError: Invalid structured content returned by tool ratio: None is not of type 'number'\n\nFailed validating 'type' in schema['properties']['result']:\n    {'title': 'Result', 'type': 'number'}\n\nOn instance['result']:\n    None\n```\n\nUncaught, this arrives as two nested `ExceptionGroup`s out of `Client.__aexit__`,\n84 lines in total, with the line naming the tool last. Catching the `RuntimeError`\nleaves the session usable and later calls succeed.\n\nThe value cannot be recovered. `validate_tool_result` runs unconditionally for any\nnon-error result (`client/session.py:1109`, `client/client.py:828`) with no opt-out,\nso the caller never reaches the `CallToolResult` to read either\n`structured_content` or the text block.\n\n## Expected behaviour\n\nEither the value survives the round trip, or the failure names the real cause. At\npresent the message directs the reader to the handler, which is the one component\nbehaving correctly.\n\nThe SDK already rejects non-finite floats explicitly elsewhere, at\n`server/request_state.py:128`, so refusing them at the point of return with a clear\nmessage would match existing practice.\n\n## Root cause\n\n1. `func_metadata.convert_result` builds `structured_content = {'result': inf}`.\n   Correct so far.\n2. `_dump_result` (`server/runner.py:118`) serializes with\n   `model_dump(by_alias=True, mode=\"json\", exclude_none=True)`. Pydantic's JSON mode\n   writes non-finite floats as `null`, since JSON has no `Infinity` or `NaN` and\n   `ser_json_inf_nan` defaults to `\"null\"`. The SDK does not set that setting\n   anywhere.\n3. The client validates `{\"result\": null}` against the generated output schema\n   `{\"result\": {\"type\": \"number\"}}`, which rejects it.\n4. `client/session.py:1155` raises, interpolating the tool name.\n\nThis is server-side and independent of transport, so it is not specific to the\nin-memory client used above.\n\nThe emitted JSON stays valid, so this is not an interoperability problem. The\nproblem is that the value is dropped silently and the diagnostic points at the\nwrong component.\n\nNon-finite floats arise from ordinary arithmetic, including division by zero,\noverflow, `statistics` on degenerate input, and numpy interop, so a handler can\nproduce one without ever writing `float(\"inf\")`.\n\n## Why the tests do not catch it\n\nNo test returns a non-finite float from a tool. `math.inf` appears in the suite\nonly as an unbounded stream buffer size (`tests/client/test_stdio.py:149`,\n`tests/interaction/transports/_bridge.py:120`) and as a rejected TTL input\n(`tests/server/test_request_state.py:355`). The one `-> float` division helper,\n`tests/server/mcpserver/test_tool_manager.py:838`, is marked `# pragma: no cover`.\n\n## Not a duplicate of #3100 or PR #3118\n\n#3100 reports the same end state, an output schema that rejects the SDK's own\nstructured result, but its cause is validation and serialization shapes differing\non aliases and computed fields. This reproduces with a plain `-> float` return and\nno Pydantic model.\n\nPR #3118 moves output schema generation into serialization mode. That does not\nchange this case: a `float` serializes as `number` either way, so `null` still\nfails the schema.\n\n#3224 is also distinct. It concerns nulls injected for absent `NotRequired`\nTypedDict keys, not values destroyed by JSON serialization.\n\n## Python & MCP Python SDK\n\n```text\nPython 3.13.11\nmcp 2.0.0            (also reproduced on main @ 0d921927 and on mcp 1.29.0)\npydantic 2.12.5\nLinux x86_64\n```\n\n---\n\nAI assistance was used to investigate and draft this report.\n","author":{"url":"https://github.com/jayhemnani9910","@type":"Person","name":"jayhemnani9910"},"datePublished":"2026-08-20T07:04:18Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3341"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:263dca58-c2f4-0063-ef55-6ed546e7258d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE0B2:24ACB9:AA399F:E23FFF:6B00E7FA
html-safe-nonce73b51235cdb7aa7f96a796313f7b52759e337edfbbf064a0133cc3c07cf0ec2c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEIyOjI0QUNCOTpBQTM5OUY6RTIzRkZGOjZCMDBFN0ZBIiwidmlzaXRvcl9pZCI6Ijg5MDE4NjM3MTA0MjgwMzA5NzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac6459355578928702c9c418fc8f7008c68974c29dfee8882cae416407f3065b59
hovercard-subject-tagissue:5200669861
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3341/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8ed99109da93e664f894e8cf94249b63775408ac394efcdb9fcf76a00247e3e3/modelcontextprotocol/python-sdk/issues/3341
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8ed99109da93e664f894e8cf94249b63775408ac394efcdb9fcf76a00247e3e3/modelcontextprotocol/python-sdk/issues/3341
og:image:altInitial Checks I confirm that I'm using the newest release of my line (verified on 2.0.0) I confirm that I searched for my issue before opening this issue Release line 2.x (current stable). Also re...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejayhemnani9910
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3341#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3341
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3341
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3341
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3341
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3341
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues308 (308)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
https://github.com/modelcontextprotocol/python-sdk
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3341
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3341
A tool returning a non-finite float fails on the client with an error naming the toolhttps://github.com/modelcontextprotocol/python-sdk/issues/3341#top
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
https://github.com/jayhemnani9910
jayhemnani9910https://github.com/jayhemnani9910
on Aug 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#issue-5200669861
#3100https://github.com/modelcontextprotocol/python-sdk/issues/3100
#3118https://github.com/modelcontextprotocol/python-sdk/pull/3118
#3100https://github.com/modelcontextprotocol/python-sdk/issues/3100
#3118https://github.com/modelcontextprotocol/python-sdk/pull/3118
#3224https://github.com/modelcontextprotocol/python-sdk/issues/3224
claudehttps://github.com/apps/claude
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
on Aug 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#event-29729184786
https://github.com/anneheartrecord
anneheartrecordhttps://github.com/anneheartrecord
on Aug 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#issuecomment-5355365372
Generated output schema uses Pydantic's validation shape while structured output uses its serialization shape #3100https://github.com/modelcontextprotocol/python-sdk/issues/3100
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Aug 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#issuecomment-5359211169
https://github.com/Srivatsa03
Srivatsa03https://github.com/Srivatsa03
on Aug 21, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#issuecomment-5364895773
#3337https://github.com/modelcontextprotocol/python-sdk/issues/3337
claudehttps://github.com/apps/claude
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
on Oct 8, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#event-32781093118
jayhemnani9910https://github.com/jayhemnani9910
not plannedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Oct 23, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3341#event-34082003967
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3341
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3341
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.