fix(mcp): answer an unknown resource or prompt with a standard error code - #107
Open
carldebilly wants to merge 1 commit into
Open
carldebilly wants to merge 1 commit into
carldebilly wants to merge 1 commit into
Conversation
…code ReadResourceAsync and GetPromptAsync threw a code-less McpException for an unknown URI or name, which the SDK surfaces as InternalError (-32603) — a broken server, as far as a host can tell, rather than a missing resource. SEP-2164 standardises the codes so hosts can tell "gone" from "broken". The codes follow the SDK 2.2.0 handlers Repl replaces on the mcp serve path, so a Repl server answers exactly as one built on the SDK alone would. An unknown prompt is InvalidParams (-32602) on every revision. An unknown resource URI is the legacy ResourceNotFound (-32002) before 2026-07-28 and InvalidParams from that revision on — McpServerImpl selects between the two by negotiated version, and McpErrorCode's own documentation says new code should prefer InvalidParams. Issue #75 predates that revision and asked for ResourceNotFound unconditionally, which would answer a modern client with a code its revision no longer uses; the era comes from the same per-request signal (IsSessionlessRequest) every other revision-dependent behaviour in the handler reads. TDD: all four tests red first with InternalError, exactly as the issue observed. Hard-coding ResourceNotFound turns the modern-revision test red, and only that one. Refs #75
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Closes #75.
Previously, an unknown resource URI or prompt name surfaced as
InternalError(-32603). To a host, that looks like a broken server, not a missing resource. Per SEP-2164, both now carry a standard code:2025-11-252026-07-28resources/readwith an unknown URIResourceNotFound(-32002)InvalidParams(-32602)prompts/getwith an unknown nameInvalidParams(-32602)InvalidParams(-32602)This deliberately differs from the issue text. #75 asked for
ResourceNotFoundon every revision, but it was written before 2026-07-28. From that revision on, an unresolvable URI is reported withInvalidParams. The SDK's own handler (McpServerImpl) selects between the two codes by negotiated version, andMcpErrorCode's docs say new code should preferInvalidParams. Repl now answers exactly as a server built on the SDK alone would. The revision comes from the per-request signal the handler already uses for every other revision-dependent behaviour.docs/mcp-conformance.mdgains a row in What differs by revision and a SEP-2164 entry.Out of scope, and unchanged: an unknown tool name still returns a tool result with
isError, whereas the SDK's own handler throwsInvalidParams. #75 names only resources and prompts. I can file it separately if we want parity there too.Test plan
Given_McpProtocolErrorCodes, with the two test names from the issue plus one per revision. All four were red first withInternalError, as the issue observed.ResourceNotFoundturns the modern-revision test red, and only that test.docs/mcp-conformance.md.