Skip to content

fix(server): gate resource not found errors by protocol version - #973

Open
Jokasa7 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Jokasa7:JoyCx/fix-sep-2164-resource-errors
Open

fix(server): gate resource not found errors by protocol version#973
Jokasa7 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Jokasa7:JoyCx/fix-sep-2164-resource-errors

Conversation

@Jokasa7

@Jokasa7 Jokasa7 commented Aug 30, 2026

Copy link
Copy Markdown

Implements the server-side resource-not-found error selection from SEP-2164 while preserving the behavior of currently negotiated 2025 protocol versions.

  • retain the negotiated protocol version on each server session
  • return the legacy RESOURCE_NOT_FOUND (-32002) through MCP 2025-11-25
  • return INVALID_PARAMS (-32602) for MCP 2026-07-28 and later
  • preserve the existing error message and data.uri payload
  • document both error-code roles and add decision, handshake, and transport coverage

Motivation and Context

Refs #805. Related lifecycle work: #815.

SEP-2164 standardizes an unknown resources/read URI as JSON-RPC INVALID_PARAMS for the 2026-07-28 specification. Applying that code unconditionally would change the wire behavior of clients that negotiate one of the SDK's currently supported 2025 protocol versions.

This change therefore makes the decision at the server boundary using the version retained from initialization. The ISO YYYY-MM-DD comparison follows the compatibility approach already used by the official C# and Rust SDK implementations. Unsupported initialization versions still fall back to LATEST_PROTOCOL_VERSION, so they cannot accidentally opt into a future error contract.

How Has This Been Tested?

  • gradlew.bat ktlintCheck detekt apiCheck — passed (173 tasks; 80 executed and 93 up-to-date).
  • Focused core/server tests for JsonRpcTest, ResourceNotFoundErrorCodeTest, and ServerSessionAssertCapabilityTest — 29 passed.
  • Linux JVM resource integration tests for ServerResourceTemplateTest and the stdio, SSE, and Streamable HTTP ResourceIntegrationTest variants — 47 passed, 0 failed, 0 skipped.
  • A wider Windows JVM run completed the core (598 tests) and server (232 tests) suites without failures. Its TypeScript interop tests could not launch because ProcessBuilder("npx", ...) does not resolve the installed Windows npx.cmd; the affected resource integrations were therefore rerun successfully under Linux, where npx is executable.

The 2026+ decision branch is unit-tested, but full 2026-07-28 wire-level coverage is not yet reachable because this SDK does not currently negotiate the modern lifecycle. That end-to-end path depends on #815; this PR does not claim complete 2026-07-28 conformance.

Breaking Changes

There is no behavior change for the SDK's currently supported 2025 protocol versions: missing resources continue to return -32002.

Once a session can negotiate MCP 2026-07-28 or later, the same condition will intentionally return -32602 as required by SEP-2164. The public RESOURCE_NOT_FOUND constant remains available with its legacy -32002 value.

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

This contribution was developed with Codex assistance. The implementation was checked against #805, SEP-2164, the current protocol-version negotiation behavior, and official C# and Rust SDK precedents, then verified with the focused checks above.

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.

1 participant