fix(server): preserve Windows path backslashes when parsing stdio args#1613
Open
Mordris wants to merge 1 commit into
Open
fix(server): preserve Windows path backslashes when parsing stdio args#1613Mordris wants to merge 1 commit into
Mordris wants to merge 1 commit into
Conversation
shell-quote treats `\` as its escape character, so parsing the args string on Windows stripped every backslash from paths like C:\Users\name\app.jar and the resulting file could not be found. Parse with cmd.exe's escape character `^` on win32 instead. Other platforms are unchanged. Fixes modelcontextprotocol#853
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows, launching a server whose arguments contain a path like
C:\Users\name\app.jarfails because the proxy strips the backslashes whiletokenizing the args string. shell-quote uses
\as its escape character bydefault, which is right for POSIX shells but wrong for Windows paths. This
change passes
{ escape: "^" }(cmd.exe's escape character) to shell-quote onwin32 only. One call site in
server/src/index.ts, no new files ordependencies.
Type of Change
Changes Made
createTransportinserver/src/index.tsnow callsshellParseArgswith aparse option that sets the escape character to
^whenprocess.platform === "win32". On every other platform the options argumentis
undefined, which shell-quote treats exactly like the old two-argumentcall.
Related Issues
Fixes #853
Testing
Test Results and/or Instructions
Reproduced on Windows 10 with the flow from the issue:
node client/bin/start.js node C:\path\to\script.js, then Connect in the UI.Before the fix the server log shows
STDIO transport: ... args=C:Userspathtoscript.jsand the spawn cannot findthe file. With the fix the same steps log the path intact and the script
actually runs.
Other inputs I checked on Windows: a quoted path with spaces
(
"C:\Program Files\My App\server.jar"), a UNC path(
\\server\share\tool.jar), quoted values with spaces(
--name="hello world"), plain flag-style args, and a trailing backslash(
--dir C:\Users\test\ --flag), which previously also merged the twofollowing tokens into one argument. Non-Windows parsing is untouched.
One behavior note: on Windows a bare
^is now consumed as an escapecharacter, same as in cmd.exe. Quoting it (
"foo^bar") keeps it literal.Checklist
npm run prettier-fix)Breaking Changes
None.