Skip to content

Return METHOD_NOT_FOUND for invalid request methods#2372

Open
raashish1601 wants to merge 1 commit intomodelcontextprotocol:mainfrom
raashish1601:contributor-26/python-sdk-1561
Open

Return METHOD_NOT_FOUND for invalid request methods#2372
raashish1601 wants to merge 1 commit intomodelcontextprotocol:mainfrom
raashish1601:contributor-26/python-sdk-1561

Conversation

@raashish1601
Copy link
Copy Markdown

Fixes #1561.

Summary

  • return METHOD_NOT_FOUND for unknown JSON-RPC request methods instead of collapsing them into the generic request-validation INVALID_PARAMS fallback
  • keep INVALID_PARAMS for malformed known methods by only special-casing method names that are outside the typed client request union
  • add a focused regression proving invalid/method returns -32601 while malformed initialize still returns -32602

Testing

  • PYTHONPATH=src python -m pytest -o addopts="" tests/issues/test_1561_invalid_method_names.py -q
  • python -m ruff check src/mcp/shared/session.py src/mcp/server/session.py tests/issues/test_1561_invalid_method_names.py
  • git diff --check

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.

Invalid method names return error code -32602 instead of -32601

1 participant