Title: fix(client): validate JSON-null structuredContent against outputSchema by epistemedeus · Pull Request #3346 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(client): validate JSON-null structuredContent against outputSchema by epistemedeus · Pull Request #3346 · modelcontextprotocol/python-sdk
X Title: fix(client): validate JSON-null structuredContent against outputSchema by epistemedeus · Pull Request #3346 · modelcontextprotocol/python-sdk
Description: Fixes #3345 SEP-2106 allows structuredContent to be JSON null. validate_tool_result treated structured_content is None as a missing field, so a tool that advertised a null-capable outputSchema and returned "structuredContent": null never reached jsonschema validation. Pydantic stores both omitted and explicit JSON null as None. This uses model_fields_set as the presence check, matching the TypeScript SDK's === undefined (not null / not falsy) check. Motivation and Context Declared outputSchema was not validated against a legal JSON-null structuredContent value. Clients rejected a conforming result as missing instead of schema-checking it. Omitted structuredContent still fails closed. How Has This Been Tested? uv run --frozen pytest tests/client/test_session_promotions.py tests/interaction/lowlevel/test_tools.py::test_declared_output_schema_with_no_structured_content_is_rejected_by_the_client tests/interaction/lowlevel/test_tools.py::test_call_tool_structured_content_violating_output_schema_is_rejected_by_the_client -q 24 passed, including new cases for: explicit JSON null against {"type": "null"} (accept) explicit JSON null against an object schema (schema mismatch, not missing) omitted field (existing missing-field error) falsy non-null values 0 / false Breaking Changes None. Omitted structuredContent still raises the same RuntimeError. Only an explicit JSON null is now schema-validated. Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update Checklist I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer) I have disclosed any AI assistance and can explain the change in my own words I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context Not assigned on #3345. Opening as a draft per the small-fix-with-tests shape; CONTRIBUTING may auto-close until a maintainer assigns the issue. Reporter of #3345. AI assistance: researched and implemented with Grok 4.6; I reviewed the spec text, the TypeScript v2 presence check, Pydantic model_fields_set on parsed CallToolResult, and the new tests. No protocol change. No new schema surface. Does not duplicate the existing jsonschema check; it only stops the presence check from swallowing JSON null before that check runs.
Open Graph Description: Fixes #3345 SEP-2106 allows structuredContent to be JSON null. validate_tool_result treated structured_content is None as a missing field, so a tool that advertised a null-capable outputSchema and ...
X Description: Fixes #3345 SEP-2106 allows structuredContent to be JSON null. validate_tool_result treated structured_content is None as a missing field, so a tool that advertised a null-capable outputSchema and ...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3346
X: @github
Domain: github.com
IPv4 address: 140.82.114.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:5c1a2758-4a86-cc05-1136-6a84813d40e7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D5D8:1760D:2B26E74:39061E3:6B056C5B |
| html-safe-nonce | eaac6d58f74820b59fc21f7b6db6724ba7b49df35715e1f9338ace7eebbaf9bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUQ4OjE3NjBEOjJCMjZFNzQ6MzkwNjFFMzo2QjA1NkM1QiIsInZpc2l0b3JfaWQiOiI2NDU0Mjk2NDUyNzEyOTgzNjQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3c6801fa8a83edd9628c1acff4c04aa8470b470abd9cdafed47bfb07880ea537 |
| hovercard-subject-tag | pull_request:4325104185 |
| 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/3346/files |
| twitter:image | https://avatars.githubusercontent.com/u/124947147?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/124947147?s=400&v=4 |
| og:image:alt | Fixes #3345 SEP-2106 allows structuredContent to be JSON null. validate_tool_result treated structured_content is None as a missing field, so a tool that advertised a null-capable outputSchema and ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9b4256ac5f3e310e7945ef5b71c9cb9e264357b1eb20e91d369ed6502a4c486c |
| 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 | f089e689ad324655ac44bf6cdbc04d976105b374 |
| 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