modelcontextprotocol / modelcontextprotocol/typescript-sdk

Invalid JSON RPC requests do not respond with an error

Open
#563 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed improves spec compliance P2 ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

I noticed that this request:

{"jsonrpc": "2.0", "id": 1, "method": "tools/lit", "params": {}}

... returns an error response (code -32601) as expected but this:

{"jsonrpc": "2.0", "id": 1, "method_": "tools/list", "params": {}}

... returns nothing. I would expect that a missing method property or an unknown root property like methodX would throw and error. The JSON-RPC 2.0 spec says the server should return:

  • -32600 "Invalid Request" for malformed JSON-RPC (missing required fields like method)
  • -32602 "Invalid params" for bad parameters

I think the SDK should handle these but I'm not even able to write validation logic in my application code because an invalid RPC request never reaches my handler.

Claude tells me I can do something like this:

class ValidatingStdioTransport extends StdioServerTransport {
  // Override message handling to add validation
}

.. but I don't love that.

If a maintainer agrees that this validation should be in the SDK, I'd be more than happy to write a PR! Thank you for all your work on this!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing StdioServerTransport's message-handling entry point and how requests are dispatched before reaching application handlers. Reproduce the missing-method and unknown-root-property examples, then verify that malformed JSON-RPC requests produce the specified -32600 or -32602 errors instead of no response.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.