Skip to content

fix(filesystem): ignore trailing newline in tail - #4674

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/filesystem-tail-trailing-newline
Open

fix(filesystem): ignore trailing newline in tail#4674
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/filesystem-tail-trailing-newline

Conversation

@jstar0

@jstar0 jstar0 commented Aug 20, 2026

Copy link
Copy Markdown

Description

Fix tailFile so a file's final newline is treated as a line terminator rather than an additional empty line. This makes tail=1 return the final content line for files that end with \n or \r\n.

Server Details

  • Server: filesystem
  • Changes to: file utility implementation and regression tests

Motivation and Context

When a file ends with a newline, the reverse chunk reader currently includes the synthetic empty segment after that terminator. Callers requesting the last line therefore receive an empty string instead of the final content line. The fix removes that synthetic segment only for the first chunk read from the end; line handling and chunk-boundary behavior remain unchanged.

How Has This Been Tested?

  • npm exec --workspace @modelcontextprotocol/server-filesystem -- vitest run __tests__/lib.test.ts --reporter=dot — 47 passed
  • npm run build --workspace @modelcontextprotocol/server-filesystem — passed

The regression covers a file containing line1\nline2\n and verifies that tailFile(path, 1) returns line2 and closes the file handle.

Breaking Changes

No. This corrects the returned value for files ending in a newline; files without a trailing newline retain their existing behavior.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

The change is limited to the filesystem server's existing tail operation and adds no protocol, configuration, or dependency changes.

Copilot AI balanced review requested due to automatic review settings August 20, 2026 10:11

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants