Handle spawning the client and server on Windows using correct paths
This commit is contained in:
97
bin/cli.js
97
bin/cli.js
@@ -1,65 +1,60 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { join, dirname } from "path";
|
||||
import { spawnPromise } from "spawn-rx";
|
||||
import { fileURLToPath } from "url";
|
||||
import concurrently from "concurrently";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// Get command line arguments
|
||||
const [, , command, ...mcpServerArgs] = process.argv;
|
||||
async function main() {
|
||||
// Get command line arguments
|
||||
const [, , command, ...mcpServerArgs] = process.argv;
|
||||
|
||||
const inspectorServerPath = join(__dirname, "../server/build/index.js");
|
||||
const inspectorServerPath = join(__dirname, "../server/build/index.js");
|
||||
|
||||
// Path to the client entry point
|
||||
const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
|
||||
// Path to the client entry point
|
||||
const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
|
||||
|
||||
console.log("Starting MCP inspector...");
|
||||
const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
|
||||
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
|
||||
|
||||
function escapeArg(arg) {
|
||||
if (arg.includes(" ") || arg.includes("'") || arg.includes('"')) {
|
||||
return `\\"${arg.replace(/"/g, '\\\\\\"')}\\"`;
|
||||
console.log("Starting MCP inspector...");
|
||||
|
||||
const abort = new AbortController();
|
||||
|
||||
let cancelled = false;
|
||||
process.on("SIGINT", () => {
|
||||
cancelled = true;
|
||||
abort.abort();
|
||||
});
|
||||
|
||||
const server = spawnPromise(
|
||||
"node",
|
||||
[
|
||||
inspectorServerPath,
|
||||
...(command ? [`--env`, command] : []),
|
||||
...(mcpServerArgs ?? []),
|
||||
],
|
||||
{ env: { PORT: SERVER_PORT }, signal: abort.signal },
|
||||
);
|
||||
|
||||
const client = spawnPromise("node", [inspectorClientPath], {
|
||||
env: { PORT: CLIENT_PORT },
|
||||
signal: abort.signal,
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.any([server, client]);
|
||||
} catch (e) {
|
||||
if (!cancelled) throw e;
|
||||
}
|
||||
return arg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const serverCommand = [
|
||||
`node`,
|
||||
inspectorServerPath,
|
||||
command ? `--env ${escapeArg(command)}` : "",
|
||||
mcpServerArgs.length
|
||||
? `--args="${mcpServerArgs.map(escapeArg).join(" ")}"`
|
||||
: "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
|
||||
const CLIENT_PORT = process.env.CLIENT_PORT ?? "";
|
||||
const SERVER_PORT = process.env.SERVER_PORT ?? "";
|
||||
|
||||
const { result } = concurrently(
|
||||
[
|
||||
{
|
||||
command: `PORT=${SERVER_PORT} ${serverCommand}`,
|
||||
name: "server",
|
||||
},
|
||||
{
|
||||
command: `PORT=${CLIENT_PORT} node ${inspectorClientPath}`,
|
||||
name: "client",
|
||||
},
|
||||
],
|
||||
{
|
||||
prefix: "name",
|
||||
killOthers: ["failure", "success"],
|
||||
restartTries: 3,
|
||||
},
|
||||
);
|
||||
|
||||
console.log(
|
||||
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT || 5173} 🚀`,
|
||||
);
|
||||
|
||||
result.catch((err) => {
|
||||
console.error("An error occurred:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
main()
|
||||
.then((_) => process.exit(0))
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"build": "npm run build-server && npm run build-client",
|
||||
"start-server": "cd server && npm run start",
|
||||
"start-client": "cd client && npm run preview",
|
||||
"start": "node ./bin/cli.ts",
|
||||
"start": "node ./bin/cli.js",
|
||||
"prepare": "npm run build",
|
||||
"prettier-fix": "prettier --write .",
|
||||
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
|
||||
|
||||
Reference in New Issue
Block a user