【原创】MCP Inspector启动报错

当我启动命令:

npx @modelcontextprotocol/inspector
Starting MCP inspector...
⚙️ Proxy server listening on localhost:6277
🔑 Session token: bb823335d52c3d6909ae9cab57f63a8906c1b018fa83cf709b9215c42c8d3bec
Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
🚀 MCP Inspector is up and running at:
http://localhost:6274
🌐 Opening browser...

出现了异常:

node:internal/child_process:421
throw new ErrnoException(err, 'spawn');
^
Error: spawn UNKNOWN
at ChildProcess.spawn (node:internal/child_process:421:11)
at Object.spawn (node:child_process:795:9)
at baseOpen (file:///C:/Users/xxx/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/open/index.js:297:34)
at open (file:///C:/Users/xxx/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/open/index.js:324:9)
at Server. (file:///C:/Users/xxx/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/client/bin/client.js:50:5)
at Server.emit (node:events:519:35)
at emitListeningNT (node:net:1983:10)
at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
errno: -4094,
code: 'UNKNOWN',
syscall: 'spawn'
}
Node.js v24.4.0
🚀 MCP Inspector is up and running at:
http://localhost:6274
🌐 Opening browser...
node:internal/child_process:421
throw new ErrnoException(err, 'spawn');
^
Error: spawn UNKNOWN
at ChildProcess.spawn (node:internal/child_process:421:11)
at Object.spawn (node:child_process:795:9)
at baseOpen (file:///C:/Users/xxx/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/open/index.js:297:34)
at open (file:///C:/Users/xxx/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/open/index.js:324:9)
at Server. (file:///C:/Users/xxx/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/client/bin/client.js:50:5)
at Server.emit (node:events:519:35)
at emitListeningNT (node:net:1983:10)
at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
errno: -4094,
code: 'UNKNOWN',
syscall: 'spawn'
}
Node.js v24.4.0
Failed with exit code: 1

chatGPT:

这是一个 Windows 系统上 Node.js 无法自动打开默认浏览器 的常见 bug,根本原因在于 child_process.spawn() 遇到系统环境或浏览器配置异常时,会抛出 spawn UNKNOWN。

解决方法:

C:\Users\xxx\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules@modelcontextprotocol\inspector\client\bin\client.js
文件中的
const port = parseInt(process.env.CLIENT_PORT || "6274", 10);
const host = process.env.HOST || "localhost";
server.on("listening", () => {
const url = process.env.INSPECTOR_URL || http://${host}:${port};
console.log(\n🚀 MCP Inspector is up and running at:\n ${url}\n);
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
console.log(🌐 Opening browser...);
open(url);
}
});

删除if块,不让它打开浏览器。
或者Windows命令行,执行一下:
set MCP_AUTO_OPEN_ENABLED=false

posted @ 2025-07-09 21:13  范哥范小飞  阅读(288)  评论(0)    收藏  举报