-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Define error code allocation policy and renumber draft error codes #2907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f505a6c
Define error code allocation policy and renumber draft error codes
felixweinberger 73ab7d2
Extend implementation-defined sub-range to -32019
felixweinberger 146b1f4
Update docs/specification/draft/basic/index.mdx
felixweinberger 05895d7
Update docs/specification/draft/basic/index.mdx
felixweinberger 74ac874
Update docs/specification/draft/basic/index.mdx
felixweinberger 6bdff79
Leave room for future spec-defined local error codes
felixweinberger 205e6c0
Tighten error code policy wording per review
felixweinberger 3f732fb
Apply review feedback on range guidance
felixweinberger 6ecfdcf
Merge branch 'main' into fweinberger/error-code-allocation
felixweinberger a1536e0
Merge remote-tracking branch 'origin/main' into fweinberger/error-cod…
felixweinberger e3f281c
Merge remote-tracking branch 'origin/main' into fweinberger/error-cod…
felixweinberger 0bce6bc
Only carve out -32002 in the legacy sub-range receiver rule
felixweinberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,6 +104,54 @@ can use to determine how to parse and handle the `result` object. | |||||||
| - Error responses **MUST** include an `error` field with a `code` and `message`. | ||||||||
| - Error codes **MUST** be integers. | ||||||||
|
|
||||||||
| #### Error Codes | ||||||||
|
|
||||||||
| MCP uses the standard JSON-RPC 2.0 error codes (`-32700`, `-32600` to `-32603`) | ||||||||
| for general protocol failures. | ||||||||
|
|
||||||||
| JSON-RPC 2.0 reserves the range `-32000` to `-32099` for implementation-defined | ||||||||
| server errors. MCP partitions this range as follows: | ||||||||
|
|
||||||||
| - **`-32000` to `-32019` — legacy.** Codes in this sub-range were allocated by | ||||||||
| implementations before this policy was introduced. New codes **MUST NOT** be | ||||||||
| allocated in this sub-range, and new implementations **SHOULD NOT** use codes | ||||||||
| from this sub-range at all. Apart from `-32002` (see below), receivers | ||||||||
| **MUST NOT** assume any specific meaning for these codes. | ||||||||
| - **`-32020` to `-32099` — reserved for the MCP specification.** Error codes | ||||||||
| in this sub-range are defined exclusively by the MCP specification and | ||||||||
| recorded in the [schema](/specification/draft/schema). Implementations | ||||||||
| **MUST NOT** emit any code from this sub-range that is not defined by this | ||||||||
| specification and **MUST** use defined codes only with their specified | ||||||||
| meanings. | ||||||||
|
|
||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| MCP defines the following error codes: | ||||||||
|
|
||||||||
| | Code | Name | | ||||||||
| | -------- | ----------------------------------------------------------------------------------------------------- | | ||||||||
| | `-32020` | [`HeaderMismatch`](/specification/draft/schema#headermismatcherror) | | ||||||||
| | `-32021` | [`MissingRequiredClientCapability`](/specification/draft/schema#missingrequiredclientcapabilityerror) | | ||||||||
| | `-32022` | [`UnsupportedProtocolVersion`](/specification/draft/schema#unsupportedprotocolversionerror) | | ||||||||
|
|
||||||||
| Codes defined by earlier protocol versions remain reserved and will not be | ||||||||
|
felixweinberger marked this conversation as resolved.
|
||||||||
| reused. Implementations of this protocol version **MUST NOT** emit these codes: | ||||||||
|
|
||||||||
| - `-32002` — resource not found (2025-11-25 and earlier; replaced by `-32602`). | ||||||||
| Clients [**SHOULD** still | ||||||||
| accept `-32002`](/specification/draft/server/resources#error-handling) from | ||||||||
| servers implementing earlier versions. | ||||||||
| - `-32042` — URL elicitation required (2025-11-25 only). | ||||||||
|
|
||||||||
| Errors that are purely local to an implementation (for example, a request | ||||||||
| timeout raised inside an SDK) are not currently assigned codes by this | ||||||||
| specification. Implementations surfacing local errors in JSON-RPC-shaped | ||||||||
| structures should ensure they cannot be mistaken for errors received from the | ||||||||
| peer. Future versions of the specification may define standard codes for | ||||||||
| common local error conditions in the reserved sub-range. | ||||||||
|
|
||||||||
| New error codes for purposes not defined by this specification **SHOULD** be | ||||||||
| allocated outside the JSON-RPC reserved range (`-32768` to `-32000`); the | ||||||||
| remainder of the integer space is available for application-defined errors. | ||||||||
|
|
||||||||
| ### Notifications | ||||||||
|
|
||||||||
| [Notifications](/specification/draft/schema#jsonrpcnotification) are sent from the client to the server or vice versa, as a one-way message. | ||||||||
|
|
@@ -318,7 +366,7 @@ A server **MUST NOT** rely on capabilities the client has not declared. If | |||||||
| processing a request requires a capability the client did not include in | ||||||||
| `io.modelcontextprotocol/clientCapabilities`, the server **MUST** return a | ||||||||
| [`MissingRequiredClientCapabilityError`](/specification/draft/schema#missingrequiredclientcapabilityerror) | ||||||||
| (`-32003`) whose `data.requiredCapabilities` lists the missing capabilities. On | ||||||||
| (`-32021`) whose `data.requiredCapabilities` lists the missing capabilities. On | ||||||||
| HTTP, the response status **MUST** be `400 Bad Request`. | ||||||||
|
|
||||||||
| On notifications delivered via a [`subscriptions/listen`][subscriptions-listen] stream, | ||||||||
|
|
||||||||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mention -32768 to -32000 are reserved by JSON-RPC 2.0 for pre-defined errors, even if only the listed codes are currently in use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it's a fair point but I wonder if we want to essentially restate JSONRPC specification inside MCP?
That seems like a slippery slope potentially where we pull in every external definition (say, SSE, HTTP, JSONRPC).
Not sure if we have a general view on this, maybe @localden has a view here?
I'm happy to add the spec language pointing out the JSONRPC reserved range as an FYI here at the cost of duplicating JSONRPC itself a little here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we generally shouldn't restate JSON-RPC spec, but we're already doing so with the error codes in use. And the practical reason is to deter developers who might never read the JSON-RPC spec, but do read this one, from being clever and using a reserved error code (unknowingly). But it's not a big deal. Just think it could reduce the risk of exactly the kind of clever error tricks, that cause trouble down the line