Skip to content

cli: read MCP and fastmcp.json config files as utf-8 - #5345

Merged
zzstoatzz merged 2 commits into
mainfrom
fix/cli-config-utf8-reads
Oct 2, 2026
Merged

zzstoatzz merged 2 commits into
mainfrom
fix/cli-config-utf8-reads

Conversation

@zzstoatzz

Copy link
Copy Markdown
Collaborator

the cli read fastmcp.json, mcp.json and the existing claude_desktop_config.json with the system code page, so on windows with cp1252/cp936 non-ascii env/args values came through garbled or crashed fastmcp install. every such read now passes encoding="utf-8", matching MCPConfig.from_file, MCPServerConfig.from_file and fastmcp discover (#4690).

closes #5317

what was affected

seven call sites decoded with the locale encoding: run_command and create_mcp_config_server (fastmcp run), the MCPConfig check in fastmcp inspect, _resolve_json_spec (fastmcp list/call), load_and_merge_config, process_common_args (all installers), and the env-merge pre-read in install_claude_desktop. with an arabic path like C:\Users\فاطمة\notes.js in the file, cp1252 hits the undefined byte 0x81 and raises UnicodeDecodeError. some callers don't catch it at all, and install_claude_desktop reports it as Failed to install server: 'charmap' codec .... latin-1 text like Olá José decodes to mojibake without any error.

tests

tests/cli/test_config_encoding.py adds a fixture that makes reads without an explicit encoding decode as cp1252. it patches builtins.open and io.text_encoding, which is what pathlib consults. the file then drives each entry point with a utf-8 config containing arabic and accented text. all five tests fail on the previous code with the reporter's 'charmap' codec can't decode byte 0x81 error.

not in scope

writes that still use the default encoding are untouched. fastmcp generate-cli writing its script and skill file could hit the same issue on the write side if tool descriptions contain non-ascii. that's a separate change if we want it. --env-file goes through dotenv_values, which already defaults to utf-8.


Opened by the fastmcp-triage run on nate's laptop (run); the agent chose ready, urgency soon.

The issue is open with no comments, no assignees and no linked PRs. The reporter didn't offer to fix it, so the fix is ours to do. The diagnosis checks out. MCPConfig.from_file, MCPServerConfig.from_file, write_to_file and discovery (#4690) already use utf-8. Seven CLI call sites still used the locale encoding: run_command, create_mcp_config_server, the inspect MCPConfig check, _resolve_json_spec (list/call), load_and_merge_config, process_common_args and install_claude_desktop. The fix adds encoding="utf-8" at each site, with no behavior change for utf-8 locales. The new tests in tests/cli/test_config_encoding.py simulate a cp1252 locale. All 5 fail on unchanged code with the reporter's exact 'charmap' codec can't decode byte 0x81 error, and all 5 pass with the fix. Two consecutive prek run --all-files runs were clean, and prek --files on the untracked test was clean too. Full pytest -n auto: 7916 passed and 3 failed (conformance, uv_transport, github openapi perf). All 3 need network the sandbox blocks (npm, github). That run used HOME redirected to $TMPDIR because the sandbox stops subprocesses writing ~/Library. Without the redirect, stdio tests also fail identically on unchanged code. This isn't a shared dispatch or security path, so I skipped the adversarial pass. Ready: I'd ask him to review and merge as is.

Resume the session: claude --resume b1067b9d-7a01-46e6-89ae-bfb798f631b6

🤖 Generated with Claude Code

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. labels Sep 28, 2026
@zzstoatzz
zzstoatzz marked this pull request as ready for review September 29, 2026 02:09
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T02:12:37.058354Z 8759ace Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@zzstoatzz
zzstoatzz merged commit 0e4c8aa into main Oct 2, 2026
20 checks passed
@zzstoatzz
zzstoatzz deleted the fix/cli-config-utf8-reads branch October 2, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI misreads non-ASCII fastmcp.json / mcp.json / Claude Desktop config on Windows

1 participant