diff --git a/package-lock.json b/package-lock.json index 26f07ffb9..13f4248b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@modelcontextprotocol/inspector-client": "0.3.0", "@modelcontextprotocol/inspector-server": "0.3.0", "concurrently": "^9.0.1", + "shell-quote": "^1.8.2", "spawn-rx": "^5.1.0", "ts-node": "^10.9.2" }, @@ -24,6 +25,7 @@ }, "devDependencies": { "@types/node": "^22.7.5", + "@types/shell-quote": "^1.7.5", "prettier": "3.3.3" } }, @@ -2393,6 +2395,13 @@ "@types/send": "*" } }, + "node_modules/@types/shell-quote": { + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/@types/shell-quote/-/shell-quote-1.7.5.tgz", + "integrity": "sha512-+UE8GAGRPbJVQDdxi16dgadcBfQ+KG2vgZhV1+3A1XmHbmwcdwhCUwIdy+d3pAGrbvgRoVSjeI9vOWyq376Yzw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/ws": { "version": "8.5.13", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz", @@ -5688,10 +5697,13 @@ } }, "node_modules/shell-quote": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", - "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.2.tgz", + "integrity": "sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==", "license": "MIT", + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } diff --git a/package.json b/package.json index 9061a7a73..c2625881c 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,13 @@ "@modelcontextprotocol/inspector-client": "0.3.0", "@modelcontextprotocol/inspector-server": "0.3.0", "concurrently": "^9.0.1", + "shell-quote": "^1.8.2", "spawn-rx": "^5.1.0", "ts-node": "^10.9.2" }, "devDependencies": { "@types/node": "^22.7.5", + "@types/shell-quote": "^1.7.5", "prettier": "3.3.3" } } diff --git a/server/src/index.ts b/server/src/index.ts index a217f446a..b82b17d51 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -3,6 +3,7 @@ import cors from "cors"; import EventSource from "eventsource"; import { parseArgs } from "node:util"; +import { parse as shellParseArgs } from "shell-quote"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; import { @@ -38,7 +39,7 @@ const createTransport = async (query: express.Request["query"]) => { if (transportType === "stdio") { const command = query.command as string; - const origArgs = (query.args as string).split(/\s+/); + const origArgs = shellParseArgs(query.args as string) as string[]; const env = query.env ? JSON.parse(query.env as string) : undefined; const { cmd, args } = findActualExecutable(command, origArgs);