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
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { join, dirname } from "path";
|
import { join, dirname } from "path";
|
||||||
|
import { spawnPromise } from "spawn-rx";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import concurrently from "concurrently";
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
// Get command line arguments
|
async function main() {
|
||||||
const [, , command, ...mcpServerArgs] = process.argv;
|
// 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
|
// Path to the client entry point
|
||||||
const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
|
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) {
|
console.log("Starting MCP inspector...");
|
||||||
if (arg.includes(" ") || arg.includes("'") || arg.includes('"')) {
|
|
||||||
return `\\"${arg.replace(/"/g, '\\\\\\"')}\\"`;
|
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 = [
|
main()
|
||||||
`node`,
|
.then((_) => process.exit(0))
|
||||||
inspectorServerPath,
|
.catch((e) => {
|
||||||
command ? `--env ${escapeArg(command)}` : "",
|
console.error(e);
|
||||||
mcpServerArgs.length
|
process.exit(1);
|
||||||
? `--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);
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
"build": "npm run build-server && npm run build-client",
|
"build": "npm run build-server && npm run build-client",
|
||||||
"start-server": "cd server && npm run start",
|
"start-server": "cd server && npm run start",
|
||||||
"start-client": "cd client && npm run preview",
|
"start-client": "cd client && npm run preview",
|
||||||
"start": "node ./bin/cli.ts",
|
"start": "node ./bin/cli.js",
|
||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"prettier-fix": "prettier --write .",
|
"prettier-fix": "prettier --write .",
|
||||||
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
|
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
|
||||||
|
|||||||
Reference in New Issue
Block a user