Skip to content

fix(mcp): cap legacy SSE line length - #559

Merged
BaaRai merged 2 commits into
BaaRai:mainfrom
Coff0xc:fix/mcp-sse-line
Nov 26, 2026
Merged

BaaRai merged 2 commits into
BaaRai:mainfrom
Coff0xc:fix/mcp-sse-line

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The legacy SSE client read each event with ReadString. One event that never sent a newline was buffered with no limit. The JSON-RPC body and the assembled SSE payload already stop at 8 MiB.

The endpoint announcement and the event loop now use the same cap per line. A longer line is an error and both readers stop. Short same-origin endpoint lines are unchanged.

go test -count=1 ./mcphttp/ passed.

The legacy SSE reader used ReadString, so one event with no newline was
buffered without a limit. Stop a line that grows past the existing
JSON-RPC buffer cap in both the endpoint announcement and the event loop.
@5P34R

5P34R commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review notes

Looks good to merge. readLimitedLine is correct: the loop, end-of-file handling and bounds all check out.

Nit: the 8 MiB cap counts the whole line, including data: and \r\n, so a payload of exactly 8 MiB is rejected. The existing streamable-HTTP parseSSE scanner (mcphttp/client.go:675) does the same, so the two paths are consistent.

BaaRai added a commit that referenced this pull request Nov 26, 2026
BaaRai added a commit that referenced this pull request Nov 26, 2026
BaaRai added a commit that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai merged commit 26533db into BaaRai:main Nov 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants