Skip to content

feat(filesystem): ignore dot-prefixed hidden directories by default (#2219) - #4105

Closed
DEM-YU wants to merge 3 commits into
modelcontextprotocol:mainfrom
DEM-YU:feat-filesystem-ignore-hidden
Closed

DEM-YU wants to merge 3 commits into
modelcontextprotocol:mainfrom
DEM-YU:feat-filesystem-ignore-hidden

Conversation

@DEM-YU

@DEM-YU DEM-YU commented May 5, 2026 •

Copy link
Copy Markdown

Fixes #2219

Description

This PR addresses issue #2219 by ensuring that the filesystem server ignores dot-prefixed hidden files and directories (such as .git, .terraform, .env) by default. This significantly reduces unnecessary token consumption and mitigates potential security risks associated with exposing hidden environment variables or repository histories to the LLM.

Introduced a new environment variable MCP_FILESYSTEM_INCLUDE_HIDDEN. By default, this is evaluated as false. Users can opt-in to the legacy behavior by setting MCP_FILESYSTEM_INCLUDE_HIDDEN=true.

Publishing Your Server

(Not applicable, modifying existing server)

Server Details

  • Server: filesystem
  • Changes to: tools (list_directory, list_directory_with_sizes, search_files) and general directory tree parsing logic (buildTree).

Motivation and Context

Dot-prefixed directories (especially .git and .terraform) can grow enormous. When an LLM agent uses the filesystem search tools on a project root, returning these hidden directories massively inflates token usage without adding much value for project analysis. It also introduces a security risk by potentially exposing sensitive local environment variables.

How Has This Been Tested?

  • Added __tests__/hidden-files.test.ts to validate the includeHidden boolean flag logic via vi.mock.
  • Added __tests__/hidden-tree.test.ts to validate the buildTree recursive exclusion using a real temporary directory.
  • Ran all 154 tests locally across 9 test files, all passed successfully.

Breaking Changes

There are no breaking changes to the protocol schema itself. However, clients relying on reading hidden files via this server will now need to explicitly set the MCP_FILESYSTEM_INCLUDE_HIDDEN=true environment variable.

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

Added a console.error initialization log to inform the user of the current hidden-file visibility state, ensuring it does not disrupt the MCP stdout protocol communication.

@changeset-bot

changeset-bot Bot commented Oct 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 95d73d9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cliffhall cliffhall added the closed-out-of-scope Closed: out of scope here; listings and new servers go to the MCP Registry (#4875) label Oct 20, 2026
@cliffhall

Copy link
Copy Markdown
Member

Thank you for this pull request, and apologies for the long wait for a response.

These servers are reference implementations: they exist to show how each part of MCP is used, not to be general-purpose products, so new features are taken selectively, and this change isn't one the maintainers plan to take. This repository also now accepts issues, not pull requests, from anyone but its maintainers; the policy is in CONTRIBUTING.md.

This is not a judgment on the idea or on you. A server in the MCP Registry may well offer it, and anyone is welcome to build on these servers to do so. If you think we've misread it, please open an issue describing the problem and the expected behavior.

This is part of the backlog triage in #4875.

@cliffhall cliffhall closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closed-out-of-scope Closed: out of scope here; listings and new servers go to the MCP Registry (#4875)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filesystem mcp: dot directories should be ignored

2 participants