-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix(patch): cherry-pick 1cae5ab to release/v0.28.0-preview.3-pr-18376 to patch version v0.28.0-preview.3 and create version 0.28.0-preview.4 #18463
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
Merged
skeshive
merged 1 commit into
release/v0.28.0-preview.3-pr-18376
from
hotfix/v0.28.0-preview.3/0.28.0-preview.4/preview/cherry-pick-1cae5ab/pr-18376
Feb 6, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/core/src/tools/xcode-mcp-fix-transport.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { EventEmitter } from 'node:events'; | ||
| import { XcodeMcpBridgeFixTransport } from './xcode-mcp-fix-transport.js'; | ||
| import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; | ||
| import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js'; | ||
|
|
||
| // Mock Transport that simulates the mcpbridge behavior | ||
| class MockBadMcpBridgeTransport extends EventEmitter implements Transport { | ||
| onclose?: () => void; | ||
| onerror?: (error: Error) => void; | ||
| onmessage?: (message: JSONRPCMessage) => void; | ||
|
|
||
| async start() {} | ||
| async close() {} | ||
| async send(_message: JSONRPCMessage) {} | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| emitMessage(msg: any) { | ||
| this.onmessage?.(msg); | ||
| } | ||
| } | ||
|
|
||
| describe('Xcode MCP Bridge Fix', () => { | ||
| it('intercepts and fixes the non-compliant mcpbridge response', async () => { | ||
| const mockTransport = new MockBadMcpBridgeTransport(); | ||
| const fixTransport = new XcodeMcpBridgeFixTransport(mockTransport); | ||
|
|
||
| // We need to capture what the fixTransport emits to its listeners | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const messages: any[] = []; | ||
| fixTransport.onmessage = (msg) => { | ||
| messages.push(msg); | ||
| }; | ||
|
|
||
| await fixTransport.start(); | ||
|
|
||
| // SCENARIO 1: Bad response from Xcode | ||
| // It has `content` stringified JSON, but misses `structuredContent` | ||
| const badPayload = { | ||
| jsonrpc: '2.0', | ||
| id: 1, | ||
| result: { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify({ | ||
| windows: [{ title: 'HelloWorld', path: '/path/to/project' }], | ||
| }), | ||
| }, | ||
| ], | ||
| // Missing: structuredContent | ||
| }, | ||
| }; | ||
|
|
||
| mockTransport.emitMessage(badPayload); | ||
|
|
||
| // Verify the message received by the client (listener of fixTransport) | ||
| const fixedMsg = messages.find((m) => m.id === 1); | ||
| expect(fixedMsg).toBeDefined(); | ||
| expect(fixedMsg.result.structuredContent).toBeDefined(); | ||
| expect(fixedMsg.result.structuredContent.windows[0].title).toBe( | ||
| 'HelloWorld', | ||
| ); | ||
|
|
||
| // SCENARIO 2: Good response (should be untouched) | ||
| const goodPayload = { | ||
| jsonrpc: '2.0', | ||
| id: 2, | ||
| result: { | ||
| content: [{ type: 'text', text: 'normal text' }], | ||
| structuredContent: { some: 'data' }, | ||
| }, | ||
| }; | ||
| mockTransport.emitMessage(goodPayload); | ||
|
|
||
| const goodMsg = messages.find((m) => m.id === 2); | ||
| expect(goodMsg).toBeDefined(); | ||
| expect(goodMsg.result.structuredContent).toEqual({ some: 'data' }); | ||
| }); | ||
|
|
||
| it('ignores responses that cannot be parsed as JSON', async () => { | ||
| const mockTransport = new MockBadMcpBridgeTransport(); | ||
| const fixTransport = new XcodeMcpBridgeFixTransport(mockTransport); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const messages: any[] = []; | ||
| fixTransport.onmessage = (msg) => { | ||
| messages.push(msg); | ||
| }; | ||
|
|
||
| await fixTransport.start(); | ||
|
|
||
| const nonJsonPayload = { | ||
| jsonrpc: '2.0', | ||
| id: 3, | ||
| result: { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: "Just some plain text that isn't JSON", | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| mockTransport.emitMessage(nonJsonPayload); | ||
|
|
||
| const msg = messages.find((m) => m.id === 3); | ||
| expect(msg).toBeDefined(); | ||
| expect(msg.result.structuredContent).toBeUndefined(); | ||
| expect(msg.result.content[0].text).toBe( | ||
| "Just some plain text that isn't JSON", | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,101 @@ | ||||||
| /** | ||||||
| * @license | ||||||
| * Copyright 2025 Google LLC | ||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||
| */ | ||||||
|
|
||||||
| import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; | ||||||
| import type { | ||||||
| JSONRPCMessage, | ||||||
| JSONRPCResponse, | ||||||
| } from '@modelcontextprotocol/sdk/types.js'; | ||||||
| import { EventEmitter } from 'node:events'; | ||||||
|
|
||||||
| /** | ||||||
| * A wrapper transport that intercepts messages from Xcode's mcpbridge and fixes | ||||||
| * non-compliant responses. | ||||||
| * | ||||||
| * Issue: Xcode 26.3's mcpbridge returns tool results in `content` but misses | ||||||
| * `structuredContent` when the tool has an output schema. | ||||||
| * | ||||||
| * Fix: Parse the text content as JSON and populate `structuredContent`. | ||||||
| */ | ||||||
| export class XcodeMcpBridgeFixTransport | ||||||
| extends EventEmitter | ||||||
| implements Transport | ||||||
| { | ||||||
| constructor(private readonly transport: Transport) { | ||||||
|
Contributor
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. The
Suggested change
|
||||||
| super(); | ||||||
|
|
||||||
| // Forward messages from the underlying transport | ||||||
| this.transport.onmessage = (message) => { | ||||||
| this.handleMessage(message); | ||||||
| }; | ||||||
|
|
||||||
| this.transport.onclose = () => { | ||||||
| this.onclose?.(); | ||||||
| }; | ||||||
|
|
||||||
| this.transport.onerror = (error) => { | ||||||
| this.onerror?.(error); | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| // Transport interface implementation | ||||||
| onclose?: () => void; | ||||||
| onerror?: (error: Error) => void; | ||||||
| onmessage?: (message: JSONRPCMessage) => void; | ||||||
|
|
||||||
| async start(): Promise<void> { | ||||||
| await this.transport.start(); | ||||||
| } | ||||||
|
|
||||||
| async close(): Promise<void> { | ||||||
| await this.transport.close(); | ||||||
| } | ||||||
|
|
||||||
| async send(message: JSONRPCMessage): Promise<void> { | ||||||
| await this.transport.send(message); | ||||||
| } | ||||||
|
|
||||||
| private handleMessage(message: JSONRPCMessage) { | ||||||
| if (this.isJsonResponse(message)) { | ||||||
| this.fixStructuredContent(message); | ||||||
| } | ||||||
| this.onmessage?.(message); | ||||||
| } | ||||||
|
|
||||||
| private isJsonResponse(message: JSONRPCMessage): message is JSONRPCResponse { | ||||||
| return 'result' in message || 'error' in message; | ||||||
| } | ||||||
|
|
||||||
| private fixStructuredContent(response: JSONRPCResponse) { | ||||||
| if (!('result' in response)) return; | ||||||
|
|
||||||
| // We can cast because we verified 'result' is in response, | ||||||
| // but TS might still be picky if the type is a strict union. | ||||||
| // Let's treat it safely. | ||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||
| const result = response.result as any; | ||||||
|
|
||||||
| // Check if we have content but missing structuredContent | ||||||
| if ( | ||||||
| result.content && | ||||||
| Array.isArray(result.content) && | ||||||
| result.content.length > 0 && | ||||||
| !result.structuredContent | ||||||
| ) { | ||||||
| const firstItem = result.content[0]; | ||||||
| if (firstItem.type === 'text' && typeof firstItem.text === 'string') { | ||||||
| try { | ||||||
| // Attempt to parse the text as JSON | ||||||
| const parsed = JSON.parse(firstItem.text); | ||||||
| // If successful, populate structuredContent | ||||||
| result.structuredContent = parsed; | ||||||
| } catch (_) { | ||||||
| // Ignored: Content is likely plain text, not JSON. | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Accessing the private
transportproperty usingas anyis a workaround that breaks encapsulation. Once thetransportproperty inXcodeMcpBridgeFixTransportis made public (as suggested in another comment), you can access it directly without the type cast andeslint-disablecomment, making the code cleaner and more robust.