Title: Correlate invalid JSON-RPC envelope errors with the original request id by GauthamPrabhuM · Pull Request #2857 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Correlate invalid JSON-RPC envelope errors with the original request id by GauthamPrabhuM · Pull Request #2857 · modelcontextprotocol/python-sdk
X Title: Correlate invalid JSON-RPC envelope errors with the original request id by GauthamPrabhuM · Pull Request #2857 · modelcontextprotocol/python-sdk
Description: Summary Fixes #2848. A JSON-RPC message that is valid JSON but not a valid request object (wrong jsonrpc version, missing jsonrpc, non-string method, etc.) was not answered with an error that a client could correlate back to its request. Per JSON-RPC 2.0, the server should reply with an Invalid Request (-32600) error that echoes the original request id when it is detectable (and null otherwise). Previously the behavior was inconsistent and uncorrelatable: Streamable HTTP replied 400 with id: null and code -32602 (Invalid params). A client that pipelines requests 1, 2, 3 and trips this on #2 saw a response with a non-matching id and no way to know which request failed. stdio sent no response at all — the validation exception was forwarded into the read stream and silently dropped by the dispatcher, so the original request hung from the client's perspective. Changes Added mcp.types.jsonrpc.extract_request_id() — best-effort extraction of the id from a raw payload that failed envelope validation, returning None when no valid id is present (bool and fractional values are rejected, since they are not valid RequestId types). Streamable HTTP (server/streamable_http.py): invalid envelopes now reply -32600 with the correlated id instead of -32602/null. _create_error_response gained an optional request_id parameter. stdio (server/stdio.py): an id-bearing line that fails validation now emits a correlated -32600 error response on the write stream. Lines without a detectable id (parse errors, malformed notifications, invalid id types) keep the previous behavior of forwarding the exception without a response. Testing New parametrized tests on both transports covering all three cases from the issue plus string ids, undetectable ids, and invalid id types (bool, fractional). Updated test_hosting_http.py to assert the new -32600 code for the batched-request case. End-to-end verified against a live stdio subprocess and a live streamable-HTTP server following a full init flow: invalid envelopes return correlated -32600 errors and a follow-up ping still succeeds. Full suite green: ./scripts/test (1788 passed), 100% coverage, ruff, pyright all clean. Migration / breaking change The error code returned for an invalid JSON-RPC envelope over both transports changes from -32602 (Invalid params) to -32600 (Invalid Request), and the response id is now populated when detectable. This is a behavioral change to error responses; documented here for reviewers since it may affect clients that string-matched on the prior code. 🤖 Generated with Claude Code
Open Graph Description: Summary Fixes #2848. A JSON-RPC message that is valid JSON but not a valid request object (wrong jsonrpc version, missing jsonrpc, non-string method, etc.) was not answered with an error that a cli...
X Description: Summary Fixes #2848. A JSON-RPC message that is valid JSON but not a valid request object (wrong jsonrpc version, missing jsonrpc, non-string method, etc.) was not answered with an error that a cli...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2857
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6c4b6172-9f42-712b-bf57-f48f88d71503 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A074:1F5D45:8AF53E:BC7961:6A5A85DF |
| html-safe-nonce | 78be446892a6757dba4799e1c464ee9e81fbb50127ce34d873460329ba81589b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDc0OjFGNUQ0NTo4QUY1M0U6QkM3OTYxOjZBNUE4NURGIiwidmlzaXRvcl9pZCI6IjgwODM1MzIyODcxNTYzMjM4MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ab25666c97fcf6f50c851206e547112e03187d1a36af46d8d4c232db2452e2db |
| hovercard-subject-tag | pull_request:3858824825 |
| 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/2857/files |
| twitter:image | https://avatars.githubusercontent.com/u/71874814?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/71874814?s=400&v=4 |
| og:image:alt | Summary Fixes #2848. A JSON-RPC message that is valid JSON but not a valid request object (wrong jsonrpc version, missing jsonrpc, non-string method, etc.) was not answered with an error that a cli... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 922bdba685ea48400234d557977f0e32d9adbae6f5125725b4f48cacc6801106 |
| 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 | 7c8a44665d760d73ead7e85d8f88b299152aa681 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width