mcp_transcoder: add sse server response support.#45374
Conversation
Signed-off-by: Yilin Guo <guoyilin@google.com>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
|
/gemini review cc @paulhong01 |
There was a problem hiding this comment.
Code Review
This pull request introduces support for Server-Sent Events (SSE) responses in the MCP JSON-RPC REST bridge filter. It adds an SseResponseExtractor to parse incoming text/event-stream chunks on the fly and wrap completed event payloads into distinct text items within the JSON-RPC content array. The review feedback highlights two critical robustness and security concerns: first, nlohmann::json::dump() could throw an exception and crash Envoy if it encounters invalid UTF-8 in the untrusted upstream payload, which should be mitigated by using a safe error-handling replacement strategy; second, the unbounded buffering of incomplete SSE events poses a memory exhaustion (DoS) risk, necessitating a maximum buffer size limit.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Signed-off-by: Yilin Guo <guoyilin@google.com>
Signed-off-by: Yilin Guo <guoyilin@google.com>
Signed-off-by: Yilin Guo <guoyilin@google.com>
Commit Message: mcp_transcoder: add sse server response support.
Additional Description:
This PR introduces Server-Sent Events (SSE) server response support to the MCP JSON REST bridge filter. When the upstream server responds with a
text/event-streamcontent type, the filter will now parse the stream and wrap each extracted complete event payload into a distinct text content item within the JSON-RPCcontentarray on the fly.Key Changes:
SseResponseExtractor: Introducedsse_response_extractor.ccand its header to process incoming chunks of an SSE stream and return completed event payloads.McpJsonRestBridgeFilter: Modified the encoding path to check for thetext/event-streamcontent type. It now delegates chunk processing to the new SSE extractor and formats the results into the JSON-RPC streaming envelope.sse_response_extractor_test.ccto verify the handling of single/multiple events, multiline data, incomplete chunked events, and CRLF line endings. Also addedToolsCallSseStreamingTranscodingto integration tests.Risk Level: Low
Testing: Unit and Integration tests.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A