Skip to content

FileResource.read() raises UnicodeDecodeError on Windows for UTF-8 files with non-ASCII characters #3579

@shulkx

Description

@shulkx

Enhancement

FileResource.read() doesn't specify an encoding when calling read_text(), so it falls back to the system locale. On Windows (where the default is often cp1252), this causes a UnicodeDecodeError when reading UTF-8 files that contain non-ASCII characters like smart quotes or em dashes.

Use case: Registering a UTF-8 markdown file as a FileResource with mime_type="text/markdown" on a Windows machine with a cp1252 locale.

Expected: The file is read successfully.

Actual:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 73832:
character maps to <undefined>

The byte 0x9d is part of the UTF-8 sequence for U+201D (RIGHT DOUBLE QUOTATION MARK). The file is valid UTF-8, but the system codec can't decode it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.enhancementImprovement to existing functionality. For issues and smaller PR improvements.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions