prettier-fix
This commit is contained in:
80
bin/cli.js
80
bin/cli.js
@@ -10,11 +10,9 @@ function handleError(error) {
|
|||||||
let message;
|
let message;
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
message = error.message;
|
message = error.message;
|
||||||
}
|
} else if (typeof error === "string") {
|
||||||
else if (typeof error === "string") {
|
|
||||||
message = error;
|
message = error;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
message = "Unknown error";
|
message = "Unknown error";
|
||||||
}
|
}
|
||||||
console.error(message);
|
console.error(message);
|
||||||
@@ -24,9 +22,21 @@ function delay(ms) {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
async function runWebClient(args) {
|
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
|
// 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 CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
|
||||||
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
|
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
|
||||||
console.log("Starting MCP inspector...");
|
console.log("Starting MCP inspector...");
|
||||||
@@ -36,11 +46,14 @@ async function runWebClient(args) {
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
abort.abort();
|
abort.abort();
|
||||||
});
|
});
|
||||||
const server = spawnPromise("node", [
|
const server = spawnPromise(
|
||||||
|
"node",
|
||||||
|
[
|
||||||
inspectorServerPath,
|
inspectorServerPath,
|
||||||
...(args.command ? [`--env`, args.command] : []),
|
...(args.command ? [`--env`, args.command] : []),
|
||||||
...(args.args ? [`--args=${args.args.join(" ")}`] : []),
|
...(args.args ? [`--args=${args.args.join(" ")}`] : []),
|
||||||
], {
|
],
|
||||||
|
{
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
PORT: SERVER_PORT,
|
PORT: SERVER_PORT,
|
||||||
@@ -48,7 +61,8 @@ async function runWebClient(args) {
|
|||||||
},
|
},
|
||||||
signal: abort.signal,
|
signal: abort.signal,
|
||||||
echoOutput: true,
|
echoOutput: true,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
const client = spawnPromise("node", [inspectorClientPath], {
|
const client = spawnPromise("node", [inspectorClientPath], {
|
||||||
env: { ...process.env, PORT: CLIENT_PORT },
|
env: { ...process.env, PORT: CLIENT_PORT },
|
||||||
signal: abort.signal,
|
signal: abort.signal,
|
||||||
@@ -57,11 +71,12 @@ async function runWebClient(args) {
|
|||||||
// Make sure our server/client didn't immediately fail
|
// Make sure our server/client didn't immediately fail
|
||||||
await Promise.any([server, client, delay(2 * 1000)]);
|
await Promise.any([server, client, delay(2 * 1000)]);
|
||||||
const portParam = SERVER_PORT === "3000" ? "" : `?proxyPort=${SERVER_PORT}`;
|
const portParam = SERVER_PORT === "3000" ? "" : `?proxyPort=${SERVER_PORT}`;
|
||||||
console.log(`\n🔍 MCP Inspector is up and running at http://127.0.0.1:${CLIENT_PORT}${portParam} 🚀`);
|
console.log(
|
||||||
|
`\n🔍 MCP Inspector is up and running at http://127.0.0.1:${CLIENT_PORT}${portParam} 🚀`,
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
await Promise.any([server, client]);
|
await Promise.any([server, client]);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
if (!cancelled || process.env.DEBUG) {
|
if (!cancelled || process.env.DEBUG) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -82,8 +97,7 @@ async function runCli(args) {
|
|||||||
signal: abort.signal,
|
signal: abort.signal,
|
||||||
echoOutput: true,
|
echoOutput: true,
|
||||||
});
|
});
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
if (!cancelled || process.env.DEBUG) {
|
if (!cancelled || process.env.DEBUG) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -100,13 +114,16 @@ function loadConfigFile(configPath, serverName) {
|
|||||||
const configContent = fs.readFileSync(resolvedConfigPath, "utf8");
|
const configContent = fs.readFileSync(resolvedConfigPath, "utf8");
|
||||||
const parsedConfig = JSON.parse(configContent);
|
const parsedConfig = JSON.parse(configContent);
|
||||||
if (!parsedConfig.mcpServers || !parsedConfig.mcpServers[serverName]) {
|
if (!parsedConfig.mcpServers || !parsedConfig.mcpServers[serverName]) {
|
||||||
const availableServers = Object.keys(parsedConfig.mcpServers || {}).join(", ");
|
const availableServers = Object.keys(parsedConfig.mcpServers || {}).join(
|
||||||
throw new Error(`Server '${serverName}' not found in config file. Available servers: ${availableServers}`);
|
", ",
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Server '${serverName}' not found in config file. Available servers: ${availableServers}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const serverConfig = parsedConfig.mcpServers[serverName];
|
const serverConfig = parsedConfig.mcpServers[serverName];
|
||||||
return serverConfig;
|
return serverConfig;
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
if (err instanceof SyntaxError) {
|
if (err instanceof SyntaxError) {
|
||||||
throw new Error(`Invalid JSON in config file: ${err.message}`);
|
throw new Error(`Invalid JSON in config file: ${err.message}`);
|
||||||
}
|
}
|
||||||
@@ -118,7 +135,9 @@ function parseKeyValuePair(value, previous = {}) {
|
|||||||
const key = parts[0];
|
const key = parts[0];
|
||||||
const val = parts.slice(1).join("=");
|
const val = parts.slice(1).join("=");
|
||||||
if (val === undefined || val === "") {
|
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 };
|
return { ...previous, [key]: val };
|
||||||
}
|
}
|
||||||
@@ -135,7 +154,12 @@ function parseArgs() {
|
|||||||
.name("inspector-bin")
|
.name("inspector-bin")
|
||||||
.allowExcessArguments()
|
.allowExcessArguments()
|
||||||
.allowUnknownOption()
|
.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("--config <path>", "config file path")
|
||||||
.option("--server <n>", "server name from config file")
|
.option("--server <n>", "server name from config file")
|
||||||
.option("--cli", "enable CLI mode");
|
.option("--cli", "enable CLI mode");
|
||||||
@@ -146,9 +170,13 @@ function parseArgs() {
|
|||||||
// Add back any arguments that came after --
|
// Add back any arguments that came after --
|
||||||
const finalArgs = [...remainingArgs, ...postArgs];
|
const finalArgs = [...remainingArgs, ...postArgs];
|
||||||
// Validate that config and server are provided together
|
// Validate that config and server are provided together
|
||||||
if ((options.config && !options.server) ||
|
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.");
|
(!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
|
// 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,
|
// from the command line and the file together, or we will miss the method options (--method,
|
||||||
@@ -180,12 +208,10 @@ async function main() {
|
|||||||
const args = parseArgs();
|
const args = parseArgs();
|
||||||
if (args.cli) {
|
if (args.cli) {
|
||||||
runCli(args);
|
runCli(args);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
await runWebClient(args);
|
await runWebClient(args);
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
|
||||||
handleError(error);
|
handleError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
"dev": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev\"",
|
"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\"",
|
"dev:windows": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev:windows\"",
|
||||||
"test": "npm run prettier-check && cd client && npm test",
|
"test": "npm run prettier-check && cd client && npm test",
|
||||||
"test:cli": "cd bin && npm run test",
|
"test-cli": "cd bin && npm run test",
|
||||||
"build-bin": "cd bin && npm run build",
|
"build-bin": "cd bin && npm run build",
|
||||||
"build-server": "cd server && npm run build",
|
"build-server": "cd server && npm run build",
|
||||||
"build-client": "cd client && npm run build",
|
"build-client": "cd client && npm run build",
|
||||||
|
|||||||
Reference in New Issue
Block a user