Skip to content

Change invalid resource URI error code from -32002 to -32602#1545

Open
AntonKueltz wants to merge 4 commits intomodelcontextprotocol:mainfrom
AntonKueltz:patch-1
Open

Change invalid resource URI error code from -32002 to -32602#1545
AntonKueltz wants to merge 4 commits intomodelcontextprotocol:mainfrom
AntonKueltz:patch-1

Conversation

@AntonKueltz
Copy link

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)".

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

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)".
@AntonKueltz AntonKueltz requested a review from a team September 25, 2025 17:25
@pja-ant
Copy link
Contributor

pja-ant commented Sep 25, 2025

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.

Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

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

Agreed that this looks like a typo, considering this is the full extent of error codes that we define:

// Standard JSON-RPC error codes
/** @internal */
export const PARSE_ERROR = -32700;
/** @internal */
export const INVALID_REQUEST = -32600;
/** @internal */
export const METHOD_NOT_FOUND = -32601;
/** @internal */
export const INVALID_PARAMS = -32602;
/** @internal */
export const INTERNAL_ERROR = -32603;

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?

@jonathanhefner jonathanhefner linked an issue Sep 25, 2025 that may be closed by this pull request
@AntonKueltz
Copy link
Author

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.

@dsp-ant
Copy link
Member

dsp-ant commented Sep 26, 2025

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 -32002. If we were to change this, clients and servers would have to be able to change this depending on the MCP version. I am inclined to just live with this and not cause existing code to break.

@jonathanhefner
Copy link
Member

jonathanhefner commented Sep 26, 2025

The problem is that we a lot of existing code (see https://github.com/search?q=mcp+AND+-32002&type=code) that uses -32002.

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 jsonrpc2 Go package defines -32002 as "server closing". Could this be a difference of interpretation of the JSON-RPC 2.0 spec? Or is there further evidence that MCP should refrain from using -32000 to -32099?

This issue has made me think we should do more to make schema.ts the source of truth for error codes. To that end, I've opened #1549. Is there interest in something like that?

revert changes to existing spec
@AntonKueltz
Copy link
Author

If we were to change this, clients and servers would have to be able to change this depending on the MCP version. I am inclined to just live with this and not cause existing code to break.

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.

not supporting publishing this as a doc fix for v2025-06-18.

Update the PR to reflect this.

@pja-ant
Copy link
Contributor

pja-ant commented Sep 29, 2025

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.

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 :)

@maxisbey
Copy link
Contributor

maxisbey commented Nov 6, 2025

To add to this, neither the Typescript nor the Python SDK actually return -32002 by default. The Typescript SDK returns -32602 already, whereas the Python SDK actually just returns 0 for a resource error.

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).

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.

spec defines improper error codes

5 participants