From 9a560e3f065227cd1f772b50d55532d5b9418ba1 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Tue, 19 Nov 2024 15:42:53 -0800 Subject: [PATCH] handle quotes better --- bin/cli.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 0485a30..79a6d40 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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", }, {