ravikant06/file-system-mcp-server
If you are the rightful owner of file-system-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A comprehensive Model Context Protocol (MCP) server that provides AI assistants with safe and secure file system operations.
File System Explorer MCP Server
A comprehensive Model Context Protocol (MCP) server that provides AI assistants with safe and secure file system operations. This server enables AI tools to read, write, and manage files within controlled directories.
Features
- Safe File Operations: Read, write, create, delete, copy, and move files/directories
- Security-First: Restricted to user's home directory by default
- Comprehensive Metadata: File information including size, permissions, timestamps, and MIME types
- Async Operations: Built with async/await for optimal performance
- MCP Protocol: Full compliance with Model Context Protocol standards
- Error Handling: Robust error handling with detailed logging
Available Tools
Tool | Description |
---|---|
read_file | Read contents of a text file |
write_file | Write content to a file |
list_directory | List directory contents with metadata |
create_directory | Create new directories |
delete_file | Delete files or directories |
copy_file | Copy files or directories |
move_file | Move or rename files/directories |
get_file_info | Get detailed file information |
Installation
Prerequisites
- Python 3.8 or higher
- pip (Python package installer)
Setup
-
Clone or download this repository
git clone <repository-url> cd filesystem-mcp-server
-
Create a virtual environment
python3 -m venv py3_file_sys_mcp_env source py3_file_sys_mcp_env/bin/activate # On Windows: py3_file_sys_mcp_env\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Test the installation
python filesystem_server.py
You should see:
INFO:__main__:PathValidator initialized with roots: [PosixPath('/Users/your-home')] INFO:__main__:Starting File System Explorer MCP Server... INFO:__main__:Allowed directories: ['/Users/your-home']
Configuration
Claude Desktop Integration
Add the following to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"filesystem": {
"command": "/absolute/path/to/your/virtual-env/bin/python",
"args": ["/absolute/path/to/filesystem_server.py"],
"env": {}
}
}
}
Example for macOS:
{
"mcpServers": {
"filesystem": {
"command": "/Users/username/Workspace/filesystem-mcp-server/py3_file_sys_mcp_env/bin/python",
"args": ["/Users/username/Workspace/filesystem-mcp-server/filesystem_server.py"],
"env": {}
}
}
}
Security Configuration
By default, the server restricts access to your home directory. To modify allowed directories, edit the allowed_roots
variable in filesystem_server.py
:
# Line 268 in filesystem_server.py
allowed_roots = [str(Path.home())] # Default: home directory only
# allowed_roots = ["/Users/username/Documents", "/Users/username/Projects"] # Custom paths
Usage
Starting the Server
The server runs automatically when Claude Desktop connects to it. For manual testing:
# Activate virtual environment
source py3_file_sys_mcp_env/bin/activate
# Run the server
python filesystem_server.py
Using with Claude Desktop
- Restart Claude Desktop after updating the configuration
- The filesystem tools will be available in Claude Desktop
- You can now ask Claude to:
- Read files: "Read the contents of my notes.txt file"
- Write files: "Create a new file called todo.md with my task list"
- List directories: "Show me what's in my Documents folder"
- Manage files: "Copy my project files to a backup directory"
Tool Parameters
read_file
path
(required): Path to the file to readencoding
(optional): File encoding (default: "utf-8")
write_file
path
(required): Path to the file to writecontent
(required): Content to writeencoding
(optional): File encoding (default: "utf-8")
list_directory
path
(required): Path to the directory to listinclude_hidden
(optional): Include hidden files (default: false)
create_directory
path
(required): Path to the directory to createparents
(optional): Create parent directories (default: true)
delete_file
path
(required): Path to the file or directory to delete
copy_file
source
(required): Source pathdestination
(required): Destination path
move_file
source
(required): Source pathdestination
(required): Destination path
get_file_info
path
(required): Path to the file or directory
Security Features
- Path Validation: All paths are validated against allowed root directories
- Permission Checks: File operations respect system permissions
- Error Handling: Comprehensive error handling prevents crashes
- Logging: All operations are logged for audit purposes
Troubleshooting
Common Issues
- ModuleNotFoundError: Ensure you're using the virtual environment Python in your MCP configuration
- Permission Denied: Check that the server has access to the requested directories
- Server Won't Start: Verify all dependencies are installed correctly
Debug Mode
Enable debug logging by modifying the logging level in filesystem_server.py
:
# Line 25
logging.basicConfig(level=logging.DEBUG) # Change from INFO to DEBUG
Testing the Server
# Test import
python -c "import filesystem_server; print('Import successful')"
# Test server startup
python filesystem_server.py &
# Server should start and wait for connections
kill %1 # Stop the test server
Development
Project Structure
filesystem-mcp-server/
āāā filesystem_server.py # Main server implementation
āāā requirements.txt # Python dependencies
āāā README.md # This file
āāā run_server.sh # Shell script wrapper (optional)
āāā py3_file_sys_mcp_env/ # Virtual environment (created during setup)
Key Components
- PathValidator: Handles path validation and security
- FileSystemOperations: Core file system operations
- MCP Server: Protocol implementation and tool registration
- Tool Handlers: Individual tool implementations
License
This project is open source. Please check the license file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Support
For issues and questions:
- Check the troubleshooting section above
- Review the logs for error messages
- Ensure your MCP configuration is correct
- Verify all dependencies are installed
Note: This server is designed for safe file operations within controlled directories. Always review the security configuration before use in production environments.