-
Notifications
You must be signed in to change notification settings - Fork 7
fix(brainbar): stabilize json-rpc envelope order #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -140,6 +140,24 @@ final class MCPRouterTests: XCTestCase { | |||||||||||||||
| XCTAssertEqual(toolNames, expected) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func testEncodedToolsListEnvelopeStartsWithJSONRPC() throws { | ||||||||||||||||
| let router = MCPRouter() | ||||||||||||||||
| let response = router.handle([ | ||||||||||||||||
| "jsonrpc": "2.0", | ||||||||||||||||
| "id": 2, | ||||||||||||||||
| "method": "tools/list", | ||||||||||||||||
| ]) | ||||||||||||||||
|
|
||||||||||||||||
| let framed = try MCPFraming.encode(response) | ||||||||||||||||
| let frame = try XCTUnwrap(String(data: framed, encoding: .utf8)) | ||||||||||||||||
| let body = try XCTUnwrap(frame.components(separatedBy: "\r\n\r\n").last) | ||||||||||||||||
|
|
||||||||||||||||
| XCTAssertTrue( | ||||||||||||||||
| body.hasPrefix(#"{"jsonrpc":"2.0","id":2,"result":"#), | ||||||||||||||||
| "Claude Desktop expects jsonrpc to be the first envelope key for tools/list; got: \(body.prefix(80))" | ||||||||||||||||
|
Comment on lines
+155
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the expected prefix.
🔧 Proposed fix- XCTAssertTrue(
- body.hasPrefix(#"{"jsonrpc":"2.0","id":2,"result":"#),
- "Claude Desktop expects jsonrpc to be the first envelope key for tools/list; got: \(body.prefix(80))"
- )
+ XCTAssertTrue(
+ body.hasPrefix(#"{"jsonrpc":"2.0","id":2,"result":{"#),
+ "Claude Desktop expects jsonrpc to be the first envelope key for tools/list; got: \(body.prefix(80))"
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| ) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func testEachToolHasInputSchema() throws { | ||||||||||||||||
| let router = MCPRouter() | ||||||||||||||||
| let request: [String: Any] = [ | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep notification envelopes on the deterministic path too.
This helper still falls back to
JSONSerializationwhenresult/erroris absent, so newline-delimited notifications can still come out with Foundation-dependent top-level ordering. If those messages hit the same client/parser, the original ordering bug is not fully closed here.🤖 Prompt for AI Agents