Skip to content

fix(upstream): run Windows cmd.exe-wrapped commands with spaces in paths - #1963

Merged
Dumbris merged 3 commits into
smart-mcp-proxy:mainfrom
felipecrs:claude/issue-1960-fix-30b201
Nov 24, 2026
Merged

Dumbris merged 3 commits into
smart-mcp-proxy:mainfrom
felipecrs:claude/issue-1960-fix-30b201

Conversation

@felipecrs

Copy link
Copy Markdown
Contributor

Pull Request

Description

Fixes #1960. On Windows, a stdio upstream whose command path (or any argument) contains a space never starts.

Cause: for cmd.exe, shellwrap.WrapWithUserShell returns ["/c", commandString], where commandString already has cmd.exe quoting ("C:/.../HTTP Toolkit/x.cmd" arg). exec.Cmd quotes that single argument and escapes the embedded quotes as \". cmd.exe doesn't treat \" as an escape, so it looks for a program literally named \"C:/...cmd\".

Fix: a new shellwrap.UseVerbatimCmdLine(cmd) sets SysProcAttr.CmdLine to cmd.exe /s /c "<commandString>" when the command is cmd.exe /c <string>, so cmd.exe gets the string as built. /s makes cmd.exe strip only the outer quotes. It does nothing on other platforms and for any other command. It runs at the three places that start a shell-wrapped process:

  • process_windows.go: the stdio transport CommandFunc
  • connection_launcher.go: buildLauncherCmd
  • docker.go: the login-shell fallback in newDockerCmd

WrapWithUserShell's return shape is unchanged, because the cidfile insertion helpers and the existing tests rely on ["/c", str].

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • All existing tests pass

TestUseVerbatimCmdLine_PathWithSpace (Windows only) runs a real .cmd file from a HTTP Toolkit directory with an argument containing a space. Without the helper it fails with the error from the issue; with it, it passes. The internal/upstream/... and internal/shellwrap tests pass on Windows, and go vet is clean for windows, linux and darwin on the changed packages. golangci-lint wasn't run locally.

TestResolveDockerSpawnHonorsConfiguredAbsoluteDocker fails locally when SHELL points at Git Bash (it expects backslash paths). That happens with or without this change, and the test passes with SHELL unset.

On Windows, WrapWithUserShell returns ["/c", commandString] for cmd.exe.
Go quotes that single argument and escapes its embedded quotes as \",
which cmd.exe does not understand, so any quoted command path or argument
(e.g. under "Program Files" or "HTTP Toolkit") failed to start.

Add shellwrap.UseVerbatimCmdLine, which sets SysProcAttr.CmdLine to
`cmd.exe /s /c "<commandString>"` for a cmd.exe /c invocation so the
string reaches cmd.exe as built, and call it at the three spawn sites
that run a shell-wrapped command (stdio transport, launcher, docker
fallback). No-op on other platforms and for any other command.

Fixes smart-mcp-proxy#1960
…mand line

Guards the smart-mcp-proxy#1960 fix at the stdio and launcher spawn paths, so a refactor
that drops the UseVerbatimCmdLine call fails a test.
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 20, 2026
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 21, 2026
@codecov-commenter

codecov-commenter commented Nov 22, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Codecov on smart-mcp-proxy#1963 reported two uncovered lines: the !windows no-op in
internal/shellwrap/cmdline_other.go and the shell-wrap fallback in
newDockerCmd (internal/upstream/core/docker.go). Add a !windows test for
the no-op and a cross-platform test that forces the newDockerCmd
fallback with docker genuinely absent.
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 23, 2026
@Dumbris
Dumbris enabled auto-merge (squash) November 24, 2026 11:24
@Dumbris
Dumbris merged commit da26185 into smart-mcp-proxy:main Nov 24, 2026
50 checks passed
@Dumbris

Dumbris commented Nov 24, 2026

Copy link
Copy Markdown
Member

Merged — thanks @felipecrs. This fixes #1960 on both the direct and the Docker fallback path, which is why we went with it over #1980. It ships in the next release.

You have landed several fixes this week (#1961 and this one, with #1962 and #1972 close behind). If you ever feel like mentioning mcpproxy where you talk about your setup, we would appreciate it — entirely optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Windows stdio upstreams fail when the command path contains a space

3 participants