|
| 1 | +# MCP Filesystem Server |
| 2 | + |
| 3 | +Advanced filesystem operations for AI agents with strict security boundaries. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The MCP Filesystem Server provides AI agents with advanced file operations beyond basic read/write, including batch operations, directory watching, file search/indexing, and permission management, all within strict security boundaries. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +### Core Capabilities |
| 12 | + |
| 13 | +- **Batch Operations**: Execute multiple file operations (copy, move, delete) atomically with automatic rollback on failure |
| 14 | +- **Directory Watching**: Monitor filesystem changes in real-time with event filtering and recursive watching |
| 15 | +- **File Search & Indexing**: Fast full-text search with metadata filtering using Lunr.js |
| 16 | +- **Checksum Operations**: Compute and verify file integrity using MD5, SHA-1, SHA-256, or SHA-512 |
| 17 | +- **Symlink Management**: Create and manage symbolic links within workspace boundaries |
| 18 | +- **Disk Usage Analysis**: Analyze directory sizes, identify large files, and get file type breakdowns |
| 19 | +- **Directory Operations**: Recursive copy, sync (only newer/missing files), and atomic file replacement |
| 20 | + |
| 21 | +### Security Features |
| 22 | + |
| 23 | +The server implements defense-in-depth security with 10 layers of path validation: |
| 24 | + |
| 25 | +1. **Absolute Path Resolution**: Prevents relative path tricks |
| 26 | +2. **Workspace Boundary Check**: Ensures path is within workspace |
| 27 | +3. **Path Traversal Detection**: Blocks `..` and `./` sequences |
| 28 | +4. **System Path Blocklist**: Hardcoded system directories (cannot be overridden) |
| 29 | +5. **Sensitive Pattern Blocklist**: Hardcoded sensitive files (cannot be overridden) |
| 30 | +6. **Subdirectory Restrictions**: Optional allowlist within workspace |
| 31 | +7. **User Blocklist**: Custom blocked paths |
| 32 | +8. **User Pattern Blocklist**: Custom blocked patterns |
| 33 | +9. **Read-Only Mode**: Prevents write/delete operations |
| 34 | +10. **Symlink Validation**: Validates symlink targets are within workspace |
| 35 | + |
| 36 | +### Hardcoded Security (Cannot Be Disabled) |
| 37 | + |
| 38 | +**System Paths (Always Blocked):** |
| 39 | + |
| 40 | +- `/etc`, `/sys`, `/proc`, `/dev`, `/boot`, `/root` |
| 41 | +- `C:\Windows`, `C:\Program Files` |
| 42 | +- `/System`, `/Library`, `/Applications` (macOS) |
| 43 | +- `/bin`, `/sbin`, `/usr/bin`, `/usr/sbin` |
| 44 | + |
| 45 | +**Sensitive Patterns (Always Blocked):** |
| 46 | + |
| 47 | +- `.ssh/`, `.aws/`, `.kube/` |
| 48 | +- `id_rsa`, `*.pem`, `*.key`, `*.p12`, `*.pfx` |
| 49 | +- Files containing: `password`, `secret`, `token` |
| 50 | +- `.env` files |
| 51 | + |
| 52 | +## Installation |
| 53 | + |
| 54 | +### NPM |
| 55 | + |
| 56 | +```bash |
| 57 | +npm install -g @ai-capabilities-suite/mcp-filesystem |
| 58 | +``` |
| 59 | + |
| 60 | +### Docker |
| 61 | + |
| 62 | +```bash |
| 63 | +docker pull digitaldefiance/mcp-filesystem:latest |
| 64 | +``` |
| 65 | + |
| 66 | +## Configuration |
| 67 | + |
| 68 | +### Required Configuration |
| 69 | + |
| 70 | +Create a configuration file (e.g., `mcp-filesystem-config.json`): |
| 71 | + |
| 72 | +```json |
| 73 | +{ |
| 74 | + "workspaceRoot": "/path/to/your/workspace", |
| 75 | + "blockedPaths": [".git", ".env", "node_modules"], |
| 76 | + "blockedPatterns": ["*.key", "*.pem", "*.env"], |
| 77 | + "maxFileSize": 104857600, |
| 78 | + "maxBatchSize": 1073741824, |
| 79 | + "maxOperationsPerMinute": 100, |
| 80 | + "enableAuditLog": true, |
| 81 | + "readOnly": false |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### MCP Client Configuration |
| 86 | + |
| 87 | +Add to your MCP client configuration: |
| 88 | + |
| 89 | +```json |
| 90 | +{ |
| 91 | + "mcpServers": { |
| 92 | + "filesystem": { |
| 93 | + "command": "mcp-filesystem", |
| 94 | + "args": ["--config", "/path/to/mcp-filesystem-config.json"] |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Available Tools |
| 101 | + |
| 102 | +The server exposes 12 MCP tools: |
| 103 | + |
| 104 | +1. **fs_batch_operations** - Execute multiple operations atomically |
| 105 | +2. **fs_watch_directory** - Monitor directory for changes |
| 106 | +3. **fs_get_watch_events** - Retrieve accumulated events |
| 107 | +4. **fs_stop_watch** - Stop watch session |
| 108 | +5. **fs_search_files** - Search by name, content, or metadata |
| 109 | +6. **fs_build_index** - Build searchable file index |
| 110 | +7. **fs_create_symlink** - Create symbolic link |
| 111 | +8. **fs_compute_checksum** - Compute file checksum |
| 112 | +9. **fs_verify_checksum** - Verify file integrity |
| 113 | +10. **fs_analyze_disk_usage** - Analyze disk usage |
| 114 | +11. **fs_copy_directory** - Recursively copy directory |
| 115 | +12. **fs_sync_directory** - Sync directories (only newer/missing) |
| 116 | + |
| 117 | +## Usage Examples |
| 118 | + |
| 119 | +### Batch File Operations |
| 120 | + |
| 121 | +```typescript |
| 122 | +{ |
| 123 | + "operations": [ |
| 124 | + { "type": "copy", "source": "file1.txt", "destination": "backup/file1.txt" }, |
| 125 | + { "type": "move", "source": "temp.txt", "destination": "archive/temp.txt" }, |
| 126 | + { "type": "delete", "source": "old.txt" } |
| 127 | + ], |
| 128 | + "atomic": true |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +### Watch Directory |
| 133 | + |
| 134 | +```typescript |
| 135 | +{ |
| 136 | + "path": "src", |
| 137 | + "recursive": true, |
| 138 | + "filters": ["*.ts", "*.js"] |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +### Search Files |
| 143 | + |
| 144 | +```typescript |
| 145 | +{ |
| 146 | + "query": "TODO", |
| 147 | + "searchType": "content", |
| 148 | + "fileTypes": [".ts", ".js"], |
| 149 | + "useIndex": true |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +### Verify File Integrity |
| 154 | + |
| 155 | +```typescript |
| 156 | +{ |
| 157 | + "path": "important-file.zip", |
| 158 | + "checksum": "abc123...", |
| 159 | + "algorithm": "sha256" |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## Security Warnings |
| 164 | + |
| 165 | +⚠️ **CRITICAL SECURITY CONSIDERATIONS** |
| 166 | + |
| 167 | +1. **Workspace Jail**: All operations are confined to the configured workspace root. This cannot be changed after server starts. |
| 168 | + |
| 169 | +2. **System Paths**: The server blocks access to system directories. This is hardcoded and cannot be disabled. |
| 170 | + |
| 171 | +3. **Sensitive Files**: The server blocks access to SSH keys, AWS credentials, and other sensitive files. This is hardcoded and cannot be disabled. |
| 172 | + |
| 173 | +4. **Rate Limiting**: Configure appropriate rate limits to prevent abuse. |
| 174 | + |
| 175 | +5. **Audit Logging**: Enable audit logging for security monitoring and forensics. |
| 176 | + |
| 177 | +6. **Read-Only Mode**: Consider using read-only mode for untrusted agents. |
| 178 | + |
| 179 | +## Documentation |
| 180 | + |
| 181 | +- **Full Documentation**: [GitHub Repository](https://github.com/Digital-Defiance/ai-capabilities-suite/tree/main/packages/mcp-filesystem) |
| 182 | +- **Security Guide**: [SECURITY.md](https://github.com/Digital-Defiance/ai-capabilities-suite/blob/main/packages/mcp-filesystem/SECURITY.md) |
| 183 | +- **Docker Guide**: [DOCKER.md](https://github.com/Digital-Defiance/ai-capabilities-suite/blob/main/packages/mcp-filesystem/DOCKER.md) |
| 184 | +- **API Reference**: [README.md](https://github.com/Digital-Defiance/ai-capabilities-suite/blob/main/packages/mcp-filesystem/README.md) |
| 185 | + |
| 186 | +## Support |
| 187 | + |
| 188 | +- **Issues**: [GitHub Issues](https://github.com/Digital-Defiance/ai-capabilities-suite/issues) |
| 189 | + |
| 190 | + |
| 191 | +## License |
| 192 | + |
| 193 | +MIT License - see [LICENSE](https://github.com/Digital-Defiance/ai-capabilities-suite/blob/main/packages/mcp-filesystem/LICENSE) |
| 194 | + |
| 195 | +## Related Projects |
| 196 | + |
| 197 | +- [MCP Debugger](https://github.com/Digital-Defiance/ai-capabilities-suite/tree/main/packages/mcp-debugger-server) - Debug Node.js applications via MCP |
| 198 | +- [MCP Process](https://github.com/Digital-Defiance/ai-capabilities-suite/tree/main/packages/mcp-process) - Process management via MCP |
| 199 | +- [MCP Screenshot](https://github.com/Digital-Defiance/ai-capabilities-suite/tree/main/packages/mcp-screenshot) - Screenshot capture via MCP |
0 commit comments