feat(filesystem): ignore dot-prefixed hidden directories by default (#2219)#4105
Open
DEM-YU wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat(filesystem): ignore dot-prefixed hidden directories by default (#2219)#4105DEM-YU wants to merge 1 commit intomodelcontextprotocol:mainfrom
DEM-YU wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2219
Description
This PR addresses issue #2219 by ensuring that the
filesystemserver 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 asfalse. Users can opt-in to the legacy behavior by settingMCP_FILESYSTEM_INCLUDE_HIDDEN=true.Publishing Your Server
(Not applicable, modifying existing server)
Server Details
filesystemtools(list_directory,list_directory_with_sizes,search_files) and general directory tree parsing logic (buildTree).Motivation and Context
Dot-prefixed directories (especially
.gitand.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?
__tests__/hidden-files.test.tsto validate theincludeHiddenboolean flag logic viavi.mock.__tests__/hidden-tree.test.tsto validate thebuildTreerecursive exclusion using a real temporary directory.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=trueenvironment variable.Types of changes
Checklist
Additional context
Added a
console.errorinitialization log to inform the user of the current hidden-file visibility state, ensuring it does not disrupt the MCP stdout protocol communication.