Skip to content

filesystem: read_text_file with head: 0 or tail: 0 returns the whole file #5184

Closed

Description

@cliffhall

Problem

read_text_file in src/filesystem/server.ts tests head and tail for truthiness. A request for zero lines (head: 0 or tail: 0) falls through to reading the whole file, and head: 0, tail: 0 together is not rejected. The schemas accept any number, so negative or fractional counts reach headFile and tailFile in src/filesystem/lib.ts.

Expected

head and tail are checked against undefined, accept only non-negative integers, and a count of 0 returns an empty result.

Prior work

The PR(s) above targeted the pre-refactor code and are closed as part of the backlog triage in #4875; this issue is where the work continues, with the PR(s) as a prototype. Thank you to their authors.

Activity

  1. added
    bugSomething isn't working
    server-filesystemReference implementation for the Filesystem MCP server - src/filesystem
    on Oct 20, 2026
  2. cliffhall commented on Oct 20, 2026

    @cliffhall
    MemberAuthor

    Triage: Priority Low (total 5)

    • Severity 2: a zero count returns the whole file; easy to avoid
    • Urgency 2: wanted eventually
    • Bonuses:
    • +1 bug label

    Filed from the PR backlog triage (#4877). Board: Servers V2 (#43), Status Incoming, awaiting maintainer review (no milestone yet).

  3. added this to the v2.3.0 milestone on Oct 25, 2026
  4. KissFeng commented on Oct 26, 2026

    @KissFeng

    I have prepared and verified a fix for this on a branch in my fork:
    Branch: fix/filesystem-head-tail-zero
    Commit: cc4b040

    Solution

    • In src/filesystem/server.ts, explicit checks head !== undefined and tail !== undefined are used instead of truthiness. When either is 0, an empty string "" is returned immediately without reading the whole file.
    • Rejects requests when both head: 0 and tail: 0 are supplied.
    • Tightens the input schemas in src/filesystem/server.ts to enforce .int().min(0) so negative or fractional counts are rejected early.

    Validation

    • Updated schema tests and added test cases for head: 0 and tail: 0 in src/filesystem/__tests__/server-tools.test.ts.
    • All 420 unit tests pass: npm test --workspace=@modelcontextprotocol/server-filesystem.
    • Added patch changeset (.changeset/filesystem-head-tail-zero.md).

    Feel free to cherry-pick or pull from this branch whenever ready.

  5. self-assigned this
    on Oct 28, 2026
  6. cliffhall commented on Oct 29, 2026

    @cliffhall
    MemberAuthor

    Shipped in #5377, merged into v2/main; it releases with milestone v2.3.0. Tested together with the rest of the #5269 work in the rollup #5405.

  7. added a commit that references this issue on Nov 4, 2026
    fbddfb0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingserver-filesystemReference implementation for the Filesystem MCP server - src/filesystemv2

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions