Skip to content

fix(config): read MCP config files as UTF-8 - #4164

Merged
jlowin merged 2 commits into
PrefectHQ:mainfrom
pragnyanramtha:codex/mcp-config-utf8-io
May 20, 2026
Merged

jlowin merged 2 commits into
PrefectHQ:mainfrom
pragnyanramtha:codex/mcp-config-utf8-io

Conversation

@pragnyanramtha

Copy link
Copy Markdown
Contributor

Description

MCPConfig.from_file() and MCPConfig.write_to_file() now pass encoding="utf-8" when reading and writing JSON config files.

This fixes a self-evident file IO bug: MCP config values can contain Unicode in server names, descriptions, arguments, or paths, while Path.read_text() and Path.write_text() use the platform locale by default. On Windows that can decode or encode with cp1252 instead of UTF-8. This is the same class of issue as #4084, but in MCP config file IO rather than skill files.

Contribution type

  • Bug fix (simple, well-scoped fix for a clearly broken behavior)
  • Documentation improvement
  • Enhancement (maintainers typically implement enhancements — see CONTRIBUTING.md)

Checklist

  • This PR addresses an existing issue (or fixes a self-evident bug)
  • I have read CONTRIBUTING.md
  • I have added tests that cover my changes
  • I have run uv run prek run --all-files and all checks pass
  • I have self-reviewed my changes
  • If I used an LLM, it followed the repo's contributing conventions (not generic output)

Focused checks run:

  • uv run pytest tests/test_mcp_config.py::test_mcp_config_file_io_uses_utf8 -q
  • uv run pytest tests/cli/test_run.py::TestMCPConfig::test_run_mcp_config -q
  • uv run ruff check fastmcp_slim/fastmcp/mcp_config.py tests/test_mcp_config.py
  • uv run ruff format --check fastmcp_slim/fastmcp/mcp_config.py tests/test_mcp_config.py
  • git diff --check

@marvin-context-protocol marvin-context-protocol Bot added the bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. label May 17, 2026
@pragnyanramtha
pragnyanramtha marked this pull request as ready for review May 17, 2026 01:47
Copilot AI review requested due to automatic review settings May 17, 2026 01:47

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eda3cc1560

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"""Load configuration from JSON file."""
if file_path.exists() and (content := file_path.read_text().strip()):
if file_path.exists() and (
content := file_path.read_text(encoding="utf-8").strip()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve backward compatibility for pre-existing config encodings

Decoding with encoding="utf-8" unconditionally makes from_file() fail on configs written by earlier FastMCP versions on non-UTF-8 locales (for example Windows cp1252 files containing é), which previously round-tripped successfully because both read and write used the locale default. After upgrading, those existing files will raise UnicodeDecodeError and cannot be loaded. Consider a compatibility path (e.g., UTF-8 first, then locale fallback) so this bugfix does not break existing user configs.

Useful? React with 👍 / 👎.

@jlowin
jlowin merged commit 5c2627c into PrefectHQ:main May 20, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants