Title: fix: correlate invalid JSON-RPC envelope errors with the original request id by anneheartrecord · Pull Request #2852 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: correlate invalid JSON-RPC envelope errors with the original request id by anneheartrecord · Pull Request #2852 · modelcontextprotocol/python-sdk
X Title: fix: correlate invalid JSON-RPC envelope errors with the original request id by anneheartrecord · Pull Request #2852 · modelcontextprotocol/python-sdk
Description: Fixes #2848 When an incoming message is valid JSON but fails JSON-RPC envelope validation (e.g. "jsonrpc": "1.0", a missing jsonrpc field, or a non-string method), the error response could not be correlated with the originating request: stdio: the server transport forwarded the exception in-stream and never answered, so the client got no response for its request id. Streamable HTTP: the server replied 400 with a JSON-RPC error using a null id ("server-error" on v1.x), breaking client-side request/response correlation. This PR extracts the request id best-effort from the raw parsed payload (shared helper extract_raw_request_id; only spec-valid id types are accepted — strings and non-bool integers) and preserves it in the error response on both transports, falling back to a null id per the JSON-RPC 2.0 spec when no valid id can be extracted. The stdio transport now also answers unparseable lines with -32700 Parse error (null id), matching the HTTP transport's existing parse-error behavior. Envelope-invalid messages are now reported as -32600 Invalid Request instead of -32602 Invalid params, matching JSON-RPC 2.0 error code semantics (the issue's three repro cases are envelope violations, not parameter errors). Tests cover all three repro cases from the issue on both transports, plus the null-id fallback (unextractable id and unparseable body). Full suite, ruff, and pyright pass.
Open Graph Description: Fixes #2848 When an incoming message is valid JSON but fails JSON-RPC envelope validation (e.g. "jsonrpc": "1.0", a missing jsonrpc field, or a non-string method), the error res...
X Description: Fixes #2848 When an incoming message is valid JSON but fails JSON-RPC envelope validation (e.g. "jsonrpc": "1.0", a missing jsonrpc field, or a non-string method...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2852
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1bd9e881-f127-39af-683b-666a7c4bb537 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B07C:1D7A16:DABA95:12927A8:6A5A9BBE |
| html-safe-nonce | c3589f1ea15a21146e5496426b511951469924e6ece74adffde07f787219bd42 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDdDOjFEN0ExNjpEQUJBOTU6MTI5MjdBODo2QTVBOUJCRSIsInZpc2l0b3JfaWQiOiI4NjQzMTQ0MzQ2NjE0MDEyODYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 90256f6fb45521aefe956e809e5512454bf5b91d6732f511672554a8b0aeb498 |
| hovercard-subject-tag | pull_request:3855885151 |
| 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/2852/files |
| twitter:image | https://avatars.githubusercontent.com/u/74543653?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/74543653?s=400&v=4 |
| og:image:alt | Fixes #2848 When an incoming message is valid JSON but fails JSON-RPC envelope validation (e.g. "jsonrpc": "1.0", a missing jsonrpc field, or a non-string method), the error res... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 69f915f8d1f777c494e9106a13f148eaddfa8984cb86436e87809d42b400e544 |
| 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 | c9a4a89553add5a97cf9f034f0e1e7f1a66257c9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width