René's URL Explorer Experiment


Title: Bug: task_result_handler.py serializes None optional fields as JSON null, breaking Node SDK Zod validation · Issue #2539 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Bug: task_result_handler.py serializes None optional fields as JSON null, breaking Node SDK Zod validation · Issue #2539 · modelcontextprotocol/python-sdk

X Title: Bug: task_result_handler.py serializes None optional fields as JSON null, breaking Node SDK Zod validation · Issue #2539 · 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 Bug: task_result_handl...

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/2539

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: task_result_handler.py serializes None optional fields as JSON null, breaking Node SDK Zod validation","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\n Bug: task_result_handler.py serializes None optional fields as JSON null,\n  breaking Node SDK Zod validation\n\n  What the spec says\n\n  The MCP spec defines TextContent with optional fields:\n\n  interface TextContent {\n    type: \"text\";\n    text: string;\n    annotations?: Annotations;  // optional — may be absent\n    _meta?: Record\u003cstring, unknown>;  // optional — may be absent\n  }\n\n  \"Optional\" in the spec means the field may be absent from the JSON. Both SDKs\n  agree on this:\n  - Python SDK's TextContentSchema defines annotations and _meta with\n  Optional[...] = None\n  - Node SDK's TextContentSchema defines them with .optional() — accepts\n  undefined (absent) but not null\n\n  What the Python SDK does\n\n  The Python SDK has two serialization paths for CallToolResult:\n\n  1. Normal responses (_send_response in session.py): uses\n  model_dump(by_alias=True, mode=\"json\", exclude_none=True). This correctly omits\n   None fields from the JSON. Works fine.\n  2. Task result delivery (handle in task_result_handler.py, line 131): uses\n  result.model_dump(by_alias=True) without exclude_none=True. This serializes\n  None fields as explicit JSON null:\n\n  # task_result_handler.py line 131\n  result_data = result.model_dump(by_alias=True)  # ← missing exclude_none=True\n\n  Produces:\n  {\n    \"content\": [{\n      \"type\": \"text\",\n      \"text\": \"counted to 20\",\n      \"annotations\": null,\n      \"_meta\": null\n    }],\n    \"isError\": false\n  }\n\n  What breaks\n\n  The Node SDK's requestStream polls tasks/result when a task completes, then\n  parses the response with CallToolResultSchema. The Zod discriminated union for\n  content blocks uses:\n\n  annotations: AnnotationsSchema.optional()  // accepts undefined, rejects null\n  _meta: z.record(z.string(), z.unknown()).optional()  // accepts undefined,\n  rejects null\n\n  null ≠ undefined in Zod. The parse fails:\n  \"expected object, received null\" at path [\"annotations\"]\n  \"expected record, received null\" at path [\"_meta\"]\n\n  This kills the task result stream. The runtime falls back to polling tasks/get\n  + tasks/result, but by then the result may already be consumed.\n\n  Fix\n\n  One line — add exclude_none=True to the model_dump call in\n  task_result_handler.py:\n\n  # Before (line 131):\n  result_data = result.model_dump(by_alias=True)\n\n  # After:\n  result_data = result.model_dump(by_alias=True, exclude_none=True)\n\n  This matches the pattern used everywhere else in the SDK (_send_response,\n  send_notification).\n\n  Reproduction\n\n  1. Python MCP server with a task-aware tool that returns\n  CallToolResult(content=[TextContent(type=\"text\", text=\"hello\")])\n  2. Node MCP client connects and calls the tool with task: {}\n  3. Task completes → client calls tasks/result → Zod parse fails on annotations:\n   null\n\n### Example Code\n\n```Python\n\n```\n\n### Python & MCP Python SDK\n\n```Text\n- mcp (Python): 1.27.0\n  - @modelcontextprotocol/sdk (Node): 1.29.0\n```","author":{"url":"https://github.com/rynowak","@type":"Person","name":"rynowak"},"datePublished":"2026-05-04T23:07:55Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/2539"}

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:73422b8b-9878-f16a-ee9f-1c2b4fdc65d3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9392:9EAA1:42EF8E:58BA37:6AFCEAFD
html-safe-noncedbe65ac28171e9709531d8ff539072ae4a822a97b1aeb60f3937f42d615bd574
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzkyOjlFQUExOjQyRUY4RTo1OEJBMzc6NkFGQ0VBRkQiLCJ2aXNpdG9yX2lkIjoiMTM5MjkyMTA2MTk3MTc4MjM5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacda235f0720f05402462991572605f5c2b2291412365fd0329ca4d752b695b69d
hovercard-subject-tagissue:4380268656
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/2539/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d5505564d536425bb709e5084a5bf42af84e72eec60cf423cbdc5c0858f336f8/modelcontextprotocol/python-sdk/issues/2539
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d5505564d536425bb709e5084a5bf42af84e72eec60cf423cbdc5c0858f336f8/modelcontextprotocol/python-sdk/issues/2539
og:image:altInitial 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerynowak
hostnamegithub.com
expected-hostnamegithub.com
None99aede4c5f55ec5cf06666a8c9e03ebf9f85f7231223e7f1c38c16e5504835b3
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
releaseecfd63ca125ec74b42f74eeb158b3fa081c8c497
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/2539#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2539
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%2F2539
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/2539
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2539
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2539
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues305 (305)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/2539
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2539
Bug: task_result_handler.py serializes None optional fields as JSON null, breaking Node SDK Zod validationhttps://github.com/modelcontextprotocol/python-sdk/issues/2539#top
https://github.com/rynowak
rynowakhttps://github.com/rynowak
on May 4, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2539#issue-4380268656
https://github.com/modelcontextprotocol/python-sdk/issueshttps://github.com/modelcontextprotocol/python-sdk/issues
https://github.com/abhinavmathur-atlan
abhinavmathur-atlanhttps://github.com/abhinavmathur-atlan
on May 5, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2539#issuecomment-4377423163
https://github.com/maxisbey
maxisbeyhttps://github.com/maxisbey
on Jul 29, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2539#issuecomment-5118480968
#2809https://github.com/modelcontextprotocol/python-sdk/pull/2809
AI Disclaimerhttps://gist.github.com/maxisbey/6123d132484e4c533eab519a2800693d
maxisbeyhttps://github.com/maxisbey
completedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 29, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2539#event-28663274884
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2539
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2539
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.