Title: Validate an explicit null structuredContent against the output schema by maxisbey · Pull Request #3621 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Validate an explicit null structuredContent against the output schema by maxisbey · Pull Request #3621 · modelcontextprotocol/python-sdk
X Title: Validate an explicit null structuredContent against the output schema by maxisbey · Pull Request #3621 · modelcontextprotocol/python-sdk
Description: Fixes #3345. What was wrong When a tool declares an output schema and the server returns "structuredContent": null, the client raised Tool ... has an output schema but did not return structured content without checking the schema. An explicit null and a field that was left out were treated as the same thing. The 2026-07-28 schema lists null as a legal structuredContent value: "any JSON value (object, array, string, number, boolean, or null) that conforms to the tool's outputSchema" (schema.ts). A server returning null for a tool whose schema allows null is conformant, and the client rejected its result. 0, false and "" were already validated. Null was the only JSON value treated as "nothing". The TypeScript SDK treats the result as missing only when the field is undefined, and validates null (client.ts). The Go and Rust SDKs also keep null distinct from absent. What changes One condition in ClientSession.validate_tool_result: structured content counts as missing only when the value is None and the field was not set on the result (model_fields_set). An explicit null now reaches the existing schema validation like any other value. No new names, parameters or defaults. Nothing changes on the wire. What users will notice Only results with an explicit null structuredContent, for a tool that declares an output schema, behave differently: The schema allows null: the call used to raise and now returns the result. The schema does not constrain the top-level type ({}, or properties without type): the call used to raise and now returns the result, because null is valid against such a schema. The schema does not allow null: the call still raises RuntimeError, with a different message. Before: Tool ... has an output schema but did not return structured content After: Invalid structured content returned by tool ...: None is not of type ... This also applies on sessions using earlier protocol versions. A CallToolResult built in code with structured_content=None passed explicitly counts as an explicit null too. This applies when it is passed to validate_tool_result directly, or returned by an extension's result resolver. CallToolResult(content=[...]) without the argument is still "missing". Unchanged: A result with no structuredContent field still raises the "did not return structured content" error, whatever the schema allows. isError results and tools without an output schema are still not validated. Not included A server built on this SDK still leaves a null structuredContent off the wire, so it cannot return a top-level null result itself. That is a separate change on the sending side. How it was checked Three new tests in tests/client/test_session.py drive ClientSession.call_tool on a 2026-07-28 session against scripted wire results, since an SDK server cannot produce the null: null against a schema that allows it is returned null against a schema that does not is a schema mismatch an absent field against a schema that allows null is still "missing" The first two fail on main and pass with the change; the third passes on both. ./scripts/test passes with 100% coverage; ruff and pyright are clean. AI Disclaimer
Open Graph Description: Fixes #3345. What was wrong When a tool declares an output schema and the server returns "structuredContent": null, the client raised Tool ... has an output schema but did not return stru...
X Description: Fixes #3345. What was wrong When a tool declares an output schema and the server returns "structuredContent": null, the client raised Tool ... has an output schema but did not ret...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3621
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:afd2062a-191a-f967-a234-eb745a6c39a3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CDAA:FCC28:11AE2F7:1837F5A:6B056647 |
| html-safe-nonce | 6793912c7edfddcea4c0ce79a3a5c12bfe49f97a1316b1256740886e5a1b48c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDREFBOkZDQzI4OjExQUUyRjc6MTgzN0Y1QTo2QjA1NjY0NyIsInZpc2l0b3JfaWQiOiIxNTg0ODY1NDQzOTQzMTE0MzExIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8440b6f7625ca2c4563e7c723a6bfc50bc245f5663136d4da632b31b178c1860 |
| hovercard-subject-tag | pull_request:4716303121 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/modelcontextprotocol/python-sdk/pull/3621/files |
| twitter:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| og:image:alt | Fixes #3345. What was wrong When a tool declares an output schema and the server returns "structuredContent": null, the client raised Tool ... has an output schema but did not return stru... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1be5cc09efdd4833c24a4ffa71d698e3999fa09071e159fe14c2c08e41c98331 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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 |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width