Skip to content

rmcp shouldn't respond to unparseable messages #938

Description

@stephentoub

Describe the bug
When rmcp receives invalid json, it sends back {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}. As far as I can tell, it's the only one of the official MCP SDKs that responds in this manner to invalid data. Most of the others just ignore invalid data, and none of the others respond. The problem with responding is it can trigger a storm of communication, where the client sending this back triggers the server to respond with more invalid data, which triggers another "parse error" response, which triggers more invalid data, and so on. I ported a component from TypeScript to Rust and thus switched from the TypeScript SDK to the Rust SDK, and it immediately caused problems when talking to a server that (erroneously) was putting some logging onto stdout.

To Reproduce
Try to connect to a stdio server that puts invalid data onto stdout, e.g. a logging message every time data is received.

Expected behavior
The invalid data will be ignored (this happens) and no response will be sent back (this doesn't happen).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions