Skip to content

fix(mcp): answer an unknown resource or prompt with a standard error code - #107

Open
carldebilly wants to merge 1 commit into
mainfrom
dev/cdb/mcp-sep-2164-error-codes
Open

carldebilly wants to merge 1 commit into
mainfrom
dev/cdb/mcp-sep-2164-error-codes

Conversation

@carldebilly

Copy link
Copy Markdown
Member

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:

Request 2025-11-25 2026-07-28
resources/read with an unknown URI ResourceNotFound (-32002) InvalidParams (-32602)
prompts/get with an unknown name InvalidParams (-32602) InvalidParams (-32602)

This deliberately differs from the issue text. #75 asked for ResourceNotFound on every revision, but it was written before 2026-07-28. From that revision on, an unresolvable URI is reported with InvalidParams. The SDK's own handler (McpServerImpl) selects between the two codes by negotiated version, and McpErrorCode's docs say new code should prefer InvalidParams. 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.md gains 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 throws InvalidParams. #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 with InternalError, as the issue observed.
  • Hard-coding ResourceNotFound turns the modern-revision test red, and only that test.
  • Repl.Tests 803, Repl.IntegrationTests 641 (+10 skipped), Repl.McpTests 327 (+1 skipped), Repl.SpectreTests 17.
  • markdownlint clean on docs/mcp-conformance.md.

…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
@carldebilly carldebilly added this to the 0.12.0 milestone Sep 22, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-22T22:11:00.308516Z d7bb66e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

SEP-2164 compliance: return ResourceNotFound/InvalidParams error codes for unknown resources and prompts

1 participant