handle quotes better

This commit is contained in:
Ashwin Bhat
2024-11-19 15:42:53 -08:00
parent 1843562dce
commit 9a560e3f06

View File

@@ -16,10 +16,30 @@ const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
console.log("Starting MCP inspector...");
function escapeArg(arg) {
if (arg.includes(" ") || arg.includes("'") || arg.includes('"')) {
return `\\"${arg.replace(/"/g, '\\\\\\"')}\\"`;
}
return arg;
}
const serverCommand = [
`node`,
inspectorServerPath,
command ? `--env ${escapeArg(command)}` : "",
mcpServerArgs.length
? `--args="${mcpServerArgs.map(escapeArg).join(" ")}"`
: "",
]
.filter(Boolean)
.join(" ");
console.log(serverCommand);
const { result } = concurrently(
[
{
command: `node ${inspectorServerPath}${command ? ` --env ${command}` : ""}${mcpServerArgs.length ? ` --args="${mcpServerArgs.join(" ")}"` : ""}`,
command: serverCommand,
name: "server",
},
{