| Crates.io | mcp-server-filesystem |
| lib.rs | mcp-server-filesystem |
| version | 0.1.2 |
| created_at | 2025-09-21 05:19:57.924269+00 |
| updated_at | 2025-09-22 22:47:47.45436+00 |
| description | A comprehensive Model Context Protocol (MCP) server for filesystem operations |
| homepage | https://github.com/sabry-awad97/rust-mcp-servers |
| repository | https://github.com/sabry-awad97/rust-mcp-servers |
| max_upload_size | |
| id | 1848462 |
| size | 263,509 |
A comprehensive Model Context Protocol (MCP) server that provides secure filesystem operations with directory allowlisting, robust error handling, and comprehensive file management capabilities.
cargo install mcp-server-filesystem
# Start the MCP server with allowed directories (communicates via stdio)
mcp-server-filesystem /path/to/allowed/directory
# Allow multiple directories
mcp-server-filesystem /home/user/projects /tmp/workspace
# Enable debug logging
mcp-server-filesystem /path/to/dir --log-level debug
# Install and run the MCP Inspector to test the server
npx @modelcontextprotocol/inspector mcp-server-filesystem /path/to/test/dir
Add to your Claude Desktop MCP configuration:
{
"mcpServers": {
"filesystem": {
"command": "mcp-server-filesystem",
"args": ["."]
}
}
}
read_text_fileRead 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 linesExample Request:
{
"path": "/home/user/projects/README.md",
"head": 10
}
Example Response:
{
"content": "# My Project\n\nThis is a sample project...",
"path": "/home/user/projects/README.md",
"size": 1024,
"encoding": "utf-8"
}
read_media_fileRead image or audio files and return base64 encoded data with MIME type detection.
Parameters:
path (string): Path to the media fileExample Request:
{
"path": "/home/user/images/photo.jpg"
}
Example Response:
{
"content": "/9j/4AAQSkZJRgABAQEAYABgAAD...",
"mime_type": "image/jpeg",
"path": "/home/user/images/photo.jpg",
"size": 245760
}
read_multiple_filesRead multiple files simultaneously for efficient batch operations.
Parameters:
paths (array of strings): Array of file paths to readExample Request:
{
"paths": [
"/home/user/config.json",
"/home/user/settings.yaml",
"/home/user/data.txt"
]
}
write_fileCreate 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 fileExample Request:
{
"path": "/home/user/projects/new_file.txt",
"content": "Hello, World!\nThis is a new file."
}
edit_fileMake 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 themEdit Operation Format:
{
"old_text": "original line content",
"new_text": "new line content"
}
Example Request:
{
"path": "/home/user/config.py",
"edits": [
{
"old_text": "DEBUG = False",
"new_text": "DEBUG = True"
}
],
"dry_run": false
}
create_directoryCreate a new directory or ensure a directory exists, including parent directories.
Parameters:
path (string): Path of the directory to createExample Request:
{
"path": "/home/user/projects/new_project/src"
}
list_directoryGet a detailed listing of all files and directories in a specified path.
Parameters:
path (string): Path to the directory to listExample Response:
{
"entries": [
{
"name": "README.md",
"type": "[FILE]",
"size": 1024
},
{
"name": "src",
"type": "[DIRECTORY]",
"size": 0
}
],
"path": "/home/user/projects",
"total_entries": 2
}
list_directory_with_sizesGet 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_treeGet a recursive tree view of files and directories as JSON.
Parameters:
path (string): Root path for the treeexclude_patterns (optional array): Glob patterns to excludeExample Request:
{
"path": "/home/user/projects",
"exclude_patterns": ["*.log", "node_modules/**", ".git/**"]
}
move_fileMove or rename files and directories safely.
Parameters:
source (string): Source pathdestination (string): Destination pathExample Request:
{
"source": "/home/user/old_name.txt",
"destination": "/home/user/documents/new_name.txt"
}
search_filesSearch 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 excludeExample Request:
{
"path": "/home/user/projects",
"pattern": "*.rs",
"exclude_patterns": ["target/**", "*.tmp"]
}
get_file_infoRetrieve detailed metadata about a file or directory.
Parameters:
path (string): Path to the file or directoryExample Response:
{
"name": "config.json",
"type": "[FILE]",
"size": 2048,
"is_directory": false,
"modified": 1642694400,
"path": "/home/user/config.json",
"permissions": {
"readable": true,
"writable": true,
"executable": false
}
}
list_allowed_directoriesReturns the list of directories that this server is allowed to access.
Example Response:
Allowed directories:
/home/user/projects
/home/user/documents
/tmp/workspace
The server provides built-in resources for help and status information:
fs://statusCurrent 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://helpComprehensive help documentation with tool descriptions, examples, and usage patterns.
Content includes:
fs://allowed-directoriesDetailed 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
mcp-server-filesystem [OPTIONS]
Options:
-a, <PATH> Add an allowed directory (can be used multiple times)
-l, --log-level <LEVEL> Set logging level [default: info] [possible values: trace, debug, info, warn, error]
-f, --log-format <FORMAT> Set log format [default: pretty] [possible values: pretty, json, compact]
--help Print help information
--version Print version information
The server implements a strict security model:
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"
# Test the server interactively
npx @modelcontextprotocol/inspector mcp-server-filesystem /path/to/test
# 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
# Use MCP Inspector for interactive testing
npx @modelcontextprotocol/inspector mcp-server-filesystem /home/user/projects
# 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
The server provides detailed error messages for common issues:
Run the comprehensive test suite:
# Run all tests
cargo test
# Run specific test categories
cargo test read_files
cargo test search_files
cargo test get_file_info
# Run with coverage
cargo tarpaulin --out html
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.
cargo buildcargo testThis project follows SOLID principles and Domain-Driven Design:
Run cargo fmt and cargo clippy before submitting.
This project is licensed under the MIT License - see the LICENSE file for details.