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 <ai@openclaw.dev>
This commit is contained in:
RoomWithOutRoof 2026-03-12 21:10:50 +08:00 committed by GitHub
parent f3d995112a
commit 9df0224bdd

View file

@ -69,7 +69,20 @@ async function runMcporter(
signal?: AbortSignal,
timeoutMs = 30000,
): Promise<string> {
// 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,