How to Set Up and Use the Filesystem MCP Server — Complete Guide
Step-by-step guide to the Filesystem MCP server. Read files, write code, search directories, and manage project structure from your AI assistant.
The Filesystem MCP server gives your AI assistant scoped read and write access to directories on your local machine. It is one of the foundational MCP servers -- maintained by Anthropic in the official modelcontextprotocol/servers repository -- and it solves a specific problem: letting your assistant interact with files outside the context window of your current editor session, while keeping access restricted to directories you explicitly approve.
With 11 tools and roughly 5,665 tokens of context overhead, it is one of the lightest MCP servers available. This guide covers the setup, the security model, practical workflows, and when you actually need it versus when your AI client already handles file access natively.
What the Filesystem MCP Server Exposes
The server provides 11 tools for file and directory operations:
Reading:
read_file-- read the complete contents of a fileread_multiple_files-- read several files in a single callget_file_info-- get metadata (size, modification time, permissions) without reading contentlist_directory-- list the contents of a directory (files and subdirectories)
Writing:
write_file-- create or overwrite a file with new contentedit_file-- make targeted edits to an existing file (search and replace with diff output)
Searching:
search_files-- recursively search for files matching a patternlist_allowed_directories-- show which directories the server has access to
File management:
create_directory-- create a new directory (including nested directories)move_file-- move or rename a file or directorydirectory_tree-- get a recursive tree view of a directory structure
These tools cover the file operations you would normally do in a terminal or file explorer. The important distinction is that every operation is constrained to the directories you specified when starting the server.
The Directory Allowlist Security Model
This is the defining feature of the Filesystem MCP server and the reason it exists as a separate tool rather than being baked into every AI client.
When you start the server, you pass one or more directory paths as arguments. These are the only directories the server can access. Any attempt to read, write, or list files outside these directories will fail. There is no escape, no traversal, no symlink following that bypasses the boundary.
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects/my-app", "/Users/me/data"]
In this configuration, the assistant can access anything under /Users/me/projects/my-app and /Users/me/data, but nothing else on your machine. It cannot read your SSH keys, your browser history, your other projects, or your system files.
This model matters because:
-
AI assistants are conversational. You might ask "find all config files" and expect it to search your project. Without an allowlist, that query could scan your entire filesystem.
-
Write access is powerful. An assistant that can write files anywhere on your machine is a significant security surface. The allowlist constrains writes to directories you control and expect to be modified.
-
Multi-project isolation. If you configure the server with just your current project directory, the assistant cannot accidentally modify files in other projects, even if they are referenced in imports or documentation.
-
Team safety. When you share MCP configurations with your team, the allowlist ensures everyone's server is scoped appropriately. A new team member cannot accidentally configure access to sensitive directories.
Setup
The Filesystem MCP server requires no API keys or environment variables. The only configuration is the list of allowed directories.
Claude Code
Add to your project's .mcp.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/me/projects/my-app"
]
}
}
}
To allow access to multiple directories, add more paths to the args array:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/me/projects/my-app",
"/Users/me/shared-configs",
"/Users/me/data/datasets"
]
}
}
}
Cursor
Create or edit .cursor/mcp.json in your project root:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/me/projects/my-app"
]
}
}
}
VS Code (Copilot)
Add to your VS Code settings.json:
{
"mcp": {
"servers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/me/projects/my-app"
]
}
}
}
}
Choosing your allowed directories
Be specific. Do not pass your home directory (/Users/me) or root (/) as an allowed path. Narrow the scope to the directories the assistant actually needs:
- Single project: pass just the project root. The assistant can read source code, write new files, and manage the directory structure within that project.
- Project plus data: pass the project root and a data directory. Useful for data science workflows where datasets live outside the project.
- Multiple projects: pass each project root separately. The assistant can read across projects (useful for monorepos or shared libraries) while still being unable to access anything else.
On Windows, use Windows-style paths:
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"C:\\Users\\me\\projects\\my-app"
]
Workflow 1: Analyze Project Structure and Find Unused Files
Understanding the shape of a project -- especially one you did not write -- is a common reason to reach for the Filesystem MCP server.
"Show me the directory tree of the project. Then read the package.json and tsconfig.json to understand the project setup. List any TypeScript files in src/ that are not imported by any other file."
The assistant uses directory_tree to get the full project structure, read_multiple_files to inspect key configuration files, and then search_files combined with read_file to trace import chains and identify orphaned files.
This is a workflow that would take considerable manual effort -- opening files, searching for import statements, cross-referencing paths. The assistant does it systematically and reports the results.
Workflow 2: Create a New Module with Proper File Structure
When you are adding a new feature that requires multiple files -- a component, its types, tests, and an index file -- the assistant can create the entire structure in one go.
"Create a new module at src/modules/notifications/ with the following files: types.ts for TypeScript interfaces, service.ts for the notification service class, index.ts that re-exports everything, and service.test.ts with a basic test skeleton. Use the patterns from the existing src/modules/auth/ module as a reference."
The assistant reads the existing auth module to understand your coding patterns, then uses create_directory and write_file to build the new module. The generated code follows your existing conventions because the assistant reads your actual codebase, not a generic template.
Workflow 3: Search for Files Containing a Specific Pattern
The search_files tool performs recursive file searching with pattern matching. It is useful when you need to find files across a large project or multiple directories.
"Search for all files containing 'DATABASE_URL' across the project. Show me each file and the line where it appears."
The assistant uses search_files to locate matches, then read_file on each result to show you the surrounding context. This is similar to running grep -r in a terminal, but the results come back in a structured format that the assistant can reason about.
A more practical example:
"Find all files that import from the old '@utils/helpers' path. I need to update them to import from '@lib/helpers' instead."
The assistant searches for the import pattern, reads each file, and can use edit_file to make the replacements. The edit_file tool performs search-and-replace operations and returns a diff showing what changed, so you can verify each modification.
Workflow 4: Batch Operations on Project Files
File management tasks that are tedious in a GUI or require scripting become conversational with the Filesystem MCP server.
"Find all .test.ts files that are currently in the same directory as their source files. Move each one into a tests subdirectory, creating the directory if it doesn't exist."
The assistant uses search_files to find test files, list_directory to check the current structure, create_directory to set up __tests__ directories where they do not exist, and move_file to relocate each test file. It reports what it moved and where.
Another common scenario:
"Read all the JSON files in src/data/servers/ and generate a summary table showing the name, tool count, and estimated tokens for each server."
The assistant uses list_directory to find the JSON files, read_multiple_files to load them all, and then processes the data to produce the summary. This kind of cross-file analysis is where the Filesystem MCP server shines -- it can read dozens of files in rapid succession without you opening any of them.
Workflow 5: Inspect File Metadata and Audit Permissions
The get_file_info tool returns metadata about a file without reading its contents. This is useful for auditing and diagnostics.
"Check the file sizes and last modified dates for all files in the dist/ directory. Are there any files larger than 1MB? When was the directory last built?"
The assistant lists the directory contents and calls get_file_info on each file to collect sizes and timestamps. It can identify unexpectedly large bundles, stale build artifacts, or files that have not been updated when they should have been.
Token Impact
At 11 tools and approximately 5,665 tokens, the Filesystem MCP server is one of the lightest MCP servers you can run. That is under 3% of Claude's 200K context window. You can comfortably run it alongside several other servers without meaningful impact on your available context.
For comparison, Playwright MCP uses ~10,300 tokens and Supabase MCP uses ~12,875 tokens. The Filesystem server's small footprint makes it an easy addition to any stack without the token budgeting concerns that heavier servers introduce.
When You Need It vs When You Don't
This is the question most developers ask, and the answer depends entirely on which AI client you use.
You probably don't need it if:
-
You use Claude Code. Claude Code has built-in file reading, writing, and searching capabilities that cover the same ground as the Filesystem MCP server. Adding the MCP server on top would be redundant -- you would pay 5,665 tokens for tools you already have natively.
-
You use Cursor or Windsurf in their default configuration. These editors give the AI assistant direct access to your project files through their built-in context providers. The assistant can already read and write files in your workspace.
You do need it if:
-
You need access to files outside your current project. Your AI client typically scopes file access to the open workspace. The Filesystem MCP server can reach into other directories -- a shared config folder, a data directory, another project -- that your editor does not know about.
-
You want explicit access control. The allowlist model gives you fine-grained control over exactly which directories are accessible. If you are working with sensitive codebases or sharing configurations across a team, this explicit scoping is valuable.
-
You use Claude Desktop or another chat-based client. Chat interfaces do not have a concept of a "workspace" or "open project." The Filesystem MCP server is the primary way to give these clients file access.
-
You are building AI agents or automation pipelines. When your MCP client is not an editor but a programmatic agent, the Filesystem server provides structured, scoped file access through the standard MCP protocol.
-
You need to work across multiple project directories simultaneously. Even in editors with built-in file access, you are usually limited to the current workspace. The Filesystem MCP server can span multiple directories.
Common Gotchas
Path resolution
All paths passed to the server tools must be absolute paths. Relative paths (like ./src/index.ts) may not resolve correctly. When giving instructions to your assistant, use full paths or reference files relative to the allowed directories.
Symlinks
The server follows symlinks but constrains access to the allowlist. If a symlink inside an allowed directory points to a location outside the allowed directories, the operation will fail. This is a security feature, not a bug.
Large files
The read_file tool reads entire file contents into the context window. For very large files (multi-megabyte log files, data dumps, compiled bundles), this can consume a significant portion of your context. If you need to inspect large files, consider asking the assistant to read only specific sections or use get_file_info first to check the file size before reading.
Binary files
The Filesystem MCP server is designed for text files. Reading binary files (images, compiled binaries, compressed archives) will return garbled content that the assistant cannot meaningfully interpret. Use get_file_info to check file types before reading, or instruct the assistant to skip non-text files.
Write safety
There is no undo mechanism. When the assistant writes or overwrites a file, the previous content is gone unless you have version control. Always ensure your working directory is under git (or another VCS) before giving the assistant write access. This way, any unintended changes can be reverted with git checkout or git restore.
Concurrent access
The server does not implement file locking. If you are editing a file in your editor while the assistant modifies it through the MCP server, you may encounter conflicts. Save your editor changes first, or use version control to merge the differences.
Configuring the Allowlist for Common Scenarios
Here are some practical allowlist configurations for different workflows:
Solo developer, single project:
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects/my-app"]
Monorepo with shared packages:
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects/monorepo"]
Data science with separate data directory:
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects/ml-project", "/Users/me/datasets"]
Multiple related projects:
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects/frontend", "/Users/me/projects/backend", "/Users/me/projects/shared-types"]
Each scenario scopes access to exactly what is needed. Resist the temptation to pass a broad parent directory "for convenience" -- the narrower the scope, the safer the setup.
Get Started
The Filesystem MCP server is a straightforward, low-overhead tool that fills a specific gap: giving your AI assistant scoped, secure access to files on your machine. Whether you need it depends on your client and your workflow, but when you do need it, nothing else fills the role as cleanly.
For stacks that include the Filesystem server alongside complementary tools, check out the curated configurations on stackmcp.dev. You can also see detailed specs on the Filesystem MCP server page.