Skip to content

fix(transport): Handle multi-line and concatenated JSON-RPC messages#57

Closed
mrchypark wants to merge 1 commit intomattt:mainfrom
mrchypark:main
Closed

fix(transport): Handle multi-line and concatenated JSON-RPC messages#57
mrchypark wants to merge 1 commit intomattt:mainfrom
mrchypark:main

Conversation

@mrchypark
Copy link

This pull request fixes an issue in the Stdio transport where it incorrectly assumes that each JSON-RPC message arrives on a single line. The previous implementation would parse each line break, leading to Parse error for valid, formatted multi-line JSON inputs.

This change modifies the reader goroutine in mcp/transport.go to:

  1. Buffer incoming data from the reader.
  2. Intelligently scan the buffer for a complete JSON object by tracking the balance of curly braces ({}), while correctly ignoring braces inside string literals.
  3. Only attempt to process a message once a full, valid JSON object has been detected in the buffer.

This new approach ensures that emcee can robustly handle:

  • Formatted, multi-line JSON objects.
  • Multiple JSON objects sent in a single stream (concatenated).

This significantly improves the usability and robustness of the Stdio transport, making it more resilient to different input formats.

@mattt
Copy link
Owner

mattt commented Aug 14, 2025

Hi @mrchypark. Thanks so much for contributing this PR.

emcee pre-dates any community implementations of the MCP spec in Go, and this was also my first introduction to the protocol. So there are a bunch of problems like this. I just merged #58, which swaps in the official Go SDK. This is now available in the latest release (v0.6.0).

Can you please give that a try and let me know if you're still seeing this issue?

@mrchypark
Copy link
Author

good to me version 0.6.0

thank you!

@mattt
Copy link
Owner

mattt commented Aug 15, 2025

@mrchypark Awesome. Thanks so much for confirming. I'll go ahead and close this PR.

@mattt mattt closed this Aug 15, 2025
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.

2 participants