Filesystem MCP
MCP Server that enables LLMs to interact with the local filesystem. Provides tools for navigation, search, file management, and analysis — all scoped to allowed directories.
Overview
Filesystem MCP exposes a rich set of tools for reading, writing, searching, and inspecting files and directories. All operations are strictly bounded to the directories you provide at startup, preventing access to any path outside those roots.
Key Features
Navigation: List directory contents (
ls), render trees (tree), and query workspace roots (roots).File I/O: Read single or multiple files (
read,read_many); write, edit, move, and delete (write,edit,mv,rm).Search: Find files by glob pattern (
find) or search content with full regex support (grep).Analysis: Metadata and token estimates (
stat,stat_many), SHA-256 hashing (calculate_hash), and unified diffs (diff_files).Patch & Replace: Apply unified patches (
apply_patch) and bulk search-and-replace across files (search_and_replace).Tasks: Long-running tools support background task execution with progress notifications and cancellation.
Large Output Handling: Oversized results are externalized to ephemeral resource URIs instead of truncating inline.
Security: Strict path validation, safe regex via RE2,
.gitignore-aware operations, and atomic writes.
Requirements
Node.js
>= 24
Quick Start
Run directly:
Client Configuration
Or add manually to .vscode/mcp.json:
CLI:
CLI:
Or add to ~/.cursor/mcp.json:
Add to claude_desktop_config.json:
MCP config:
MCP Surface
Tools
Tool | Description |
| List workspace roots the server can access |
| List directory contents (non-recursive) |
| Find files by glob pattern |
| Render a bounded directory tree |
| Read text content of a file |
| Read multiple files in one request |
| Get file or directory metadata |
| Get metadata for multiple paths |
| Search file content by literal or RE2 regex |
| Compute SHA-256 hash of a file or directory |
| Generate a unified diff between two files |
| Create a directory (recursive) |
| Write content to a file (create or overwrite) |
| Edit a file via sequential string replacements |
| Move or rename a file or directory |
| Delete a file or directory |
| Apply a unified diff patch to a file |
| Search and replace text across files matching a glob |
roots — List workspace roots
Enumerate the directories the server is allowed to access. Call this first in any session.
No input parameters.
ls — List directory contents
List immediate directory contents (non-recursive). Returns name, type, size, and modified date per entry.
Parameter | Type | Required | Default | Description |
| string | No | root | Base directory |
| boolean | No |
| Include hidden items ( |
| boolean | No |
| Include |
| string | No | — | Glob filter enabling recursive traversal (e.g. |
|
| No |
| Sort field |
| integer | No | — | Max recursion depth when |
| integer | No | — | Truncation limit (1–20,000) |
| boolean | No |
| Resolve and include symlink targets |
find — Find files by glob
Locate files matching a glob pattern. Returns relative paths and metadata.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Glob pattern (e.g. |
| string | No | root | Search root |
| integer | No |
| Max results (1–10,000) |
| integer | No | — | Max directory depth to scan (0–100) |
|
| No |
| Sort field |
| boolean | No |
| Include hidden files |
| boolean | No |
| Include ignored directories (disables |
Supports background task execution with progress reporting.
tree — Render directory tree
Returns both an ASCII tree (text) and a structured JSON tree.
Parameter | Type | Required | Default | Description |
| string | No | root | Base directory |
| integer | No |
| Max depth (0–50); |
| integer | No |
| Max entries (1–20,000) |
| boolean | No |
| Include hidden items |
| boolean | No |
| Include ignored items (disables |
read — Read file content
Read text content of a single file with optional line-range or head preview.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Absolute path to file |
| integer | No | — | Read first N lines (1–100,000); mutually exclusive with |
| integer | No | — | Start line (1-based, inclusive) |
| integer | No | — | End line (1-based, inclusive); requires |
Large files return a resourceUri; call resources/read on that URI for full content.
read_many — Read multiple files
Batch-read up to 100 files in a single request.
Parameter | Type | Required | Default | Description |
| string[] | Yes | — | File paths (1–100 items) |
| integer | No | — | Read first N lines of each file |
| integer | No | — | Start line per file |
| integer | No | — | End line per file (requires |
Per-file truncationReason can be head, range, or externalized. Total read budget is capped internally.
stat — Get file/directory metadata
Returns name, type, size, created/modified/accessed timestamps, permissions, MIME type, and a token estimate (size ÷ 4).
Parameter | Type | Required | Default | Description |
| string | Yes | — | Absolute path |
stat_many — Get metadata for multiple paths
Batch version of stat.
Parameter | Type | Required | Default | Description |
| string[] | Yes | — | Paths (1–100 items) |
grep — Search file content
Search for text within files using literal match or RE2 regex. Returns matching lines with optional context.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Text to search (literal by default, RE2 regex when |
| string | No | root | Search root (file or directory) |
| boolean | No |
| Treat |
| boolean | No |
| Case-sensitive matching |
| boolean | No |
| Match whole words only |
| integer | No |
| Lines of context before/after each match (0–50) |
| integer | No |
| Max match rows returned (0–10,000) |
| string | No |
| Glob to restrict candidate files (e.g. |
| boolean | No |
| Include hidden files |
| boolean | No |
| Include ignored directories |
RE2 does not support lookahead, lookbehind, or backreferences. Results exceeding 50 inline matches are externalized viaresourceUri.
calculate_hash — SHA-256 hash
Compute a SHA-256 hash. For directories, produces a deterministic composite hash of all contained files (lexicographically sorted, .gitignore-aware).
Parameter | Type | Required | Default | Description |
| string | Yes | — | File or directory path |
diff_files — Generate unified diff
Create a unified diff between two files. Check isIdentical in the response — if true, the files match and no patch is needed.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Original file path |
| string | Yes | — | Modified file path |
| integer | No | — | Lines of context in the diff |
| boolean | No |
| Ignore leading/trailing whitespace |
| boolean | No |
| Strip trailing carriage returns |
Large diffs are externalized to a resourceUri.
mkdir — Create directory
Create a directory and all missing parent directories (recursive).
Parameter | Type | Required | Default | Description |
| string | Yes | — | Directory path to create |
write — Write file
Create or overwrite a file. Parent directories are created automatically.
Parameter | Type | Required | Default | Description |
| string | Yes | — | File path |
| string | Yes | — | Content to write |
Overwrites existing file content without confirmation.
edit — Edit file
Apply sequential literal string replacements to an existing file. Replaces the first occurrence of each oldText.
Parameter | Type | Required | Default | Description |
| string | Yes | — | File to edit |
|
| Yes | — | Ordered list of replacement operations |
| boolean | No |
| Validate edits without writing |
Include 3–5 lines of surrounding context in oldText to uniquely target the location. Unmatched edits are reported in unmatchedEdits.
mv — Move or rename
Move or rename a file or directory. Parent directories of the destination are created automatically. Falls back to copy+delete for cross-device moves.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Source path |
| string | Yes | — | Destination path |
rm — Delete file or directory
Delete a file or directory.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Path to delete |
| boolean | No |
| Delete non-empty directories |
| boolean | No |
| No error if the path is missing |
Non-empty directories withrecursive: false return E_INVALID_INPUT with guidance to retry using recursive: true.
apply_patch — Apply unified patch
Apply a unified diff patch to a file. Always validate with dryRun: true before writing.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Target file path |
| string | Yes | — | Unified diff patch content (must include hunk headers) |
| integer | No |
| Fuzzy matching tolerance |
| boolean | No |
| Auto-convert line endings to match the target file |
| boolean | No |
| Validate without writing |
If patch application fails, regenerate a fresh patch via diff_files against the current file content and retry.
search_and_replace — Search and replace across files
Replace text in all files matching a glob. Replaces all occurrences per file. Use dryRun: true to preview scope before writing.
Parameter | Type | Required | Default | Description |
| string | Yes | — | Glob for target files (e.g. |
| string | Yes | — | Text to find |
| string | Yes | — | Replacement text |
| string | No | root | Search root directory |
| boolean | No |
| Treat |
| boolean | No |
| Preview matches without writing |
Resources
URI | Description | MIME Type |
| Usage guidance for models |
|
| Ephemeral cached large tool output | varies |
When a tool response includes a resource_link/resourceUri, treat it as authoritative for full payload retrieval and call resources/read with that URI.
Prompts
Prompt | Description |
| Returns usage instructions for the server |
Tasks (Background Execution)
The server declares full task capabilities (tasks/list, tasks/cancel). The following tools support task-based invocation with progress notifications:
find, tree, read, read_many, stat_many, grep, mkdir, write, mv, rm, calculate_hash, apply_patch, search_and_replace
Include _meta.progressToken in a tools/call request to receive notifications/progress updates. Use tools/call with a task field to invoke as a background task, then poll tasks/get and retrieve output via tasks/result.
Recommended task follow-up loop:
Start with
tools/call+task(optional_meta.progressToken).Poll
tasks/getuntil terminal status (completed,failed,cancelled).Fetch final payload with
tasks/result.
Task status notifications (notifications/tasks/status) are best-effort and emitted only when the transport/runtime provides a notification sender.
Cancellation semantics:
tasks/cancelis the canonical cancellation API.Clients should treat
E_CANCELLEDas cancellation even if a transport/client surfaces a terminal failure shape.
Configuration
CLI
Option | Description |
| Positional: one or more directories the server may access |
| Allow the current working directory as an additional root |
| Display server version |
| Display help |
Examples:
Allowed Directories
Directories are resolved from three sources, merged at runtime:
CLI arguments — positional directory paths passed at startup.
MCP Roots protocol — directories provided by the connected client after initialization (accepted only if they are within the CLI baseline when CLI directories are set).
--allow-cwd— the current working directory is added automatically.
If no directories are configured at startup and the connected client does not supply MCP Roots, all tool calls will fail. Pass at least one directory argument or use--allow-cwd.
Compatibility
Set FS_CONTEXT_STRIP_STRUCTURED=1 to strip structuredContent from tool results and outputSchema from tool definitions for compatibility with clients that only consume text content.
Security
Path validation: All operations use
isPathWithinDirectoriesto prevent path traversal attacks.Glob safety: Glob patterns are validated to reject absolute paths and
..traversal before execution.Safe regex:
re2executes regex (no catastrophic backtracking);safe-regex2rejects unsafe patterns before use.Hidden files: Excluded from listings and searches by default; opt in with
includeHidden: true.Ignored directories:
node_modules,.git,dist, and similar directories are excluded by default; opt in withincludeIgnored: true.Windows safety: Reserved device names (e.g.
CON,NUL,COM1) and drive-relative paths (e.g.C:path) are rejected at the CLI.Input limits: Paths are bounded to 4,096 characters; patterns to 1,000 characters.
Atomic writes: File writes use an atomic write-then-rename strategy to prevent partial writes.
Docker: The container runs as a non-root user (
mcp).
All diagnostic output goes tostderr. Tool handlers must never write to stdout, as doing so would corrupt the stdio transport.
Development
Install
Scripts
Script | Command | Purpose |
|
| Watch-mode TypeScript compilation |
|
| Run built server with file watching |
|
| Production build |
|
| Run full test suite |
|
| Fast test runner (no build step) |
|
| Test with coverage |
|
| Lint source files |
|
| Auto-fix lint issues |
|
| Format all files |
|
| TypeScript type checking |
MCP Inspector
Or manually:
Build & Release
Releases are triggered manually via GitHub Actions (workflow_dispatch). The pipeline:
Bumps
package.jsonandserver.jsonto the selected version (patch / minor / major or custom).Runs lint, type-check, tests, and build.
Commits, tags (
vX.Y.Z), and creates a GitHub Release with auto-generated notes.Publishes to npm (
@j0hanz/filesystem-mcp) with OIDC provenance.Publishes to the MCP Registry (
io.github.j0hanz/filesystem-mcp).Builds and pushes the Docker image (
ghcr.io/j0hanz/filesystem-mcp) forlinux/amd64andlinux/arm64.
The Glama listing requires a separate manual release step on the Glama dashboard.
Docker Build (local)
Troubleshooting
No directories configured
If no directories are provided at startup and the client doesn't supply MCP Roots, all tool calls fail with E_ACCESS_DENIED. Use roots to inspect configured roots.
Path outside allowed directories
Tools return E_ACCESS_DENIED when a path is outside all allowed roots. Use roots first to see what is available.
Empty directory or no matches
find and grep return empty results rather than errors when nothing matches. Verify the pattern and root path.
Pattern rejected (
Glob patterns cannot be absolute or use .. to traverse upward. RE2 patterns are validated before use.
Non-empty directory delete fails
rm returns E_INVALID_INPUT for non-empty directories without recursive: true. Either set recursive: true or remove contents first.
Patch application failed
apply_patch requires valid unified hunk headers (@@ -N,M +N,M @@). Regenerate the patch with diff_files against the current file content and retry.
Stdout contamination
The server uses stdio transport. Never write to stdout in custom integrations. All diagnostic output goes to stderr. For Claude Desktop, check ~/Library/Logs/Claude/mcp*.log (macOS) or the equivalent on Windows.