File System MCP Server
A Model Context Protocol server that provides safe file system operations with built-in safeguards, backup mechanisms, and comprehensive error handling.
Features
- Safe file reading with metadata extraction and binary file detection
- File creation with overwrite protection and automatic directory creation
- File updates with automatic backup creation and rollback on failure
- Directory listing with filtering, pattern matching, and recursive traversal
- Safe file deletion with backup recovery (moves to backup instead of permanent deletion)
- Comprehensive error handling with structured error responses and recovery suggestions
- Security safeguards with protected path checking and file size limits
- Configurable logging with structured logging and file rotation
Installation
From Source
Dependencies
The server requires Python 3.8+ and the following packages:
mcp
- Model Context Protocol implementationpython-magic
- MIME type detectionaiofiles
- Async file operations
Quick Start
- Create example configuration:
- Validate configuration:
- Start the server:
Configuration
Configuration File
The server uses a JSON configuration file with the following options:
Configuration Options
backup_directory
: Directory where backup files are stored (default:./.mcp_backups
)max_file_size
: Maximum file size for read operations in bytes (default: 10MB)max_recursion_depth
: Maximum depth for recursive directory listing (default: 10)allowed_extensions
: List of allowed file extensions, ornull
for all (default:null
)protected_paths
: List of paths that cannot be modified (default: system directories)enable_backups
: Whether to create backups before destructive operations (default:true
)log_level
: Logging level - DEBUG, INFO, WARNING, ERROR, CRITICAL (default:INFO
)
Kiro Integration
To use with Kiro, add the server to your MCP configuration:
Available Tools
read_file
Read file contents with metadata extraction.
Parameters:
path
(string): Path to the file to read
Features:
- Binary file detection
- Encoding detection and handling
- File metadata (size, permissions, timestamps)
- MIME type detection
write_file
Create a new file with content.
Parameters:
path
(string): Path where the file should be createdcontent
(string): Content to write to the fileoverwrite
(boolean, optional): Whether to overwrite existing file
Features:
- Automatic directory creation
- Overwrite protection
- Backup creation for existing files
- File extension validation
update_file
Update an existing file with automatic backup.
Parameters:
path
(string): Path to the file to updatecontent
(string): New content for the file
Features:
- Automatic backup creation
- Rollback on failure
- File existence validation
list_directory
List directory contents with filtering options.
Parameters:
path
(string): Path to the directory to listpattern
(string, optional): Glob pattern to filter files (e.g.,*.py
,test_*
)recursive
(boolean, optional): Whether to list recursively
Features:
- Pattern matching with glob syntax
- Recursive traversal with depth limits
- File metadata for each entry
- Entry counting and filtering statistics
delete_file
Safely delete a file or directory with backup.
Parameters:
path
(string): Path to the file or directory to delete
Features:
- Moves to backup instead of permanent deletion
- Directory deletion support
- Protected path checking
- File count reporting
get_file_info
Get detailed metadata about a file or directory.
Parameters:
path
(string): Path to the file or directory
Features:
- Comprehensive metadata (size, timestamps, permissions)
- MIME type detection
- Existence checking
- Owner/group information (Unix systems)
Security Features
Protected Paths
The server prevents operations on system-critical directories:
/etc
,/usr
,/bin
,/sbin
(Unix/Linux)/System
(macOS)C:\Windows
,C:\Program Files
(Windows)
File Size Limits
Read operations are limited by the max_file_size
configuration to prevent resource exhaustion.
Path Validation
All paths are resolved and validated to prevent directory traversal attacks.
Backup System
Destructive operations create timestamped backups before making changes, allowing for recovery.
Command Line Interface
Examples
Development
Running Tests
Code Formatting
Project Structure
Error Handling
The server provides structured error responses with:
- Error type classification (SecurityError, FileNotFound, etc.)
- Detailed error messages with context
- Recovery suggestions for common issues
- Structured logging for debugging
Example error response:
Troubleshooting
Common Issues
- Permission Denied
- Check file/directory permissions
- Ensure the server has appropriate access rights
- Verify the path is not in protected directories
- File Too Large
- Increase
max_file_size
in configuration - Use streaming for large files (future enhancement)
- Increase
- Backup Directory Issues
- Ensure backup directory is writable
- Check disk space availability
- Verify backup directory path in configuration
- MIME Type Detection Fails
- Install
python-magic
system dependencies - Falls back to file extension-based detection
- Install
Logging
Enable debug logging for detailed operation information:
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
Changelog
v0.1.0
- Initial release
- Core file operations (read, write, update, delete, list)
- Safety and backup system
- MCP server implementation
- Configuration management
- Comprehensive error handling
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Enables safe file system operations including reading, writing, updating, and deleting files with built-in security safeguards, automatic backups, and comprehensive error handling. Provides directory listing, file metadata extraction, and protects against operations on system-critical paths.
Related MCP Servers
- -securityAlicense-qualityThis server offers secure, read-only access to directory files via the MCP, supporting file searching, .gitignore compliance, path traversal protection, and MIME type detection using the 'file://' URI scheme.Last updated -19MIT License
- -securityFlicense-qualityThis server provides an interface for performing basic file system operations such as navigation, reading, writing, and file analysis, allowing users to manage directories and files efficiently.Last updated -4Python
- -securityFlicense-qualityA full-stack web application that allows users to upload, view, edit, and delete files and folders in a specified workspace, with protection for binary files.Last updated -JavaScript
- AsecurityFlicenseAqualityEnables secure filesystem operations with directory sandboxing and optional read-only mode. Supports file reading/writing, directory management, file searching, and text operations while restricting access to specified directories.Last updated -12Python