Skip to content

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

@corv89

Description

@corv89

Initial Checks

Description

How to reproduce:

echo '{"jsonrpc":"2.0","method":"invalid/method","id":1,"params":{}}' | your-mcp-server

Expected result:

{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"Method not found"}}

Actual result:

{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Invalid request parameters","data":""}}

The issue appears to occur because request validation in mcp/shared/session.py (lines 360-375) catches the validation exception and returns -32602 before the proper method-not-found handler in mcp/server/lowlevel/server.py (lines 716-718) can be reached.

Example Code

Python & MCP Python SDK

**Environment:**
- Python SDK version: `1.2.0`
- Python version: `3.12`
- Platform: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesneeds confirmationNeeds confirmation that the PR is actually required or needed.specSpecification compliance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions