Title: fix: return INVALID_PARAMS (-32602) for resource-not-found errors by leoneperdigao · Pull Request #2325 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: return INVALID_PARAMS (-32602) for resource-not-found errors by leoneperdigao · Pull Request #2325 · modelcontextprotocol/python-sdk
X Title: fix: return INVALID_PARAMS (-32602) for resource-not-found errors by leoneperdigao · Pull Request #2325 · modelcontextprotocol/python-sdk
Description: Summary Fix read_resource() to raise MCPError(code=INVALID_PARAMS) instead of ResourceError, so resource-not-found errors return -32602 instead of 0 Aligns with the TypeScript SDK behavior and emerging spec consensus (modelcontextprotocol#1545) Adds regression test verifying the error code for both unknown resources and resource read failures Root cause ResourceError extends MCPServerError which extends Exception, it is not an MCPError. When the low-level server's request handler catches it, it falls into the generic except Exception branch which returns ErrorData(code=0, ...). The fix raises MCPError directly at the protocol boundary in read_resource(), following the same pattern used elsewhere in the codebase (validation errors, session errors, UrlElicitationRequiredError). Test plan New test test_1579_resource_error_code.py verifies error code is -32602 for unknown resources and read failures Updated test_141_resource_templates.py to catch MCPError instead of ResourceError All 364 existing tests pass with no regressions Closes #1579
Open Graph Description: Summary Fix read_resource() to raise MCPError(code=INVALID_PARAMS) instead of ResourceError, so resource-not-found errors return -32602 instead of 0 Aligns with the TypeScript SDK behavior and eme...
X Description: Summary Fix read_resource() to raise MCPError(code=INVALID_PARAMS) instead of ResourceError, so resource-not-found errors return -32602 instead of 0 Aligns with the TypeScript SDK behavior and eme...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2325
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d59ca8b9-d8cf-00c7-7941-4ce554171a5a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9244:61DF9:1EAF7FE:2C43D0E:6A58D965 |
| html-safe-nonce | 60b56ba4b11eb641afe346b4ace2603579d6a16bb95e114c5caa1ce9090a1756 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjQ0OjYxREY5OjFFQUY3RkU6MkM0M0QwRTo2QTU4RDk2NSIsInZpc2l0b3JfaWQiOiI2MzQ3NjM4OTI0MjQ5NzE3MDkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 88f4d9f924b47bd2294c35d5faf8e30e15149c225f93dca3ac9f4dadd5748152 |
| hovercard-subject-tag | pull_request:3428169671 |
| 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/2325/files |
| twitter:image | https://avatars.githubusercontent.com/u/8030485?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8030485?s=400&v=4 |
| og:image:alt | Summary Fix read_resource() to raise MCPError(code=INVALID_PARAMS) instead of ResourceError, so resource-not-found errors return -32602 instead of 0 Aligns with the TypeScript SDK behavior and eme... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| 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 | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width