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>
This commit is contained in:
parent
5608e78dd0
commit
3913fd4443
3 changed files with 56 additions and 5 deletions
5
.changeset/fix-stdio-windows-hide.md
Normal file
5
.changeset/fix-stdio-windows-hide.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@modelcontextprotocol/sdk': patch
|
||||
---
|
||||
|
||||
Always set windowsHide to true when spawning stdio server processes on Windows, not just in Electron environments.
|
||||
|
|
@ -125,7 +125,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
|
||||
});
|
||||
|
||||
|
|
@ -257,7 +257,3 @@ export class StdioClientTransport implements Transport {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
function isElectron() {
|
||||
return 'type' in process;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,4 +150,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…
Reference in a new issue