fix(mcp-bridge): encode stderr notifications as JSON#13549
Open
shreemaan-abhishek wants to merge 5 commits into
Open
fix(mcp-bridge): encode stderr notifications as JSON#13549shreemaan-abhishek wants to merge 5 commits into
shreemaan-abhishek wants to merge 5 commits into
Conversation
Build the notifications/stderr message with core.json.encode instead of string concatenation, so subprocess stderr output containing double quotes, backslashes or other JSON special characters no longer breaks the framing of the JSON-RPC notification sent to the client.
There was a problem hiding this comment.
Pull request overview
This PR fixes malformed notifications/stderr JSON-RPC notifications emitted by the mcp-bridge plugin when the subprocess writes stderr lines containing JSON-special characters, by switching from manual string concatenation to core.json.encode.
Changes:
- Build
notifications/stderrmessages viacore.json.encodeto ensure correct JSON escaping. - Add a regression test that feeds stderr content containing quotes, backslashes, and
}}, and asserts the notification JSON round-trips correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
apisix/plugins/mcp-bridge.lua |
Switch stderr notification construction to JSON encoding instead of string concatenation. |
t/plugin/mcp-bridge.t |
Add a regression test ensuring stderr content with JSON-special characters yields valid JSON. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Extract the notifications/stderr message construction into a helper that is also exercised directly by the regression test, log the encode error on the fallback path, and reap the spawned subprocess in the test.
Document the mcp-bridge plugin in both languages, add it to the AI plugin category in the sidebars, and note that the plugin is currently experimental.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The
mcp-bridgeplugin forwards a spawned MCP subprocess's stderr to theclient as a
notifications/stderrJSON-RPC message. The message was builtby concatenating the raw stderr line into a JSON string literal, so any
stderr output containing JSON special characters (double quotes,
backslashes, etc.) produced a malformed JSON-RPC notification and broke the
framing of the message sent to the client.
This change builds the notification with
core.json.encodeinstead, whichproperly escapes the content. A regression test in
t/plugin/mcp-bridge.tfeeds a stderr line containing quotes, a backslash and a
}}sequence andasserts the resulting notification is well-formed JSON that round-trips back
to the original content.
Which issue(s) this PR fixes:
Fixes #
Checklist