Skip to content

filesystem: read_text_file's tool description claims "Handles various text encodings", contradicting its UTF-8-only implementation and README #5746

Backlog

Description

@MicroMilo

Which server?

filesystem (@modelcontextprotocol/server-filesystem)

Server version

2.4.1 (npm; also verified unchanged on v2/main 002bcceed159)

How did you run the server?

npx (npm package)

Transport

stdio

Protocol era

Legacy (2025-11-25 or earlier)

MCP client and version

Custom Python JSON-RPC stdio client (mcpfuse test harness)

Operating system and runtime

Linux x64 (Ubuntu 22.04), Node.js v22

Server configuration

npx -y @modelcontextprotocol/server-filesystem@2.4.1 /tmp/fs-encoding-repro

Steps to reproduce

  1. Create non-UTF-8 text files inside /tmp/fs-encoding-repro:
    python3 -c '
    open("/tmp/fs-encoding-repro/utf16_bom.txt", "wb").write("Hello\nSecond line\n".encode("utf-16"))
    open("/tmp/fs-encoding-repro/gbk.txt", "wb").write("你好世界\n".encode("gbk"))
    '
  2. Call read_text_file on both files (with and without head/tail):
    {"path": "/tmp/fs-encoding-repro/utf16_bom.txt"}
    {"path": "/tmp/fs-encoding-repro/utf16_bom.txt", "tail": 1}
    {"path": "/tmp/fs-encoding-repro/gbk.txt", "head": 1}

Expected behavior

Either read_text_file actually handles non-UTF-8 text encodings (e.g., UTF-16 with BOM) or reports an error as claimed, or its tools/list description accurately states that it decodes files as UTF-8 (matching src/filesystem/README.md:159).

Actual behavior

src/filesystem/server.ts:418-420 advertises in tools/list:

Read the complete contents of a file from the file system as text. Handles various text encodings and provides detailed error messages if the file cannot be read.

However:

  • src/filesystem/README.md:159 explicitly states the opposite: Always treats the file as UTF-8 text regardless of extension.
  • readFileContent (src/filesystem/lib.ts:644-651), headFile (lib.ts:1238, new StringDecoder("utf-8")), and tailFile all unconditionally decode bytes as UTF-8 with no BOM/encoding detection or decoding error.
  • Reading a UTF-16LE+BOM file silently returns isError: false with U+FFFD replacement characters and NUL-interleaved text (and tail: 1 returns a single NUL byte); reading a GBK file silently returns replacement characters (\ufffd) with all text lost.

Logs or error output

read_text_file({"path": "utf16_bom.txt"}) -> isError: false:
"\ufffd\ufffdH\u0000e\u0000l\u0000l\u0000o\u0000\n\u0000S\u0000e\u0000c\u0000o\u0000n\u0000d\u0000 \u0000l\u0000i\u0000n\u0000e\u0000\n\u0000"

read_text_file({"path": "utf16_bom.txt", "tail": 1}) -> isError: false:
"\u0000"

read_text_file({"path": "gbk.txt", "head": 1}) -> isError: false:
"\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"

Already prototyped a fix?

Per CONTRIBUTING.md (issues-only policy), I am not opening a pull request. (Similar tools/list description alignment fix: #5704.)

Suggested prompt for fixing this:

In src/filesystem/server.ts, update read_text_file's (and its deprecated alias read_file's, if applicable) description so it no longer claims "Handles various text encodings". Align it with src/filesystem/README.md ("Always treats the file as UTF-8 text regardless of extension"), noting clearly that files are decoded as UTF-8 (and that read_media_file should be used for binary or non-UTF-8 files). Update any affected tool description snapshot tests.

Before you submit

  • I searched existing issues and this is not a duplicate.
  • This is not a security vulnerability report (those go through the private advisory form).

Activity

  1. FranklinFranklin commented on Dec 3, 2026

    @FranklinFranklin

    If you are integrating tools or external APIs with LLMs (Claude Desktop, Cursor, Zed), the Model Context Protocol (MCP) is the current standardized standard (JSON-RPC over stdio or SSE).

    Key Architectural Considerations:

    1. Direct stdio vs SSE: For local desktop extensions, standard stdio transport is the cleanest and requires no port management. For remote or hosted sandboxes, use SSE with token bearer authentication.
    2. Top Production Servers in the Ecosystem:
      • Playwright_Mcp: invisible playwright mcp: Playwright MCP server undetected by anti-bots and captchas: AI agent browses the web (▲ 350 community upvotes)
      • Metaharness: The meta-harness for AI agents — scaffold your own focused, branded agent harness with its own npx CLI, MCP
    3. 1-Click CLI Inspection:
      You can inspect verified MCP configurations and telemetry directly from your terminal:
      # Install the zero-dependency AgentStack CLI:
      curl -sL https://agents.techuis.nl/install.sh | bash
      
      # Inspect MCP registry details & client config:
      agentstack info playwright_mcp

    For the complete community-verified registry of 40+ MCP servers with Claude & Cursor 1-click configs, check:
    https://agents.techuis.nl/mcp

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions