Filesystem MCP Server
A secure server for filesystem operations with controlled access to specified directories.
Filesystem MCP Server
A secure Model Context Protocol (MCP) server that provides filesystem operations with controlled access to specified directories.
Features
- Directory access controlled via environment variables
- File operations within allowed directories only
- Thread-safe caching of allowed directories
- Proper handling of paths with spaces
Installation
go get github.com/gomcpgo/filesys
Configuration
Set allowed directories using the environment variable:
export MCP_ALLOWED_DIRS="/path1,/path2,/path with spaces/dir3"
Tools
File Reading
read_file: Read single file contentsread_multiple_files: Read multiple files simultaneously
File Writing
write_file: Create or overwrite files
Directory Operations
create_directory: Create new directorieslist_directory: List directory contentslist_allowed_directories: Show accessible directories
File Management
move_file: Move or rename files and directoriesget_file_info: Get file metadatasearch_files: Search files recursively with pattern matching
Usage with Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"filesystem": {
"command": "/path/to/filesys",
"env": {
"MCP_ALLOWED_DIRS": "/path1,/path2,/path with spaces/dir3"
}
}
}
}
Tool Examples
Reading a File
{
"name": "read_file",
"arguments": {
"path": "/allowed/path/file.txt"
}
}
Listing Directory
{
"name": "list_directory",
"arguments": {
"path": "/allowed/path"
}
}
Security
The filesystem MCP server implements comprehensive security measures to prevent unauthorized file access:
Path Validation
- Symbolic link resolution: All paths are resolved to their canonical form using
filepath.EvalSymlinks()before validation - Canonical path checking: Paths are validated against allowed directories only after resolving all symbolic links
- Path traversal prevention: Attempts to escape allowed directories using
../or similar techniques are blocked - Prefix matching protection: Directory prefixes are validated with path separators to prevent
/allowedfrom matching/allowed_attacker
Symbolic Link Handling
- Legitimate symlinks: Symbolic links within allowed directories are permitted (if their target is also within allowed directories)
- Attack prevention: Symbolic links pointing outside allowed directories are automatically blocked
- Broken symlinks: Broken symbolic links (pointing to non-existent targets) are rejected for security
- Allowed directory symlinks: Allowed directories themselves may be symbolic links (resolved during initialization)
Write Operation Security
- Non-existent paths: When creating new files or directories, the parent directory chain is validated
- Parent validation: Only paths whose parent directories are within allowed areas can be created
- Atomic validation: Path resolution and validation occur atomically to prevent race conditions
Attack Prevention
The server protects against:
- Symlink-based directory traversal attacks
- Path traversal with
../sequences - Broken symlink exploitation
- Prefix matching attacks (
/allowedvs/allowed_attacker) - Nested symlink chains escaping allowed directories
Security Logging
- All blocked access attempts are logged with "SECURITY:" prefix
- Logs include both the requested path and its canonical resolution
- Helps detect and investigate potential attack attempts
Best Practices
- Configure
MCP_ALLOWED_DIRSwith the minimum necessary directories - Use absolute paths for allowed directories
- Monitor logs for "SECURITY:" messages indicating blocked access attempts
- Regularly review allowed directory configurations
Building
go build -o bin/filesys cmd/main.go
License
MIT License
Contributing
Pull requests welcome. Please ensure:
- Tests pass
- New features include documentation
- Code follows project style
Related Servers
Smart Photo Journal MCP Server
Create a memory journal from your local photos in the macOS Photos library.
FTP Access
Provides access to an FTP server for file operations.
awaBerry device as a service
awaBerry Agentic allows for secure remote access to any terminal based device for workflows allowing any Agent and Large Language Model based routine to execute commands on your devices for getting access to required data - and to also write genrated data back.
ZIP MCP Server
Compress and decompress ZIP files, with support for multi-file packaging, password protection, and encryption.
Filesystem MCP Server
Provides AI agents with secure access to local filesystem operations like reading, writing, and managing files and directories.
MCP-PROCESS
Provides shell access to execute commands and interact with the local file system.
Filesystem MCP Server for WSL
A filesystem server for Windows Subsystem for Linux (WSL), using native commands for faster file operations.
Filesystem
Secure file operations with configurable access controls
Cursor MCP File Organizer
Organize files in your Downloads folder using Cursor IDE with customizable rules.
Desktop Commander MCP
Execute terminal commands and edit local files on your desktop.