Skip to content

fix(mcp-bridge): encode stderr notifications as JSON#13549

Open
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:fix/mcp-bridge-stderr-json-encode
Open

fix(mcp-bridge): encode stderr notifications as JSON#13549
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:fix/mcp-bridge-stderr-json-encode

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

The mcp-bridge plugin forwards a spawned MCP subprocess's stderr to the
client as a notifications/stderr JSON-RPC message. The message was built
by 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.encode instead, which
properly escapes the content. A regression test in t/plugin/mcp-bridge.t
feeds a stderr line containing quotes, a backslash and a }} sequence and
asserts the resulting notification is well-formed JSON that round-trips back
to the original content.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

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.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant