From 8b49ceb3be46e911d990f3c20ec561ea47b8b00e Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Thu, 26 Mar 2026 18:12:33 +0000 Subject: [PATCH] fix(stdio): always set windowsHide on Windows, not just in Electron Fixes #1638. Forward-port of #1640 from v1.x. Co-authored-by: jnMetaCode <147776183+jnMetaCode@users.noreply.github.com> --- .changeset/fix-stdio-windows-hide.md | 5 ++ packages/client/src/client/stdio.ts | 6 +-- .../client/test/client/crossSpawn.test.ts | 50 +++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .changeset/fix-stdio-windows-hide.md diff --git a/.changeset/fix-stdio-windows-hide.md b/.changeset/fix-stdio-windows-hide.md new file mode 100644 index 000000000..7b0db2743 --- /dev/null +++ b/.changeset/fix-stdio-windows-hide.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/client': patch +--- + +Always set `windowsHide` when spawning stdio server processes on Windows, not just in Electron environments. Prevents unwanted console windows in non-Electron Windows applications. diff --git a/packages/client/src/client/stdio.ts b/packages/client/src/client/stdio.ts index 6c1571f11..5dcb8ef9a 100644 --- a/packages/client/src/client/stdio.ts +++ b/packages/client/src/client/stdio.ts @@ -126,7 +126,7 @@ export class StdioClientTransport implements Transport { }, stdio: ['pipe', 'pipe', this._serverParams.stderr ?? 'inherit'], shell: false, - windowsHide: process.platform === 'win32' && isElectron(), + windowsHide: process.platform === 'win32', cwd: this._serverParams.cwd }); @@ -258,7 +258,3 @@ export class StdioClientTransport implements Transport { }); } } - -function isElectron() { - return 'type' in process; -} diff --git a/packages/client/test/client/crossSpawn.test.ts b/packages/client/test/client/crossSpawn.test.ts index 8e4a80fc2..a6d0272a4 100644 --- a/packages/client/test/client/crossSpawn.test.ts +++ b/packages/client/test/client/crossSpawn.test.ts @@ -152,4 +152,54 @@ describe('StdioClientTransport using cross-spawn', () => { // verify message is sent correctly expect(mockProcess.stdin.write).toHaveBeenCalled(); }); + + describe('windowsHide', () => { + const originalPlatform = process.platform; + + afterEach(() => { + Object.defineProperty(process, 'platform', { + value: originalPlatform + }); + }); + + test('should set windowsHide to true on Windows', async () => { + Object.defineProperty(process, 'platform', { + value: 'win32' + }); + + const transport = new StdioClientTransport({ + command: 'test-command' + }); + + await transport.start(); + + expect(mockSpawn).toHaveBeenCalledWith( + 'test-command', + [], + expect.objectContaining({ + windowsHide: true + }) + ); + }); + + test('should set windowsHide to false on non-Windows', async () => { + Object.defineProperty(process, 'platform', { + value: 'linux' + }); + + const transport = new StdioClientTransport({ + command: 'test-command' + }); + + await transport.start(); + + expect(mockSpawn).toHaveBeenCalledWith( + 'test-command', + [], + expect.objectContaining({ + windowsHide: false + }) + ); + }); + }); });