Forgot package files

This commit is contained in:
Nicolas Barraud
2025-03-10 20:34:07 -04:00
parent 4c4c8a0884
commit 9f42629b34
3 changed files with 238 additions and 204 deletions

View File

@@ -10,9 +10,11 @@ function handleError(error) {
let message;
if (error instanceof Error) {
message = error.message;
} else if (typeof error === "string") {
}
else if (typeof error === "string") {
message = error;
} else {
}
else {
message = "Unknown error";
}
console.error(message);
@@ -22,21 +24,9 @@ function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function runWebClient(args) {
const inspectorServerPath = resolve(
__dirname,
"..",
"server",
"build",
"index.js",
);
const inspectorServerPath = resolve(__dirname, "..", "server", "build", "index.js");
// Path to the client entry point
const inspectorClientPath = resolve(
__dirname,
"..",
"client",
"bin",
"cli.js",
);
const inspectorClientPath = resolve(__dirname, "..", "client", "bin", "cli.js");
const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
console.log("Starting MCP inspector...");
@@ -46,14 +36,11 @@ async function runWebClient(args) {
cancelled = true;
abort.abort();
});
const server = spawnPromise(
"node",
[
const server = spawnPromise("node", [
inspectorServerPath,
...(args.command ? [`--env`, args.command] : []),
...(args.args ? [`--args=${args.args.join(" ")}`] : []),
],
{
], {
env: {
...process.env,
PORT: SERVER_PORT,
@@ -61,8 +48,7 @@ async function runWebClient(args) {
},
signal: abort.signal,
echoOutput: true,
},
);
});
const client = spawnPromise("node", [inspectorClientPath], {
env: { ...process.env, PORT: CLIENT_PORT },
signal: abort.signal,
@@ -71,12 +57,11 @@ async function runWebClient(args) {
// Make sure our server/client didn't immediately fail
await Promise.any([server, client, delay(2 * 1000)]);
const portParam = SERVER_PORT === "3000" ? "" : `?proxyPort=${SERVER_PORT}`;
console.log(
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT}${portParam} 🚀`,
);
console.log(`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT}${portParam} 🚀`);
try {
await Promise.any([server, client]);
} catch (e) {
}
catch (e) {
if (!cancelled || process.env.DEBUG) {
throw e;
}
@@ -97,7 +82,8 @@ async function runCli(args) {
signal: abort.signal,
echoOutput: true,
});
} catch (e) {
}
catch (e) {
if (!cancelled || process.env.DEBUG) {
throw e;
}
@@ -114,16 +100,13 @@ function loadConfigFile(configPath, serverName) {
const configContent = fs.readFileSync(resolvedConfigPath, "utf8");
const parsedConfig = JSON.parse(configContent);
if (!parsedConfig.mcpServers || !parsedConfig.mcpServers[serverName]) {
const availableServers = Object.keys(parsedConfig.mcpServers || {}).join(
", ",
);
throw new Error(
`Server '${serverName}' not found in config file. Available servers: ${availableServers}`,
);
const availableServers = Object.keys(parsedConfig.mcpServers || {}).join(", ");
throw new Error(`Server '${serverName}' not found in config file. Available servers: ${availableServers}`);
}
const serverConfig = parsedConfig.mcpServers[serverName];
return serverConfig;
} catch (err) {
}
catch (err) {
if (err instanceof SyntaxError) {
throw new Error(`Invalid JSON in config file: ${err.message}`);
}
@@ -135,9 +118,7 @@ function parseKeyValuePair(value, previous = {}) {
const key = parts[0];
const val = parts.slice(1).join("=");
if (val === undefined || val === "") {
throw new Error(
`Invalid parameter format: ${value}. Use key=value format.`,
);
throw new Error(`Invalid parameter format: ${value}. Use key=value format.`);
}
return { ...previous, [key]: val };
}
@@ -154,12 +135,7 @@ function parseArgs() {
.name("inspector-bin")
.allowExcessArguments()
.allowUnknownOption()
.option(
"-e <env>",
"environment variables in KEY=VALUE format",
parseKeyValuePair,
{},
)
.option("-e <env>", "environment variables in KEY=VALUE format", parseKeyValuePair, {})
.option("--config <path>", "config file path")
.option("--server <n>", "server name from config file")
.option("--cli", "enable CLI mode");
@@ -170,13 +146,9 @@ function parseArgs() {
// Add back any arguments that came after --
const finalArgs = [...remainingArgs, ...postArgs];
// Validate that config and server are provided together
if (
(options.config && !options.server) ||
(!options.config && options.server)
) {
throw new Error(
"Both --config and --server must be provided together. If you specify one, you must specify the other.",
);
if ((options.config && !options.server) ||
(!options.config && options.server)) {
throw new Error("Both --config and --server must be provided together. If you specify one, you must specify the other.");
}
// If config file is specified, load and use the options from the file. We must merge the args
// from the command line and the file together, or we will miss the method options (--method,
@@ -206,13 +178,14 @@ async function main() {
});
try {
const args = parseArgs();
console.log(args);
if (args.cli) {
runCli(args);
} else {
}
else {
await runWebClient(args);
}
} catch (error) {
}
catch (error) {
handleError(error);
}
}

68
package-lock.json generated
View File

@@ -10,25 +10,56 @@
"license": "MIT",
"workspaces": [
"client",
"server"
"server",
"cli",
"bin"
],
"dependencies": {
"@modelcontextprotocol/inspector-client": "0.4.1",
"@modelcontextprotocol/inspector-server": "0.4.1",
"@modelcontextprotocol/inspector-bin": "0.5.1",
"@modelcontextprotocol/inspector-cli": "0.5.1",
"@modelcontextprotocol/inspector-client": "0.5.1",
"@modelcontextprotocol/inspector-server": "0.5.1",
"@modelcontextprotocol/sdk": "^1.6.1",
"commander": "^13.1.0",
"concurrently": "^9.0.1",
"shell-quote": "^1.8.2",
"spawn-rx": "^5.1.2",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"zod": "^3.23.8"
},
"bin": {
"mcp-inspector": "bin/cli.js"
"mcp-inspector": "bin/cli.js",
"mcp-inspector-cli": "cli/bin/cli.js"
},
"devDependencies": {
"@types/node": "^22.7.5",
"@types/shell-quote": "^1.7.5",
"prettier": "3.3.3"
"prettier": "3.3.3",
"typescript": "^5.4.2"
}
},
"bin": {
"name": "@modelcontextprotocol/inspector-bin",
"version": "0.5.1",
"license": "MIT",
"bin": {
"mcp-inspector": "cli.js"
},
"devDependencies": {}
},
"cli": {
"name": "@modelcontextprotocol/inspector-cli",
"version": "0.5.1",
"license": "MIT",
"dependencies": {
"commander": "^13.1.0",
"spawn-rx": "^5.1.2"
},
"bin": {
"mcp-inspector-cli": "build/index.js"
},
"devDependencies": {}
},
"client": {
"name": "@modelcontextprotocol/inspector-client",
"version": "0.5.1",
@@ -1204,6 +1235,14 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@modelcontextprotocol/inspector-bin": {
"resolved": "bin",
"link": true
},
"node_modules/@modelcontextprotocol/inspector-cli": {
"resolved": "cli",
"link": true
},
"node_modules/@modelcontextprotocol/inspector-client": {
"resolved": "client",
"link": true
@@ -4108,12 +4147,12 @@
"license": "MIT"
},
"node_modules/commander": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
"integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==",
"version": "13.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-13.1.0.tgz",
"integrity": "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==",
"license": "MIT",
"engines": {
"node": ">= 6"
"node": ">=18"
}
},
"node_modules/concat-map": {
@@ -6936,6 +6975,15 @@
"node": ">=16 || 14 >=14.17"
}
},
"node_modules/sucrase/node_modules/commander": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
"integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==",
"license": "MIT",
"engines": {
"node": ">= 6"
}
},
"node_modules/supports-color": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",

View File

@@ -8,24 +8,31 @@
"bugs": "https://github.com/modelcontextprotocol/inspector/issues",
"type": "module",
"bin": {
"mcp-inspector": "./bin/cli.js"
"mcp-inspector": "./bin/cli.js",
"mcp-inspector-cli": "./cli/bin/cli.js"
},
"files": [
"bin",
"client/bin",
"client/dist",
"server/build"
"server/build",
"cli/bin",
"cli/build"
],
"workspaces": [
"client",
"server"
"server",
"cli",
"bin"
],
"scripts": {
"dev": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev\"",
"dev:windows": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev:windows",
"build-bin": "cd bin && npm run build",
"build-server": "cd server && npm run build",
"build-client": "cd client && npm run build",
"build": "npm run build-server && npm run build-client",
"build-cli": "cd cli && npm run build",
"build": "npm run build-bin && npm run build-server && npm run build-client && npm run build-cli",
"start-server": "cd server && npm run start",
"start-client": "cd client && npm run preview",
"start": "node ./bin/cli.js",
@@ -34,16 +41,22 @@
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
},
"dependencies": {
"@modelcontextprotocol/inspector-client": "0.4.1",
"@modelcontextprotocol/inspector-server": "0.4.1",
"@modelcontextprotocol/inspector-bin": "0.5.1",
"@modelcontextprotocol/inspector-cli": "0.5.1",
"@modelcontextprotocol/inspector-client": "0.5.1",
"@modelcontextprotocol/inspector-server": "0.5.1",
"@modelcontextprotocol/sdk": "^1.6.1",
"commander": "^13.1.0",
"concurrently": "^9.0.1",
"shell-quote": "^1.8.2",
"spawn-rx": "^5.1.2",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^22.7.5",
"@types/shell-quote": "^1.7.5",
"prettier": "3.3.3"
"prettier": "3.3.3",
"typescript": "^5.4.2"
}
}