Skip to content

Commit 3913fd4

Browse files
jnMetaCodefelixweinbergerKKonstantinov
authored
fix(stdio): always set windowsHide on Windows, not just in Electron (#1640)
Co-authored-by: JiangNan <1394485448@qq.com> Co-authored-by: Felix Weinberger <fweinberger@anthropic.com> Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
1 parent 5608e78 commit 3913fd4

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/sdk': patch
3+
---
4+
5+
Always set windowsHide to true when spawning stdio server processes on Windows, not just in Electron environments.

src/client/stdio.ts

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

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

test/client/cross-spawn.test.ts

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

0 commit comments

Comments
 (0)