A comprehensive, secure, cross-platform MCP (Model Context Protocol) server for advanced file system operations with enterprise-grade security features.
- Path Validation: Prevents directory traversal attacks
- Sandboxing: Configurable path restrictions
- Rate Limiting: Prevents abuse with configurable limits
- Audit Logging: Comprehensive operation tracking
- Permission Validation: File system permission checks
- Basic Operations: Read, write, delete, copy, move files
- Directory Operations: Create, list, delete directories
- Batch Operations: Efficient bulk file operations
- File Information: Detailed metadata and statistics
- Search: Advanced file search with filters
- ZIP Support: Create and extract ZIP archives
- GZIP Support: Single file compression
- Archive Listing: View archive contents
- Nested Archives: Handle complex archive structures
- Real-time Monitoring: Watch files and directories for changes
- Event Filtering: Configurable event types
- Cross-platform: Works on Windows, macOS, and Linux
- Windows: Full support including long paths
- macOS: Native file system features
- Linux: POSIX compliance
- Path Handling: Automatic path normalization
npm install filesystem-mcp-server
import { FileSystemMCPServer } from 'filesystem-mcp-server';
const server = new FileSystemMCPServer({
allowedPaths: ['/safe/directory'],
restrictedPaths: ['/system', '/etc'],
rateLimit: {
enabled: true,
maxRequests: 100,
windowMs: 60000
}
});
await server.start();
-
read_file
- Description: Read the contents of a file
- Parameters:
-
filePath
(string): Path to the file to read -
encoding
(optional): Text encoding (utf8, ascii, base64, hex, binary, utf16le)
-
-
write_file
- Description: Write content to a file
- Parameters:
-
filePath
(string): Path to the file to write -
content
(string): Content to write -
encoding
(optional): Text encoding -
createDirectories
(optional boolean): Create parent directories if needed
-
-
delete_file
- Description: Delete a file
- Parameters:
-
filePath
(string): Path to the file to delete
-
-
copy_file
- Description: Copy a file from source to destination
- Parameters:
-
sourcePath
(string): Source file path -
destinationPath
(string): Destination file path -
overwrite
(optional boolean): Whether to overwrite existing files
-
-
move_file
- Description: Move or rename a file
- Parameters:
-
sourcePath
(string): Source file path -
destinationPath
(string): Destination file path
-
-
get_file_info
- Description: Get detailed information about a file or directory
- Parameters:
-
path
(string): Path to the file or directory
-
-
file_exists
- Description: Check if a file or directory exists
- Parameters:
-
path
(string): Path to check
-
-
list_directory
- Description: List the contents of a directory
- Parameters:
-
dirPath
(string): Path to the directory -
includeHidden
(optional boolean): Include hidden files
-
-
create_directory
- Description: Create a new directory
- Parameters:
-
dirPath
(string): Path to create -
recursive
(optional boolean): Create parent directories
-
-
delete_directory
- Description: Delete a directory
- Parameters:
-
dirPath
(string): Path to delete -
recursive
(optional boolean): Delete recursively
-
Access file contents using file://
URIs:
file:///path/to/your/file.txt
Access directory listings using directory://
URIs:
directory:///path/to/your/directory
- Path Validation: All paths are validated and normalized to prevent directory traversal attacks
- Permission Checking: File and directory permissions are checked before operations
- Error Handling: Comprehensive error handling with descriptive messages
- Cross-Platform Support: Works on both Windows and Linux with proper path handling
The server runs with stdio transport by default. For custom configurations or different transports, modify the src/index.ts
file.
src/
├── index.ts # Main server entry point
├── tools/
│ └── fileSystemTools.ts # File system tool implementations
├── resources/
│ └── fileSystemResources.ts # File system resource implementations
└── utils/
├── fileOperations.ts # Core file system operations
└── pathUtils.ts # Path validation and utilities
npm run build
npm run dev
npm run clean
{
"name": "read_file",
"arguments": {
"filePath": "/path/to/file.txt",
"encoding": "utf8"
}
}
{
"name": "write_file",
"arguments": {
"filePath": "/path/to/new-file.txt",
"content": "Hello, World!",
"createDirectories": true
}
}
{
"name": "list_directory",
"arguments": {
"dirPath": "/path/to/directory",
"includeHidden": false
}
}
All operations include comprehensive error handling:
- Invalid paths are rejected with descriptive error messages
- Permission errors are clearly reported
- File not found errors include the attempted path
- Directory traversal attempts are blocked
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues and questions, please create an issue in the repository.