Compare commits

...

5 Commits

Author SHA1 Message Date
Spencer
e9ba38ed5c
Merge branch 'main' into debug-fix 2026-04-24 14:18:12 -04:00
Spencer
3f82b001d2
Merge branch 'main' into debug-fix 2026-04-24 13:10:03 -04:00
Spencer
2eebc2980b
Merge branch 'main' into debug-fix 2026-04-23 19:24:09 -04:00
Spencer
e96eb82a13
Merge branch 'main' into debug-fix 2026-04-23 19:03:32 -04:00
Spencer
85f99d174f fix(core): drain stderr stream unconditionally for StdioClientTransport 2026-04-23 22:51:17 +00:00
2 changed files with 48 additions and 18 deletions

View File

@ -1993,6 +1993,27 @@ describe('mcp-client', () => {
}); });
}); });
it('should unconditionally attach a data listener to stderr to prevent process hang', async () => {
const mockStderr = {
on: vi.fn(),
};
vi.spyOn(SdkClientStdioLib, 'StdioClientTransport').mockReturnValue({
stderr: mockStderr,
} as unknown as SdkClientStdioLib.StdioClientTransport);
await createTransport(
'test-server',
{
command: 'test-command',
},
false, // debugMode = false
MOCK_CONTEXT,
);
expect(mockStderr.on).toHaveBeenCalledWith('data', expect.any(Function));
});
it('sets an env variable GEMINI_CLI=1 for stdio MCP servers', async () => { it('sets an env variable GEMINI_CLI=1 for stdio MCP servers', async () => {
const mockedTransport = vi const mockedTransport = vi
.spyOn(SdkClientStdioLib, 'StdioClientTransport') .spyOn(SdkClientStdioLib, 'StdioClientTransport')

View File

@ -2291,31 +2291,40 @@ export async function createTransport(
transport = new XcodeMcpBridgeFixTransport(transport); transport = new XcodeMcpBridgeFixTransport(transport);
} }
if (debugMode) { // The `XcodeMcpBridgeFixTransport` wrapper hides the underlying `StdioClientTransport`,
// The `XcodeMcpBridgeFixTransport` wrapper hides the underlying `StdioClientTransport`, // which exposes `stderr` for debug logging. We need to unwrap it to attach the listener.
// which exposes `stderr` for debug logging. We need to unwrap it to attach the listener.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const underlyingTransport =
const underlyingTransport = transport instanceof XcodeMcpBridgeFixTransport
transport instanceof XcodeMcpBridgeFixTransport ? // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
? // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-type-assertion (transport as unknown as { transport: unknown }).transport
(transport as any).transport : transport;
: transport;
if ( // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
underlyingTransport instanceof StdioClientTransport && const streamTransport = underlyingTransport as {
underlyingTransport.stderr stderr?: {
) { on: (event: string, listener: (data: unknown) => void) => void;
underlyingTransport.stderr.on('data', (data) => { };
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment };
const stderrStr = data.toString().trim();
if (
streamTransport &&
typeof streamTransport === 'object' &&
'stderr' in streamTransport &&
streamTransport.stderr &&
typeof streamTransport.stderr.on === 'function'
) {
streamTransport.stderr.on('data', (data: unknown) => {
if (debugMode) {
const stderrStr = String(data).trim();
debugLogger.debug( debugLogger.debug(
`[DEBUG] [MCP STDERR (${mcpServerName})]: `, `[DEBUG] [MCP STDERR (${mcpServerName})]: `,
stderrStr, stderrStr,
); );
}); }
} });
} }
return transport; return transport;
} }