Skip to content

Commit 61c6c5f

Browse files
sorryccSymboler
andauthored
fix: win32 spawn npx enoent error (#705)
* fix(mcp): Fix spawn npx ENOENT error on Windows * fix: clearformat error * fix: support bun and case-insensitive windows commands --------- Co-authored-by: symboler <1228500083@qq.com>
1 parent 6f2e1da commit 61c6c5f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/mcp.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,26 @@ export class MCPManager {
334334
const { Experimental_StdioMCPTransport } = await import(
335335
'@ai-sdk/mcp/mcp-stdio'
336336
);
337-
337+
// Windows: if command is npx/npm/yarn/pnpm/bun/bunx, use cmd.exe to execute, fix: spawn npx ENOENT error
338+
const windowsShellCommands = [
339+
'npx',
340+
'npm',
341+
'yarn',
342+
'pnpm',
343+
'bun',
344+
'bunx',
345+
];
346+
let command = config.command;
347+
let args = config.args;
348+
const isWin = process.platform === 'win32';
349+
if (isWin && windowsShellCommands.includes(command.toLowerCase())) {
350+
args = ['/c', command, ...(args || [])];
351+
command = 'cmd.exe';
352+
}
338353
return experimental_createMCPClient({
339354
transport: new Experimental_StdioMCPTransport({
340-
command: config.command,
341-
args: config.args,
355+
command,
356+
args,
342357
stderr: 'ignore',
343358
env,
344359
}),

0 commit comments

Comments
 (0)