Skip to content

Return -32602 for resource not found (SEP-2164)#2920

Merged
Kludex merged 3 commits into
mainfrom
sep-2164-resource-not-found
Jun 20, 2026
Merged

Return -32602 for resource not found (SEP-2164)#2920
Kludex merged 3 commits into
mainfrom
sep-2164-resource-not-found

Conversation

@Kludex

@Kludex Kludex commented Jun 20, 2026

Copy link
Copy Markdown
Member

Implements SEP-2164. Closes #2794.

Reading a missing resource now returns JSON-RPC -32602 (invalid params) with the requested URI in error.data, instead of code 0 with no data, so clients can reliably distinguish not-found.

Changes

  • Add ResourceNotFoundError(ResourceError) (backward compatible - existing ResourceError catchers still work).
  • ResourceManager.get_resource() raises it for an unmatched URI; template-creation failures now raise ResourceError instead of ValueError.
  • _handle_read_resource() maps ResourceNotFoundError -> -32602 and other ResourceError -> -32603, both carrying {"uri": ...}.
  • Resolves the SEP-2164 interaction-suite divergence and drops the matching conformance baseline entry, which now passes (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.

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.
Comment thread src/mcp/server/mcpserver/resources/templates.py
Comment thread src/mcp/server/mcpserver/resources/templates.py Outdated
Comment thread src/mcp/server/mcpserver/exceptions.py Outdated
Comment thread src/mcp/server/mcpserver/server.py
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.
Comment thread src/mcp/server/mcpserver/resources/templates.py Outdated
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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped in 0cd887a.

Comment thread src/mcp/server/mcpserver/exceptions.py Outdated
@Kludex Kludex merged commit f253682 into main Jun 20, 2026
36 checks passed
@Kludex Kludex deleted the sep-2164-resource-not-found branch June 20, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-2164: Standardize resource not found error code (-32602)

2 participants