fix(mcp): parse SSE-framed responses from mcp-org streamable-HTTP#49
Conversation
After #48 added the Accept header, mcp-org started returning text/event-stream responses for tools/call. res.json() chokes on "event: message\ndata: {...}" framing, surfacing as: SyntaxError: Unexpected token 'e', "event: mes"... is not valid JSON Branch on Content-Type: keep the JSON path for application/json, and add a tiny SSE parser that concatenates data: lines from the first non-empty frame and JSON-parses the result. Failures now include the content-type and a body snippet so future regressions are diagnosable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 913edc2b65
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (const line of frame.split(/\r?\n/)) { | ||
| if (line.startsWith('data:')) dataLines.push(line.slice(5).trimStart()); | ||
| } | ||
| if (dataLines.length > 0) return JSON.parse(dataLines.join('\n')) as Envelope; |
There was a problem hiding this comment.
Continue scanning SSE frames until JSON-RPC result appears
parseSseEnvelope returns after parsing the first SSE frame that has any data: lines, but Streamable HTTP responses are allowed to include JSON-RPC notifications/requests before the actual response. In that case this code will either throw on non-JSON data or parse a non-response message and cause callOrgTool to return empty response, even though a valid result frame appears later in the same stream. The parser should keep iterating frames until it finds a JSON-RPC message with a matching response shape (or exhausts the stream).
Useful? React with 👍 / 👎.
Summary
text/event-stream(SSE) framing, sores.json()blows up onevent: message\ndata: {...}— surfaces asSyntaxError: Unexpected token 'e', "event: mes"... is not valid JSONfrom thelist_org_projects/get_org_health/search_org_tasks/get_org_roadmappassthrough tools.application/json, add a small SSE parser that concatenatesdata:lines from the first non-empty frame and JSON-parses the result.Test plan
pnpm -C backend typecheckcleanmcp__baton__list_org_projectsfrom a fresh Claude Code session and confirm a real JSON envelope comes back (not a parse error).Refs: handoff
2026-05-18-multi-repo-pr-cleanup.md"Key context for next session" item 1 (predicted this exact follow-up). Closes the deferred verification on baton taskb02a1ba9(mcp-org 406).🤖 Generated with Claude Code