Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-stdio-windows-hide.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 1 addition & 5 deletions packages/client/src/client/stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down Expand Up @@ -258,7 +258,3 @@ export class StdioClientTransport implements Transport {
});
}
}

function isElectron() {
return 'type' in process;
}
50 changes: 50 additions & 0 deletions packages/client/test/client/crossSpawn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);
});
});
});
Loading