Skip to content

fix(mcp): parse SSE-framed responses from mcp-org streamable-HTTP#49

Merged
JustAGhosT merged 1 commit into
mainfrom
fix/mcp-org-sse-parse
May 18, 2026
Merged

fix(mcp): parse SSE-framed responses from mcp-org streamable-HTTP#49
JustAGhosT merged 1 commit into
mainfrom
fix/mcp-org-sse-parse

Conversation

@JustAGhosT

Copy link
Copy Markdown
Collaborator

Summary

  • Follow-up to fix(mcp): add Accept header for streamable-HTTP transport on orgClient #48. The Accept header fix made requests succeed, but mcp-org now responds with text/event-stream (SSE) framing, so res.json() blows up on event: message\ndata: {...} — surfaces as SyntaxError: Unexpected token 'e', "event: mes"... is not valid JSON from the list_org_projects/get_org_health/search_org_tasks/get_org_roadmap passthrough tools.
  • Branch on Content-Type: keep the JSON path for application/json, add a small SSE parser that concatenates data: lines from the first non-empty frame and JSON-parses the result.
  • Error messages now include the content-type and a body snippet so future regressions are diagnosable.

Test plan

  • pnpm -C backend typecheck clean
  • After Railway redeploy: call mcp__baton__list_org_projects from 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 task b02a1ba9 (mcp-org 406).

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@JustAGhosT has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 7 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1d7886c-5b75-443a-9eb2-bc54e5bd3b0b

📥 Commits

Reviewing files that changed from the base of the PR and between 3f102e3 and 913edc2.

📒 Files selected for processing (1)
  • backend/src/mcp/orgClient.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-org-sse-parse

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@JustAGhosT JustAGhosT merged commit 1ce82da into main May 18, 2026
3 checks passed
@JustAGhosT JustAGhosT deleted the fix/mcp-org-sse-parse branch May 18, 2026 09:55
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.

1 participant