fix(brainbar): compact tools list for Claude MCPB#275
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughThe PR adds response preprocessing for newline-delimited JSON-RPC transport to remove tool annotations before encoding, keeping raw responses under size limits. Content-Length framed responses are unaffected. Tests verify annotations are preserved in standard framing and omitted in raw-line mode. ChangesAnnotation Compaction for Raw-Line Transport
Sequence DiagramsequenceDiagram
participant Client as Client
participant Server as BrainBarServer
participant Framing as MCPFraming
participant Response as Response
rect rgba(100, 150, 200, 0.5)
Note over Client,Response: Content-Length Framing (Preserves Annotations)
Client->>Server: tools/list request
Server->>Response: build full response with annotations
Response->>Framing: encodeJSONResponse(response)
Framing->>Client: Content-Length framed response (preserves annotations)
end
rect rgba(150, 200, 100, 0.5)
Note over Client,Response: Raw Newline-Delimited (Compacts Annotations)
Client->>Server: tools/list request (raw line)
Server->>Response: build full response with annotations
Server->>Server: compactRawJSONResponseIfNeeded (remove tool annotations)
Response->>Framing: encodeJSONResponse(compacted response)
Framing->>Client: newline-delimited response (no annotations, <8192 bytes)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
@coderabbitai review |
|
@codex review |
✅ Actions performedReview triggered.
|
|
Excellent! Now let me write a comprehensive review of this PR. Based on my analysis: 🔍 Bugbot Review: PR #275 - Fix BrainBar MCPB Tools List SizeSummaryThis PR successfully fixes a critical Claude Desktop boot failure by reducing the BrainLayer MCPB ✅ What Works Well1. Root Cause Analysis is Spot-On 2. Elegant Two-Layer Design // Public API: compact, fits in 8 KiB
static let compactToolDefinitions: [[String: Any]] = toolDefinitions.map { tool in
var compact = tool
compact.removeValue(forKey: "annotations")
return compact
}
// Internal: full annotations for testing/docs
static let toolDefinitions: [[String: Any]] = [...]This preserves the annotation taxonomy internally while keeping the wire format lean. 3. Test Coverage is Comprehensive
4. Performance Impact: Zero 🔬 Technical CorrectnessArchitecture:
Test Changes:
Byte Budget Math:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a1301690d
ℹ️ 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".
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Addressed Codex P1 in 4b1f020: canonical MCPRouter tools/list and Content-Length/framed socket responses now preserve full tool annotations. The sub-8192-byte compaction is scoped only to raw newline transport used by Claude Desktop's MCPB extension bridge, with a regression test covering both paths. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b1f020c4e
ℹ️ 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".
|
Addressed latest Codex P2 in 99371eb: raw newline responses now encode the canonical payload first and preserve annotations whenever the message is below the 8192-byte Claude MCPB chunk limit. Compaction only runs for oversized tools/list responses. |
|
@codex review |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |


Summary
tools/listresponse below Claude Desktop MCPB's observed 8192-byte raw stdout parse boundary by omitting optional toolannotationsfrom the response.MCPRouter.toolDefinitions, so tool safety metadata remains documented and tested internally.Root Cause
Claude Desktop config shows BrainLayer Memory is managed by the installed MCPB extension:
node /Users/etanheyman/Library/Application Support/Claude/Claude Extensions/local.mcpb.etan-heyman.brainlayer/server/index.jswith
BRAINBAR_SOCKET=/tmp/brainbar.sock.Claude Desktop logs show the utility process attempts to parse the raw stdout stream in 8192-byte chunks. The previous
tools/listresponse was 8995 bytes, so Claude parsed the first chunk as an unterminated JSON string and then parsed the second chunk as a separate JSON-RPC message.Raw bytes captured from the deployed Node extension path before this fix:
Claude's own UI/log error matches the second fragment beginning at
agent_id:Tests
swift test --package-path brain-bar --filter MCPRouterTests/testEncodedToolsListFitsClaudeExtensionRawMessageLimitfailed before fix with8995bytes and annotations present.swift test --package-path brain-bar --filter MCPRouterTests/testEncodedToolsListFitsClaudeExtensionRawMessageLimitpassed after fix.swift test --package-path brain-bar --filter MCPRouterTestspassed: 45 tests, 0 failures.swift test --package-path brain-bar --filter MCPFramingTestspassed: 8 tests, 0 failures.swift test --package-path brain-bar --filter SocketIntegrationTests/testMCPToolsListOverSocketpassed.swift test --package-path brain-barpassed: 340 tests, 0 failures../scripts/run_tests.shpassed: pytest unit suite 1823 passed, 9 skipped, 75 deselected, 1 xfailed; MCP registration 3 passed; isolated eval/hook routing 32 passed; bun suite 1 pass; FTS5 regression PASS../scripts/run_tests.shand passed with the same suites.Deploy Verification Plan
After merge: pull main, pause enrichment, rebuild/reinstall BrainBar, restart BrainBar, then launch the MCPB Node extension bridge and verify the raw
tools/listline is below 8192 bytes and Claude logs no longer showUnterminated string in JSON at position 8192orInvalid JSON-RPC message: agent_id.Note
Medium Risk
Changes JSON-RPC output for newline-delimited transport by conditionally stripping
annotations, which could affect clients relying on that metadata or any large raw responses near the size threshold.Overview
Fixes Claude Desktop MCPB newline-delimited JSON parsing failures by conditionally compacting oversized raw JSON-RPC responses.
When
BrainBarServersends newline-delimited responses (noContent-Length), it now enforces an 8192-byte safety limit by re-encodingtools/listwith per-toolannotationsremoved if needed; framed (Content-Length) responses keep the canonical payload (including annotations).Tests are updated/added to assert canonical
tools/listkeeps annotations, framed socket transport still includes annotations even when >8192 bytes, and raw-line transport returns a sub-8192-bytetools/listwith annotations omitted.Reviewed by Cursor Bugbot for commit 99371eb. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Compact
tools/listresponse for Claude MCP raw newline transport when payload exceeds 8192 bytesBrainBarServernow strips theannotationsfield from each tool intools/listresults if the encoded payload is ≥ 8192 bytes.encodeRawJSONResponse(_:)helper handles size detection and delegates tocompactRawJSONResponseIfNeeded(_:)for compaction, falling back to the original encoding if compaction fails.annotationsomitted, while framed responses retainannotations.annotationsintools/listresponses when the payload is large.Macroscope summarized 99371eb.
Summary by CodeRabbit
Bug Fixes
Tests