Skip to content

Commit 5276439

Browse files
felixweinbergerDeltaMasterDtmKKonstantinov
authored
fix(stdio): always set windowsHide on Windows, not just in Electron (modelcontextprotocol#1772)
Co-authored-by: jnMetaCode <147776183+jnMetaCode@users.noreply.github.com> Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
1 parent e86b183 commit 5276439

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/client': patch
3+
---
4+
5+
Always set `windowsHide` when spawning stdio server processes on Windows, not just in Electron environments. Prevents unwanted console windows in non-Electron Windows applications.

packages/client/src/client/stdio.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class StdioClientTransport implements Transport {
126126
},
127127
stdio: ['pipe', 'pipe', this._serverParams.stderr ?? 'inherit'],
128128
shell: false,
129-
windowsHide: process.platform === 'win32' && isElectron(),
129+
windowsHide: process.platform === 'win32',
130130
cwd: this._serverParams.cwd
131131
});
132132

@@ -258,7 +258,3 @@ export class StdioClientTransport implements Transport {
258258
});
259259
}
260260
}
261-
262-
function isElectron() {
263-
return 'type' in process;
264-
}

packages/client/test/client/crossSpawn.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,54 @@ describe('StdioClientTransport using cross-spawn', () => {
152152
// verify message is sent correctly
153153
expect(mockProcess.stdin.write).toHaveBeenCalled();
154154
});
155+
156+
describe('windowsHide', () => {
157+
const originalPlatform = process.platform;
158+
159+
afterEach(() => {
160+
Object.defineProperty(process, 'platform', {
161+
value: originalPlatform
162+
});
163+
});
164+
165+
test('should set windowsHide to true on Windows', async () => {
166+
Object.defineProperty(process, 'platform', {
167+
value: 'win32'
168+
});
169+
170+
const transport = new StdioClientTransport({
171+
command: 'test-command'
172+
});
173+
174+
await transport.start();
175+
176+
expect(mockSpawn).toHaveBeenCalledWith(
177+
'test-command',
178+
[],
179+
expect.objectContaining({
180+
windowsHide: true
181+
})
182+
);
183+
});
184+
185+
test('should set windowsHide to false on non-Windows', async () => {
186+
Object.defineProperty(process, 'platform', {
187+
value: 'linux'
188+
});
189+
190+
const transport = new StdioClientTransport({
191+
command: 'test-command'
192+
});
193+
194+
await transport.start();
195+
196+
expect(mockSpawn).toHaveBeenCalledWith(
197+
'test-command',
198+
[],
199+
expect.objectContaining({
200+
windowsHide: false
201+
})
202+
);
203+
});
204+
});
155205
});

0 commit comments

Comments
 (0)