Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 69 additions & 52 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,82 @@
#!/usr/bin/env node

import { join, dirname } from "path";
import { resolve, 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;
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function main() {
// Get command line arguments
const [, , command, ...mcpServerArgs] = process.argv;

const inspectorServerPath = resolve(
__dirname,
"..",
"server",
"build",
"index.js",
);

// Path to the client entry point
const inspectorClientPath = resolve(
__dirname,
"..",
"client",
"bin",
"cli.js",
);

const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";

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

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

console.log("Starting MCP inspector...");
let cancelled = false;
process.on("SIGINT", () => {
cancelled = true;
abort.abort();
});

function escapeArg(arg) {
if (arg.includes(" ") || arg.includes("'") || arg.includes('"')) {
return `\\"${arg.replace(/"/g, '\\\\\\"')}\\"`;
const server = spawnPromise(
"node",
[
inspectorServerPath,
...(command ? [`--env`, command] : []),
...(mcpServerArgs ? ["--args", mcpServerArgs.join(" ")] : []),
],
{ env: { ...process.env, PORT: SERVER_PORT }, signal: abort.signal },
);

const client = spawnPromise("node", [inspectorClientPath], {
env: { ...process.env, PORT: CLIENT_PORT },
signal: abort.signal,
});

// Make sure our server/client didn't immediately fail
await Promise.any([server, client, delay(2 * 1000)]);
console.log(
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT} 🚀`,
);

try {
await Promise.any([server, client]);
} catch (e) {
if (!cancelled || process.env.DEBUG) 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);
});
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"preview": "vite preview"
},
"dependencies": {
"@modelcontextprotocol/sdk": "0.7.0",
"@modelcontextprotocol/sdk": "^1.0.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.2",
Expand Down
3 changes: 2 additions & 1 deletion client/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('tailwindcss').Config} */
import animate from "tailwindcss-animate";
export default {
darkMode: ["class"],
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
Expand Down Expand Up @@ -53,5 +54,5 @@ export default {
},
},
},
plugins: [require("tailwindcss-animate")],
plugins: [animate],
};
Loading