Return -32602 for resource not found (SEP-2164)#2920
Merged
Conversation
Reading a missing resource now returns JSON-RPC error -32602 (invalid params) with the requested URI in error.data, instead of code 0. A new ResourceNotFoundError(ResourceError) carries the not-found signal: ResourceManager.get_resource raises it for an unmatched URI, and _handle_read_resource maps it to -32602 while other ResourceErrors map to -32603 (internal error). Resource lookups now raise typed exceptions instead of ValueError. Implements SEP-2164. Removes the matching conformance baseline entry, which now passes.
Kludex
commented
Jun 20, 2026
Kludex
commented
Jun 20, 2026
Kludex
commented
Jun 20, 2026
Kludex
commented
Jun 20, 2026
Mirror the read_resource read-path: log the full traceback but raise a ResourceError naming only the URI, so the original exception is not leaked to the client. Reflow the ResourceNotFoundError docstring to 120.
Kludex
commented
Jun 20, 2026
| raise | ||
| except Exception as exc: | ||
| logger.exception(f"Error creating resource from template {uri}") | ||
| # If an exception happens when creating the resource, we should not leak the exception to the client. |
Kludex
commented
Jun 20, 2026
maxisbey
approved these changes
Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements SEP-2164. Closes #2794.
Reading a missing resource now returns JSON-RPC
-32602(invalid params) with the requested URI inerror.data, instead of code0with no data, so clients can reliably distinguish not-found.Changes
ResourceNotFoundError(ResourceError)(backward compatible - existingResourceErrorcatchers still work).ResourceManager.get_resource()raises it for an unmatched URI; template-creation failures now raiseResourceErrorinstead ofValueError._handle_read_resource()mapsResourceNotFoundError->-32602and otherResourceError->-32603, both carrying{"uri": ...}.3 passed, 0 failed).Breaking change documented in
docs/migration.md.AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.