Change invalid resource URI error code from -32002 to -32602#1545
Change invalid resource URI error code from -32002 to -32602#1545AntonKueltz wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
Change error code from `-32002` to `-32602` when invalid resource name is provided. `-32002` is a non-standard JSON-RPC code. Using `-32602` is also consistent with how tools and prompts behave when given invalid names e.g. "Invalid prompt name: `-32602` (Invalid params)".
|
Good catch, looks like a typo, but this change should be made to the draft spec. I don't believe we retroactively update already published specs. |
jonathanhefner
left a comment
There was a problem hiding this comment.
Agreed that this looks like a typo, considering this is the full extent of error codes that we define:
modelcontextprotocol/schema/draft/schema.ts
Lines 111 to 121 in 14ec41c
I think it makes sense to publish this as doc fix to v2025-06-18, but I agree with @pja-ant that we must fix this for the draft spec as well. Would you mind adding that change?
Update draft spec as well.
|
Ah good catch, draft updated as well. I defer to reviewers on whether to keep changes in 2025-06-18, let me know and I'll update as needed. |
|
I agree, this is a typo. The problem is that we a lot of existing code (see https://github.com/search?q=mcp+AND+-32002&type=code) that uses |
It's worth pointing out that "-32002" is not resource-related in some of those results. For example, "method not allowed", "invalid bearer token", and lamenting -32002 as a bug in the spec (see also #509). But I agree with your point, and have changed my mind to not supporting publishing this as a doc fix for v2025-06-18. I still think there may be value in changing this for v2025-11-25 though. @jba, in a code comment you wrote that the This issue has made me think we should do more to make |
revert changes to existing spec
Out of curiosity, are new spec versions not recommended to have breaking changes? I understand the line of thinking of not changing specs that have been finalized and released to not break existing implementations, but the next spec version seems like as good a place as any to fix this. I'm not terribly opinionated on this change (beyond the "nice-to-have" of consistency with how other server capabilities handle similar scenarios), more so interested in understanding what the philosophy behind versioning and breaking changes for the project is.
Update the PR to reflect this. |
New specs are definitely a better place to make breaking changes, but a breaking change is still a breaking change. There are many clients and servers out there, and not all of them use the SDKs. Also, likely very few of the maintainers of those clients/servers are following the protocol development closely to know when those changes occur. If they miss the breaking change (highly likely) then software may just stop working or become incompatible with different clients/servers. We still probably need to make breaking changes occasionally, but it's probably a case of picking your battles, i.e. only doing it when there is a large pay-off in doing so. Not an easy problem to solve. See HTTP Referer :) |
|
To add to this, neither the Typescript nor the Python SDK actually return -32002 by default. The Typescript SDK returns Although, both SDKs allow users to raise their own errors and manually specify the return code (unless you're using the Python SDK's FastMCP, then you can't). |
Change error code from
-32002to-32602when invalid resource name is provided.-32002is a non-standard JSON-RPC code. Using-32602is also consistent with how tools and prompts behave when given invalid names e.g. "Invalid prompt name:-32602(Invalid params)".Motivation and Context
Use a standard JSON-RPC error code when an invalid resource URI is requested. This creates consistency with how prompts and tools respond to analogous situations.
How Has This Been Tested?
Doc-only changes.
Breaking Changes
Breaking change in spec if clients have behavior dependent on the old error code.
Types of changes
Checklist
Additional context