Ignore non-parseable lines on stdout. #434
Open
+7
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
As reported in #412, a non-conforming stdio transport-based server can break this client library by writing non-JSONRPC text to stdout before the initialization handshake.
This changes the
JsonRpcMessageCodec::decode
to ignore lines that don't parse as JSONRPC instead of propagating up an error.How Has This Been Tested?
Tested this in Warp, using the
@circleci/mcp-server-circleci
server. We've had this change live in production (via a fork) for a week now and have not received any reports from users of it causing issues.Breaking Changes
No, this does not affect any public APIs, and should strictly improve compatibility with stdio-based MCP servers.
Types of changes
Checklist
Additional context
Important
I don't love this change. While it is effective (and was a good quick fix in our fork), it ultimately makes behavioral decisions in parsing code that belong in calling code.
I think the better fix here is to change the signature of
Transport::receive()
to produceResult<RxJsonRpcMessage<R>, _>
instead ofOption<RxJsonRpcMessage<R>>
, so that we can surface errors to the service layer and let it make decisions. For example, the service layer might want to ignore decoding errors (and read another message), but handle I/O errors.Figured I'd start by sending this change as-is in case y'all are ok with it as a quick fix for the problem, and want to make the API change later (given that it would be a semver breaking change).