You can make MCP server log error, send response and then abruptly exit, with a json input malformed at the end
$ go run github.com/modelcontextprotocol/go-sdk/examples/hello
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"roots":{"listChanged":true},"sampling":{},"elicitation":{}},"clientInfo":{"name":"ExampleClient","title":"Example Client Display Name","version":"1.0.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"},
$ go run github.com/modelcontextprotocol/go-sdk/examples/hello
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"roots":{"listChanged":true},"sampling":{},"elicitation":{}},"clientInfo":{"name":"ExampleClient","title":"Example Client Display Name","version":"1.0.0"}}}
read: {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"roots":{"listChanged":true},"sampling":{},"elicitation":{}},"clientInfo":{"name":"ExampleClient","title":"Example Client Display Name","version":"1.0.0"}}}
{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"completions":{},"logging":{},"prompts":{"listChanged":true},"resources":{"listChanged":true},"tools":{"listChanged":true}},"protocolVersion":"2024-11-05","serverInfo":{"name":"greeter","version":""}}}
write: {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"completions":{},"logging":{},"prompts":{"listChanged":true},"resources":{"listChanged":true},"tools":{"listChanged":true}},"protocolVersion":"2024-11-05","serverInfo":{"name":"greeter","version":""}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
read: {"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"},
read: {"jsonrpc":"2.0","id":1,"method":"tools/list"}
read error: invalid character ',' looking for beginning of value{"jsonrpc":"2.0","id":1,"result":{"tools":[{"description":"say hi","inputSchema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"the name to say hi to"}},"additionalProperties":{"not":{}}},"name":"greet","outputSchema":{"type":"object","additionalProperties":{"not":{}}}}]}}
write: {"jsonrpc":"2.0","id":1,"result":{"tools":[{"description":"say hi","inputSchema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"the name to say hi to"}},"additionalProperties":{"not":{}}},"name":"greet","outputSchema":{"type":"object","additionalProperties":{"not":{}}}}]}}
You can make MCP server log error, send response and then abruptly exit, with a json input malformed at the end
To Reproduce
Steps to reproduce the behavior:
initializenotifications/initializedtools/listby malforming it at the endExpected behavior
Server should handle invalid json input and report it as an error without sending the valid tool/list response and exiting
Logs