Repository navigation
fix(install): make start-server.cmd work from non-ASCII profile paths - #523
Merged
Jeomon merged 1 commit intoOct 31, 2026
Merged
Conversation
install writes start-server.cmd as UTF-8, but cmd.exe decodes a batch file with the console code page. When the user profile folder name has non-ASCII characters, the interpreter and log paths in the script come out garbled: cmd fails with "The system cannot find the path specified.", the server never starts and neither log file is created, while install reports that the server is starting. Switch the console to code page 65001 before the line with the paths.
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.
Problem
windows-mcp installwrites~/.windows-mcp/start-server.cmdas UTF-8, but cmd.exe decodes a batch file with the console code page. When the Windows profile folder name has non-ASCII characters (a local account such asC:\Users\JoséorC:\Users\张三), the log paths in the script, and the interpreter path when it lives under the profile, come out garbled: with code page 437Joséis read asJos├⌐, with 936张三is read as寮犱笁. cmd then fails on the log redirection withThe system cannot find the path specified., the server never starts, and neitherserver.lognorserver.error.logis created.installstill printsScheduled task installed — server is starting now.and points atserver.log, and the error itself goes to the task's hidden console, so the user has nothing to go on.Reproduced on Windows 11 with OEM code page 437, at 28dd6a7, without registering a task:
install --transport sse --host 127.0.0.1 --port 9000through click'sCliRunnerwith_schtasksand_register_task_powershellstubbed,CONFIG_DIRand the script path in a folder namedJosé(then张三), and_resolve_programreturning the interpreter plus a stand-in script that prints its arguments.cmd.exe /d /c "<script>"(/dskips AutoRun), in a console of its own (CREATE_NO_WINDOW).Before: exit code 1,
The system cannot find the path specified., no log files. After: exit code 0, andserver.logcontainsserve --transport sse --host 127.0.0.1 --port 9000.It fails the same way when the console is switched to 850 or 936 before the script runs, and the old script works when the console is already on 65001.
Related: #502 (for #493) fixed how
installdecodes schtasks and PowerShell output on zh-CN systems. This is a different problem, in the script thatinstallwrites.Fix
One line in
_build_start_script():chcp 65001 >nulright after@echo off. cmd decodes each line when it reaches it, so the lines after it are read as UTF-8, the encoding the file is written in. Theactivate.batthat venv and virtualenv generate does the same for the same reason.Writing the file in the OEM code page instead is not enough:
张三cannot be encoded in code page 437 or 850 at all.Side effects: the code page change applies only to the console the task gives the script (
conhost --headless). The server's own output goes to the log files. Inside the server, child output is only read through the PowerShell executor, which starts each child withCREATE_NO_WINDOW(so it gets its own console) and already forces UTF-8.installanduninstallare unchanged. Existing installs keep the old script untilwindows-mcp install --forcerewrites it.Tests
tests/test_install_start_script_encoding.py: runsinstall(schtasks and task registration stubbed) for aJoséand a张三profile folder with a stand-in for the server, then runs the generated script withcmd.exe /d /cwithout a window and checks the arguments inserver.log. Both cases fail onmainwithThe system cannot find the path specified.and pass with this change.tests/test_startup_task.py(3 passed),tests/test_install_hidden_console.py(2),tests/test_install_console_encoding.py(2),tests/test_cli_legacy_flags.py(11) andtests/test_cli_paired_flags.py(5): same results onmainand on this branch.ruff checkandruff format --checkare clean on the changed files.Running the script through the task's own action,
conhost.exe --headless cmd.exe /c "<script>", outside Task Scheduler gives the same result before and after (conhost exits with 0 even when the script fails).Not tested: the real scheduled task at logon (I did not register one on my machine), and a real zh-CN system; code page 936 was simulated with
chcp 936.