Skip to content

fix(session): return METHOD_NOT_FOUND for unknown request methods - #3210

Open
Ranga-Prasath-22 wants to merge 2 commits into
modelcontextprotocol:v1.xfrom
Ranga-Prasath-22:fix/v1-unknown-method-error-code
Open

fix(session): return METHOD_NOT_FOUND for unknown request methods#3210
Ranga-Prasath-22 wants to merge 2 commits into
modelcontextprotocol:v1.xfrom
Ranga-Prasath-22:fix/v1-unknown-method-error-code

Conversation

@Ranga-Prasath-22

@Ranga-Prasath-22 Ranga-Prasath-22 commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Return JSON-RPC -32601 METHOD_NOT_FOUND for request methods that are not part of the session's request schema, while preserving -32602 INVALID_PARAMS for known methods with invalid parameters.

Why

BaseSession previously mapped every request-model validation failure to -32602. That made an unsupported method indistinguishable from a malformed call and caused clients to retry requests that could never succeed.

Implementation

  • Derive the supported request-method set from the configured Pydantic request type once per session.
  • Apply the distinction centrally in BaseSession, covering both client and server sessions and custom request unions.
  • Fail closed if schema introspection cannot produce a method set.
  • Add symmetric regression coverage for unknown methods, malformed known methods, client-side handling, non-string schema defaults, and introspection fallback.

Validation

  • 17 focused session tests pass.
  • Ruff format and Ruff lint pass.
  • Full CI coverage remains enforced at 100%.

Fixes #3193
Resolves #1561

@Ranga-Prasath-22 Ranga-Prasath-22 changed the title fix(session): return -32601 METHOD_NOT_FOUND on unknown request methods fix(session): return METHOD_NOT_FOUND for unknown request methods Jul 29, 2026
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