Filesystem Operations
STDIOPowerful MCP server for filesystem operations with smart context management and secure access.
Powerful MCP server for filesystem operations with smart context management and secure access.
A powerful Model Context Protocol (MCP) server for filesystem operations optimized for intelligent interaction with large files and filesystems. It provides secure access to files and directories with smart context management to maximize efficiency when working with extensive data.
Smart Context Management: Work efficiently with large files and filesystems
Intelligent File Operations:
First, install uv if you haven't already:
# Install uv using the official installer curl -fsSL https://raw.githubusercontent.com/astral-sh/uv/main/install.sh | bash # Or with pipx pipx install uv
Then clone the repository and install dependencies:
# Clone the repository git clone https://github.com/safurrier/mcp-filesystem.git cd mcp-filesystem # Install dependencies with uv uv pip sync requirements.txt requirements-dev.txt
You'll need absolute paths both for the repository location and any directories you want to access:
# Get the absolute path to the repository REPO_PATH=$(pwd) echo "Repository path: $REPO_PATH" # Get absolute paths to directories you want to access realpath ~/Documents realpath ~/Downloads # Or on systems without realpath: echo "$(cd ~/Documents && pwd)"
Open your Claude Desktop configuration file:
~/Library/Application\ Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
Add the following configuration (substitute your actual paths):
{ "mcpServers": { "mcp-filesystem": { "command": "uv", "args": [ "--directory", "/absolute/path/to/mcp-filesystem", "run", "run_server.py", "/absolute/path/to/dir1", "/absolute/path/to/dir2" ] } } }
Important: All paths must be absolute (full paths from root directory). Use
realpath
orpwd
to ensure you have the correct absolute paths.
After saving your configuration, restart Claude Desktop for the changes to take effect.
You can monitor the server logs from Claude Desktop with:
# On macOS tail -n 20 -f ~/Library/Logs/Claude/mcp-server-mcp-filesystem.log # On Windows (PowerShell) Get-Content -Path "$env:APPDATA\Claude\Logs\mcp-server-mcp-filesystem.log" -Tail 20 -Wait
This is particularly useful for debugging issues or seeing exactly what Claude is requesting.
Run the server with access to specific directories:
# Using uv (recommended) uv run run_server.py /path/to/dir1 /path/to/dir2 # Or using standard Python python run_server.py /path/to/dir1 /path/to/dir2 # Example with actual paths uv run run_server.py /Users/username/Documents /Users/username/Downloads
--transport
or -t
: Transport protocol (stdio or sse, default: stdio)--port
or -p
: Port for SSE transport (default: 8000)--debug
or -d
: Enable debug logging--version
or -v
: Show version informationFor interactive testing and debugging with the MCP Inspector:
# Basic usage npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory # With SSE transport npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory --transport sse --port 8080 # With debug output npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory --debug
This server has been built with the FastMCP SDK for better alignment with current MCP best practices. It uses an efficient component caching system and direct decorator pattern.
Edit your Claude Desktop config file to integrate MCP-Filesystem:
Config file location:
~/Library/Application\ Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
{ "mcpServers": { "mcp-filesystem": { "command": "uv", "args": [ "--directory", "/path/to/mcp-filesystem/repo", "run", "run_server.py" ] } } }
To allow access to specific directories, add them as additional arguments:
{ "mcpServers": { "mcp-filesystem": { "command": "uv", "args": [ "--directory", "/path/to/mcp-filesystem/repo", "run", "run_server.py", "/Users/yourusername/Projects", "/Users/yourusername/Documents" ] } } }
Note: The
--directory
flag is important as it tells uv where to find the repository containing run_server.py. Replace/path/to/mcp-filesystem/repo
with the actual path to where you cloned the repository on your system.
# Run all tests uv run -m pytest tests/ # Run specific test file uv run -m pytest tests/test_operations_unit.py # Run with coverage uv run -m pytest tests/ --cov=mcp_filesystem --cov-report=term-missing
# Format code uv run -m ruff format mcp_filesystem # Lint code uv run -m ruff check --fix mcp_filesystem # Type check uv run -m mypy mcp_filesystem # Run all checks uv run -m ruff format mcp_filesystem && \ uv run -m ruff check --fix mcp_filesystem && \ uv run -m mypy mcp_filesystem && \ uv run -m pytest tests --cov=mcp_filesystem
Tool: read_file_lines
Arguments: {
"path": "/path/to/file.txt",
"offset": 99, # 0-based indexing (line 100)
"limit": 51, # Read 51 lines
"encoding": "utf-8" # Optional encoding
}
Tool: grep_files
Arguments: {
"path": "/path/to/search",
"pattern": "function\\s+\\w+\\(",
"is_regex": true,
"context_before": 2, # Show 2 lines before each match (like grep -B)
"context_after": 5, # Show 5 lines after each match (like grep -A)
"include_patterns": ["*.js", "*.ts"],
"results_offset": 0, # Start from the first match
"results_limit": 20 # Show at most 20 matches
}
Tool: edit_file_at_line
Arguments: {
"path": "/path/to/file.txt",
"line_edits": [
{
"line_number": 15,
"action": "replace",
"content": "This is the new content for line 15\n",
"expected_content": "Original content of line 15\n" # Verify content before editing
},
{
"line_number": 20,
"action": "delete"
}
],
"offset": 0, # Start considering lines from this offset
"relative_line_numbers": false, # Whether line numbers are relative to offset
"abort_on_verification_failure": true, # Stop on verification failure
"dry_run": true # Preview changes without applying
}
Tool: find_duplicate_files
Arguments: {
"path": "/path/to/search",
"recursive": true,
"min_size": 1024,
"format": "text"
}
MCP-Filesystem is designed for intelligent interaction with large files and complex filesystems:
Smart Context Discovery
grep_files
to find exactly what you need with precise context controlTargeted Reading
read_file_lines
using offset/limitPrecise Editing
edit_file_at_line
with content verificationAdvanced Analysis
find_duplicate_files
and compare_files
directory_tree
for quick navigationfind_large_files
and find_empty_directories
This workflow is particularly valuable for AI-powered tools that need to work with large files and filesystems. For example, Claude and other advanced AI assistants can leverage these capabilities to efficiently navigate codebases, analyze log files, or work with any large text-based datasets while maintaining token efficiency.
Unlike basic filesystem MCP servers, MCP-Filesystem offers:
Token Efficiency
Intelligent Editing
Advanced Search
Additional Utilities
Security Focus
find_duplicate_files
or recusrive search might take significant time to complete.The server enforces strict path validation to prevent access outside allowed directories:
For best performance with grep functionality:
rg
)