Skip to content

Commit 2b79b6f

Browse files
authored
Merge pull request #79 from modelcontextprotocol/ani/fix-windows
Fix launch issues on Windows
2 parents b825784 + 1f28b44 commit 2b79b6f

File tree

7 files changed

+5045
-3959
lines changed

7 files changed

+5045
-3959
lines changed

bin/cli.js

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,82 @@
11
#!/usr/bin/env node
22

3-
import { join, dirname } from "path";
3+
import { resolve, dirname } from "path";
4+
import { spawnPromise } from "spawn-rx";
45
import { fileURLToPath } from "url";
5-
import concurrently from "concurrently";
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
88

9-
// Get command line arguments
10-
const [, , command, ...mcpServerArgs] = process.argv;
9+
function delay(ms) {
10+
return new Promise((resolve) => setTimeout(resolve, ms));
11+
}
12+
13+
async function main() {
14+
// Get command line arguments
15+
const [, , command, ...mcpServerArgs] = process.argv;
16+
17+
const inspectorServerPath = resolve(
18+
__dirname,
19+
"..",
20+
"server",
21+
"build",
22+
"index.js",
23+
);
24+
25+
// Path to the client entry point
26+
const inspectorClientPath = resolve(
27+
__dirname,
28+
"..",
29+
"client",
30+
"bin",
31+
"cli.js",
32+
);
33+
34+
const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
35+
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
1136

12-
const inspectorServerPath = join(__dirname, "../server/build/index.js");
37+
console.log("Starting MCP inspector...");
1338

14-
// Path to the client entry point
15-
const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
39+
const abort = new AbortController();
1640

17-
console.log("Starting MCP inspector...");
41+
let cancelled = false;
42+
process.on("SIGINT", () => {
43+
cancelled = true;
44+
abort.abort();
45+
});
1846

19-
function escapeArg(arg) {
20-
if (arg.includes(" ") || arg.includes("'") || arg.includes('"')) {
21-
return `\\"${arg.replace(/"/g, '\\\\\\"')}\\"`;
47+
const server = spawnPromise(
48+
"node",
49+
[
50+
inspectorServerPath,
51+
...(command ? [`--env`, command] : []),
52+
...(mcpServerArgs ? ["--args", mcpServerArgs.join(" ")] : []),
53+
],
54+
{ env: { ...process.env, PORT: SERVER_PORT }, signal: abort.signal },
55+
);
56+
57+
const client = spawnPromise("node", [inspectorClientPath], {
58+
env: { ...process.env, PORT: CLIENT_PORT },
59+
signal: abort.signal,
60+
});
61+
62+
// Make sure our server/client didn't immediately fail
63+
await Promise.any([server, client, delay(2 * 1000)]);
64+
console.log(
65+
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT} 🚀`,
66+
);
67+
68+
try {
69+
await Promise.any([server, client]);
70+
} catch (e) {
71+
if (!cancelled || process.env.DEBUG) throw e;
2272
}
23-
return arg;
73+
74+
return 0;
2475
}
2576

26-
const serverCommand = [
27-
`node`,
28-
inspectorServerPath,
29-
command ? `--env ${escapeArg(command)}` : "",
30-
mcpServerArgs.length
31-
? `--args="${mcpServerArgs.map(escapeArg).join(" ")}"`
32-
: "",
33-
]
34-
.filter(Boolean)
35-
.join(" ");
36-
37-
const CLIENT_PORT = process.env.CLIENT_PORT ?? "";
38-
const SERVER_PORT = process.env.SERVER_PORT ?? "";
39-
40-
const { result } = concurrently(
41-
[
42-
{
43-
command: `PORT=${SERVER_PORT} ${serverCommand}`,
44-
name: "server",
45-
},
46-
{
47-
command: `PORT=${CLIENT_PORT} node ${inspectorClientPath}`,
48-
name: "client",
49-
},
50-
],
51-
{
52-
prefix: "name",
53-
killOthers: ["failure", "success"],
54-
restartTries: 3,
55-
},
56-
);
57-
58-
console.log(
59-
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT || 5173} 🚀`,
60-
);
61-
62-
result.catch((err) => {
63-
console.error("An error occurred:", err);
64-
process.exit(1);
65-
});
77+
main()
78+
.then((_) => process.exit(0))
79+
.catch((e) => {
80+
console.error(e);
81+
process.exit(1);
82+
});

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"preview": "vite preview"
2222
},
2323
"dependencies": {
24-
"@modelcontextprotocol/sdk": "0.7.0",
24+
"@modelcontextprotocol/sdk": "^1.0.1",
2525
"@radix-ui/react-icons": "^1.3.0",
2626
"@radix-ui/react-label": "^2.1.0",
2727
"@radix-ui/react-select": "^2.1.2",

client/tailwind.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** @type {import('tailwindcss').Config} */
2+
import animate from "tailwindcss-animate";
23
export default {
34
darkMode: ["class"],
45
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
@@ -53,5 +54,5 @@ export default {
5354
},
5455
},
5556
},
56-
plugins: [require("tailwindcss-animate")],
57+
plugins: [animate],
5758
};

0 commit comments

Comments
 (0)