Skip to content

fastmcp discover crashes with UnicodeDecodeError on Windows with a non-UTF-8 locale #4689

Closed

Description

@bangddong

What happened?

On Windows where the ANSI codepage is not UTF-8 (Korean cp949 here; cp932/cp936 should behave the same), fastmcp discover exits with an unhandled UnicodeDecodeError if any config file it scans contains a non-ASCII byte. A single em dash in an mcp.json is enough.

Expected: the config is read as UTF-8, which is what the tools writing these files emit. Actual: the command dies with a traceback.

Running the same command with PYTHONUTF8=1 succeeds.

The same failure was fixed in other modules in #3579, #4084, #4164 and #4532; the CLI config scanners aren't covered by those.

Example Code

import pathlib, subprocess, tempfile

d = pathlib.Path(tempfile.mkdtemp())
(d / "mcp.json").write_text(
    '{"mcpServers": {"demo": {"command": "echo", "args": ["hello — world"]}}}',
    encoding="utf-8",
)
subprocess.run(["fastmcp", "discover"], cwd=d)
  File "fastmcp\cli\discovery.py", line 123, in _parse_mcp_config
    text = path.read_text()
UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 60: illegal multibyte sequence

Plain fastmcp discover fails the same way at discovery.py:161 when ~/.claude.json contains a non-ASCII byte, which is common.

Version Information

FastMCP version:                                                          3.4.5
MCP version:                                                             1.28.1
Python version:                                                          3.13.3
Platform:                                             Windows-11-10.0.26200-SP0

locale.getpreferredencoding(False): cp949

Activity

  1. added
    bug
    cli
    on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions