Skip to content

mcp_transcoder: add sse server response support.#45374

Open
guoyilin42 wants to merge 4 commits into
envoyproxy:mainfrom
guoyilin42:sse
Open

mcp_transcoder: add sse server response support.#45374
guoyilin42 wants to merge 4 commits into
envoyproxy:mainfrom
guoyilin42:sse

Conversation

@guoyilin42
Copy link
Copy Markdown
Contributor

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-stream content type, the filter will now parse the stream and wrap each extracted complete event payload into a distinct text content item within the JSON-RPC content array on the fly.

Key Changes:

  • Added SseResponseExtractor: Introduced sse_response_extractor.cc and its header to process incoming chunks of an SSE stream and return completed event payloads.
  • Updated McpJsonRestBridgeFilter: Modified the encoding path to check for the text/event-stream content type. It now delegates chunk processing to the new SSE extractor and formats the results into the JSON-RPC streaming envelope.
  • Testing: Added unit tests in sse_response_extractor_test.cc to verify the handling of single/multiple events, multiline data, incomplete chunked events, and CRLF line endings. Also added ToolsCallSseStreamingTranscoding to integration tests.

Risk Level: Low
Testing: Unit and Integration tests.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

Signed-off-by: Yilin Guo <guoyilin@google.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #45374 was opened by guoyilin42.

see: more, trace.

@guoyilin42
Copy link
Copy Markdown
Contributor Author

/gemini review

cc @paulhong01

#44146

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread source/extensions/filters/http/mcp_json_rest_bridge/sse_response_extractor.cc Outdated
Comment thread source/extensions/filters/http/mcp_json_rest_bridge/sse_response_extractor.h Outdated
Signed-off-by: Yilin Guo <guoyilin@google.com>
Signed-off-by: Yilin Guo <guoyilin@google.com>
Signed-off-by: Yilin Guo <guoyilin@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants