From 9df0224bdda098b3c6870b29a269be4fe62046cf Mon Sep 17 00:00:00 2001 From: RoomWithOutRoof <166608075+Jah-yee@users.noreply.github.com> Date: Thu, 12 Mar 2026 21:10:50 +0800 Subject: [PATCH] fix: use execFile on Windows to avoid single-quote issues (#103) On Windows, cmd.exe does not strip single quotes like Unix shells. This caused MCP tools (mcp_servers, mcp_discover, mcp_call) to fail with 'Unknown command list' errors because mcporter received literal 'list' instead of just list. The fix uses execFile with shell=true on Windows, which properly passes arguments without the shell interpreting quotes. Closes #98 Co-authored-by: OpenClaw AI --- src/resources/extensions/mcporter/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/resources/extensions/mcporter/index.ts b/src/resources/extensions/mcporter/index.ts index a34f5681b..943dbeacf 100644 --- a/src/resources/extensions/mcporter/index.ts +++ b/src/resources/extensions/mcporter/index.ts @@ -69,7 +69,20 @@ async function runMcporter( signal?: AbortSignal, timeoutMs = 30000, ): Promise { - // Use shell exec so PATH resolution works in all contexts + // Cross-platform: use execFile on Windows to avoid quote handling issues + // On Windows, cmd.exe doesn't strip single quotes like Unix shells do + if (process.platform === "win32") { + // Use execFile directly - Windows doesn't need shell for PATH resolution here + const { stdout } = await execFileAsync("mcporter", args, { + timeout: timeoutMs, + maxBuffer: 1024 * 1024, + signal, + env: { ...process.env }, + shell: true, // Enable shell for PATH resolution on Windows + }); + return stdout; + } + // Use shell exec so PATH resolution works on Unix const escaped = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" "); const { stdout } = await execAsync(`mcporter ${escaped}`, { timeout: timeoutMs,