Title: Client treats JSON-null structuredContent as missing, skipping outputSchema validation · Issue #3345 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Client treats JSON-null structuredContent as missing, skipping outputSchema validation · Issue #3345 · modelcontextprotocol/python-sdk
X Title: Client treats JSON-null structuredContent as missing, skipping outputSchema validation · Issue #3345 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before openi...
Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...
X Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/mod...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3345
X: @github
Domain: redirect.github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Client treats JSON-null structuredContent as missing, skipping outputSchema validation","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Release line\n\n2.x (current stable)\n\n### Description\n\nOn current `main` (`57394b0548d1e2dc2dce8d67d84985769df3b8bb`), `ClientSession.validate_tool_result` treats `structured_content is None` as \"the tool did not return structured content\".\n\nThat collapses two different wire shapes:\n\n1. omitted `structuredContent` (field absent)\n2. explicit JSON `null` (`\"structuredContent\": null`)\n\nSEP-2106 / spec 2026-07-28 allow `structuredContent` to be any JSON value, including `null`. The TypeScript SDK already checks `=== undefined` (not falsy / not null) for this reason.\n\nPydantic stores both omitted and JSON null as `None`. `model_fields_set` distinguishes them: a `CallToolResult` parsed from `{\"content\": [], \"structuredContent\": null}` has `\"structured_content\" in model_fields_set`, while an omitted field does not.\n\n**What happens today**\n\n- Tool advertises `\"outputSchema\": {\"type\": \"null\"}` (or `{\"type\": [\"object\", \"null\"], ...}`).\n- Server returns `\"structuredContent\": null`.\n- Client raises `Tool {name} has an output schema but did not return structured content` and never runs jsonschema against the value.\n\n**What I expected**\n\n- Omitted `structuredContent` still raises the existing missing-field error.\n- Explicit JSON null is validated against the advertised schema: accept if the schema allows null, reject as a schema mismatch if it does not.\n- Falsy JSON values (`0`, `false`, `\"\"`) stay validated (they already are, because the current check is `is None` rather than falsy).\n\nThis is not #3224 (server injecting nulls for `NotRequired` keys). That issue is about serializing omitted object keys as null. This one is the client presence check before `outputSchema` validation.\n\nI hit this while checking official SDK conformance of declared `outputSchema` against `structuredContent`. I have a small backwards-compatible test and fix ready and would like to send the PR if a maintainer wants it.\n\nAI assistance: researched and drafted with Grok 4.6; I reviewed the spec text, the TypeScript v2 presence check, and the Pydantic `model_fields_set` behavior before filing.\n\n### Example Code\n\n```python\nfrom mcp_types import CallToolResult\n\nomitted = CallToolResult.model_validate({\"content\": []})\nexplicit_null = CallToolResult.model_validate({\"content\": [], \"structuredContent\": None})\n\nassert omitted.structured_content is None\nassert explicit_null.structured_content is None\nassert \"structured_content\" not in omitted.model_fields_set\nassert \"structured_content\" in explicit_null.model_fields_set\n```\n\nAgainst a tool whose `outputSchema` is `{\"type\": \"null\"}`, `validate_tool_result` currently raises the missing-field RuntimeError for `explicit_null`. After a presence check that uses `model_fields_set`, that result validates.\n\n### Python & MCP Python SDK\n\n- Python 3.12\n- MCP Python SDK `main` at `57394b0548d1e2dc2dce8d67d84985769df3b8bb` (2.x)","author":{"url":"https://github.com/epistemedeus","@type":"Person","name":"epistemedeus"},"datePublished":"2026-08-20T17:21:47Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3345"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:58c8f333-f639-08fc-2328-e4a539094cf9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAE0:24A077:2AB2018:38474DD:6B056A3A |
| html-safe-nonce | 69976255af6b4ca2288f1e3e9d2f66718ac2264cd90813af04c9f2308b9fbbb0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUUwOjI0QTA3NzoyQUIyMDE4OjM4NDc0REQ6NkIwNTZBM0EiLCJ2aXNpdG9yX2lkIjoiNzc2NTM4MDU5NjE0NjQ2NTMzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 76d20224b55ae259af3b77eaecd2b975f37822f20624abdaad4c33a0d328ee7d |
| hovercard-subject-tag | issue:5206097349 |
| 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/3345/issue_layout |
| twitter:image | https://opengraph.githubassets.com/23272027af8ca71921f275b64e84ae09e5035d4da7085ede8bd5f963e0416f64/modelcontextprotocol/python-sdk/issues/3345 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/23272027af8ca71921f275b64e84ae09e5035d4da7085ede8bd5f963e0416f64/modelcontextprotocol/python-sdk/issues/3345 |
| og:image:alt | Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | epistemedeus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1be5cc09efdd4833c24a4ffa71d698e3999fa09071e159fe14c2c08e41c98331 |
| 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 | f6d69234e682c947a48074340e69d45d5901de31 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width