Skip to content

fix(mcp): parse SSE data fields with optional spaces - #940

Open
rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/mcp-sse-data-fields
Open

rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/mcp-sse-data-fields

Conversation

@rudycelekli

Copy link
Copy Markdown

What changed

SSE allows data values immediately after the colon. The client discarded those lines and could lose valid MCP results from gateways that omit the optional space. Consume data fields with either separator, preserving whitespace beyond the optional first space. Spec: https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream

Scope

  • Platform core / API / runner

Validation

A multiline JSON-RPC response containing both valid data field forms fails on main. The mcpclient package tests and vet pass with the fix.

Full platform build and public browser checks were not run for this branch. All fixtures are synthetic.

@Yanami-2K Yanami-2K left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

核对了 readSSE:用 strings.CutPrefix(line, "data:") 后只去掉一个可选空格,符合 WHATWG SSE 解析规则,其余空白保持不变,原有的 data: 写法也不受影响。新测试在同一个事件里混用两种写法拼出多行 JSON-RPC,并断言结果完整,改动小且正确。提醒:#935、#936、#939 也在改 mcpclient/client.go,不过本 PR 只动了 readSSE,冲突风险很低。

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.

2 participants