Filesystem MCP Server Configuration Guide
Configure the official Filesystem MCP server for Claude Desktop, Cursor, and Codex CLI: Sandboxed directories, path traversal security, and tools.
claude_desktop_config.json{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"C:/Projects"
]
}
}
}Generate & Test Filesystem MCP Server Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
Filesystem MCP Server Configuration Guide
The official Filesystem Model Context Protocol (MCP) server provides AI hosts with controlled read, write, and directory inspection access to explicitly designated local storage directories. For developers using Claude Desktop, Cursor, and OpenAI Codex CLI, scoped filesystem access serves as the baseline primitive for codebase refactoring, log analysis, and automated project builds.
Granting LLM agents direct file access requires strict isolation. Without rigorous sandbox boundaries, an agent can follow symlinks outside target folders, expose credentials (.env, ~/.ssh/id_rsa), or corrupt host filesystems. The official server enforces boundary restrictions directly at the protocol layer.
The sections below walk through the sandboxed execution model, host configuration JSON/TOML, tool calling semantics, and production error mitigation.
1. System Architecture and Sandboxed Execution
The Filesystem MCP server executes as a dedicated child process communicating with the AI host over Standard Input and Output (stdio). At startup, the server receives a list of authorized directory paths via its command-line arguments. These paths form a closed sandbox boundary.
Core Security Invariants
- ▸Explicit Directory Boundaries: The server only permits operations inside the exact directories passed to its command-line arguments. If an authorized path is
/home/user/workspace, any request targeting/home/user/documentsis immediately rejected. - ▸Canonical Realpath Resolution: To prevent symlink escapes and directory traversal attacks (such as
../../etc/passwd), the server resolves symlinks usingfs.realpathSync()and verifies that the canonical target resides within an allowed root. - ▸Pure Data IO: The filesystem server provides file reading, editing, and listing tools. It possesses no shell execution capabilities, preventing command injection vulnerabilities.
2. Environment Prerequisites and Software Matrix
Verify that your workstation satisfies the following software requirements:
| Component | Minimum Version | Installation Check | Purpose |
|---|---|---|---|
| Node.js | >= 18.0.0 (20+ recommended) | node -v | JavaScript runtime environment |
| npm / npx | >= 9.0.0 | npx -v | Package runner for executing MCP servers |
| @modelcontextprotocol/server-filesystem | Latest release | Package registry | Official reference filesystem server |
Create a designated sandbox directory for development:
# macOS / Linux
mkdir -p ~/projects/mcp-sandbox
# Windows PowerShell
New-Item -ItemType Directory -Force -Path "$HOME\projects\mcp-sandbox"3. Multi-Host Configuration Snippets
Configure your AI clients to launch the Filesystem server over stdio. Provide absolute paths to your allowed directories.
Claude Desktop Configuration (claude_desktop_config.json)
On macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
On Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/developer/projects/mcp-sandbox",
"/Users/developer/documents/specs"
]
}
}
}[!IMPORTANT] On Windows, format paths using forward slashes (e.g.
C:/Users/developer/projects/mcp-sandbox) or double backslashes (C:\\Users\\developer\\projects\\mcp-sandbox). Single backslashes act as escape characters in JSON and will invalidate the file.
Cursor IDE Configuration (.cursor/mcp.json)
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"./src",
"./tests"
]
}
}
}OpenAI Codex CLI Configuration (~/.codex/config.toml)
[mcp_servers.filesystem]
command = "npx"
args = [
"-y",
"@modelcontextprotocol/server-filesystem",
"/home/developer/projects/mcp-sandbox"
]4. Exposed Tools and Capability Reference
The Filesystem MCP server exposes an extensive suite of granular file management tools:
| Tool Name | Parameters | Description |
|---|---|---|
read_file | path | Reads complete UTF-8 contents of a single file |
read_multiple_files | paths | Batch reads multiple files in a single turn to save round trips |
write_file | path, content | Atomically creates or replaces a file with complete content |
edit_file | path, edits | Performs surgical line replacements (diff-based) without rewriting |
create_directory | path | Creates nested directories recursively |
list_directory | path | Returns direct children with names and entry types |
directory_tree | path | Recursively maps a tree structure of project directories |
move_file | source, destination | Moves or renames files within the sandbox boundaries |
search_files | path, pattern | Searches for files matching glob expressions |
get_file_info | path | Retrieves file size, creation timestamp, and modification date |
5. JSON-RPC 2.0 Wire Payloads
Inspecting the underlying protocol framing helps diagnose communication issues between host and server.
Tool Invocation: Reading a File (tools/call)
{
"jsonrpc": "2.0",
"id": "fs-read-101",
"method": "tools/call",
"params": {
"name": "read_file",
"arguments": {
"path": "/home/developer/projects/mcp-sandbox/package.json"
}
}
}Formatted Response Payload
{
"jsonrpc": "2.0",
"id": "fs-read-101",
"result": {
"content": [
{
"type": "text",
"text": "{\n \"name\": \"mcp-sandbox\",\n \"version\": \"1.0.0\",\n \"type\": \"module\"\n}"
}
]
}
}Tool Error Response (Sandbox Violation)
When an agent attempts to read an unauthorized path:
{
"jsonrpc": "2.0",
"id": "fs-read-102",
"result": {
"isError": true,
"content": [
{
"type": "text",
"text": "Access denied: Path '/etc/passwd' is outside of allowed directories."
}
]
}
}6. Common Errors and Production Troubleshooting
When operating the filesystem server across various development workflows, watch for the following operational errors:
Error: Access denied - path outside allowed directories
- ▸Root Cause: The requested file path is not within the directories specified in the client configuration
args. - ▸Resolution: Verify that the path provided in the prompt matches the absolute path declared in your config. Remember that relative paths (
./) resolve relative to the server working directory, not your current shell directory.
Error: File Truncation on Large Rewrites (write_file)
- ▸Root Cause: When an AI agent attempts to rewrite a 1,500-line source file using
write_file, output token generation limits may cause the response to cut off mid-file, corrupting the code. - ▸Resolution: Prompt the agent to use
edit_filefor targeted line substitutions, or chunk modifications across separate helper modules.
Error: spawn npx ENOENT on Windows or Non-Login Shells
- ▸Root Cause: The host application could not find
npxin the system environmentPATH. - ▸Resolution: Provide the absolute binary path in
command:- ▸Windows:
C:\\Program Files\\nodejs\\npx.cmd - ▸macOS / Linux:
/usr/local/bin/npxor/opt/homebrew/bin/npx
- ▸Windows:
7. External Citations and Security Guardrails
Adhere to these operational security best practices when granting filesystem permissions:
- ▸Principle of Least Privilege: Never expose your user home directory (
/Users/usernameor/home/user) or filesystem root (/orC:/). Always configure narrow project-specific directories. - ▸Exclude Secret Files: Ensure directories exposed to the agent do not contain unprotected private keys, API secrets, or database backup dumps.
- ▸Official Specifications and Repositories:
Weekly Protocol Diffs & Verified Drops
New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.
Zero marketing spam. 1-click unsubscribe anytime.
Build your full agent toolstack in the Visual Generator
Combine Filesystem with databases, search APIs, and memory graphs in a single configuration file.
Did this setup guide work with your AI host?
Help test this configuration across Claude, Cursor, and Codex CLI. Be the first to report:
Filesystem MCP Server Configuration Guide FAQ
What is the Filesystem MCP Server Configuration Guide?
Configure the official Filesystem MCP server for Claude Desktop, Cursor, and Codex CLI: Sandboxed directories, path traversal security, and tools.
How do I configure Filesystem MCP Server Configuration Guide in Claude Desktop or Cursor?
You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.
Can I use Filesystem MCP Server Configuration Guide with the OpenAI Codex CLI?
Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.
Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.