๐ Filesystem MCP Server
A comprehensive Model Context Protocol (MCP) server that provides secure filesystem operations with directory allowlisting, robust error handling, and comprehensive file management capabilities.
โจ Features
- ๐ Security First - Directory allowlisting prevents unauthorized access
- ๐ Comprehensive File Reading - Text files, media files, and batch operations
- โ๏ธ Advanced File Editing - Line-based edits with git-style diff output
- ๐ Directory Management - Create, list, and navigate directory structures
- ๐ Powerful Search - Pattern-based file search with exclusion filters
- ๐ณ Tree Views - Recursive directory tree visualization as JSON
- ๐ File Information - Detailed metadata including size, permissions, and timestamps
- ๐ File Operations - Move, rename, and organize files safely
- ๐ก๏ธ Robust Error Handling - Comprehensive error messages with context
- ๐งน Input Validation - Automatic path validation and sanitization
- ๐ Rich Documentation - Built-in help and operation guidance
- ๐ฏ SOLID Architecture - Clean, maintainable, and testable codebase
๐ Installation & Usage
Install from Crates.io
Run the Server
# Start the MCP server with allowed directories (communicates via stdio)
# Allow multiple directories
# Enable debug logging
Test with MCP Inspector
# Install and run the MCP Inspector to test the server
Use with Claude Desktop
Add to your Claude Desktop MCP configuration:
๐ ๏ธ Available Tools
File Reading Operations
read_text_file
Read the complete contents of a text file with optional head/tail functionality.
Parameters:
path(string): Path to the file to readhead(optional number): Read only the first N linestail(optional number): Read only the last N lines
Example Request:
Example Response:
read_media_file
Read image or audio files and return base64 encoded data with MIME type detection.
Parameters:
path(string): Path to the media file
Example Request:
Example Response:
read_multiple_files
Read multiple files simultaneously for efficient batch operations.
Parameters:
paths(array of strings): Array of file paths to read
Example Request:
File Writing Operations
write_file
Create a new file or completely overwrite an existing file with new content.
Parameters:
path(string): Path where the file should be writtencontent(string): Content to write to the file
Example Request:
edit_file
Make line-based edits to a text file with git-style diff output.
Parameters:
path(string): Path to the file to editedits(array): Array of edit operationsdry_run(optional boolean): Preview changes without applying them
Edit Operation Format:
Example Request:
Directory Operations
create_directory
Create a new directory or ensure a directory exists, including parent directories.
Parameters:
path(string): Path of the directory to create
Example Request:
list_directory
Get a detailed listing of all files and directories in a specified path.
Parameters:
path(string): Path to the directory to list
Example Response:
list_directory_with_sizes
Get a detailed listing with file sizes and sorting options.
Parameters:
path(string): Path to the directory to listsort_by(string): Sort criteria ("name", "size", "modified")
directory_tree
Get a recursive tree view of files and directories as JSON.
Parameters:
path(string): Root path for the treeexclude_patterns(optional array): Glob patterns to exclude
Example Request:
File Management Operations
move_file
Move or rename files and directories safely.
Parameters:
source(string): Source pathdestination(string): Destination path
Example Request:
search_files
Search for files and directories matching a pattern with exclusion support.
Parameters:
path(string): Directory to search inpattern(string): Glob pattern to matchexclude_patterns(optional array): Patterns to exclude
Example Request:
get_file_info
Retrieve detailed metadata about a file or directory.
Parameters:
path(string): Path to the file or directory
Example Response:
Utility Operations
list_allowed_directories
Returns the list of directories that this server is allowed to access.
Example Response:
Allowed directories:
/home/user/projects
/home/user/documents
/tmp/workspace
๐ Available Resources
The server provides built-in resources for help and status information:
fs://status
Current server status, configuration, and capabilities information.
Example Content:
Filesystem MCP Server Status
Server: Running
Allowed Directories: /home/user/projects, /home/user/documents
Total Allowed Paths: 2
Tools Available: 13
Resources Available: 3
Capabilities:
- Secure file reading (text and media files)
- File writing and editing with line-based operations
- Directory management and navigation
- File search with pattern matching and exclusions
- File metadata and information retrieval
- File operations (move, rename, copy)
- Directory tree visualization
- Security through directory allowlisting
fs://help
Comprehensive help documentation with tool descriptions, examples, and usage patterns.
Content includes:
- Complete tool reference with parameters and examples
- Security model explanation
- Pattern syntax guide
- Example workflows for common tasks
- Allowed directories listing
fs://allowed-directories
Detailed information about configured allowed directories and security model.
Example Content:
Allowed Directories Configuration
The Filesystem MCP Server is configured with the following allowed directories.
All file operations are restricted to these paths and their subdirectories.
ALLOWED PATHS:
1. /home/user/projects
2. /home/user/documents
SECURITY INFORMATION:
- All file paths are validated against these allowed directories
- Operations outside these paths will be rejected
- Symlinks pointing outside allowed directories trigger warnings
- Path traversal attempts (../) are blocked
๐ง Configuration
Command Line Options
)
Security Model
The server implements a strict security model:
- Directory Allowlisting: Only specified directories can be accessed
- Path Validation: All paths are validated and normalized
- Symlink Protection: Symlinks are handled safely with warnings
- Size Limits: Configurable file size limits prevent abuse
- Error Sanitization: Error messages don't leak sensitive information
๐ Usage Examples
With Claude Desktop
Once configured, you can ask Claude:
"Read the contents of my project's README.md file"
"Create a new directory structure for a Python project"
"Search for all Python files in my project and show their contents"
"Edit my configuration file to enable debug mode"
"Show me a tree view of my project directory, excluding build artifacts"
"Show me the server status and available resources"
With MCP Inspector
# Test the server interactively
# Try these operations:
# 1. Use read_text_file to examine files
# 2. Use directory_tree to explore structure
# 3. Use search_files to find specific files
# 4. Use edit_file to make changes with dry_run: true
# 5. Browse resources: fs://status, fs://help, fs://allowed-directories
Command Line Testing
# Use MCP Inspector for interactive testing
# Test specific operations:
# - File reading: read_text_file, read_multiple_files
# - Directory operations: list_directory, directory_tree
# - File management: write_file, edit_file, move_file
# - Search: search_files with various patterns
# - Resources: Browse fs://status, fs://help, fs://allowed-directories
๐จ Error Handling
The server provides detailed error messages for common issues:
- Path Not Found: Clear indication when files or directories don't exist
- Permission Denied: Helpful messages for access issues
- Invalid Patterns: Guidance for correct glob pattern syntax
- Validation Errors: Specific feedback on parameter validation failures
- Security Violations: Safe error messages for unauthorized access attempts
๐งช Testing
Run the comprehensive test suite:
# Run all tests
# Run specific test categories
# Run with coverage
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Clone the repository
- Install Rust (1.70+ required)
- Run
cargo build - Run
cargo test
Code Style
This project follows SOLID principles and Domain-Driven Design:
- Clean Architecture: Separation of concerns with clear layers
- Dependency Injection: Testable and maintainable code
- Comprehensive Testing: Unit and integration tests
- Error Handling: Robust error types and handling
Run cargo fmt and cargo clippy before submitting.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with rmcp - Rust MCP implementation
- File operations powered by tokio
- Pattern matching via globset
- MIME type detection using mime_guess
๐ Support
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions