Advanced filesystem operations for AI agents with strict security boundaries. Part of the AI Capabilities Suite.
This package is maintained in the AI Capabilities Suite monorepo.
The MCP Filesystem Server provides AI agents with advanced file operations beyond basic read/write, including:
- Batch Operations: Execute multiple file operations atomically with rollback support
- Directory Watching: Monitor filesystem changes in real-time with event filtering
- File Search & Indexing: Fast full-text search with metadata filtering
- Checksum Operations: Compute and verify file integrity (MD5, SHA-1, SHA-256, SHA-512)
- Symlink Management: Create and manage symbolic links within workspace boundaries
- Disk Usage Analysis: Analyze directory sizes and identify large files
- Directory Operations: Recursive copy, sync, and atomic file replacement
All operations are confined within strict security boundaries to prevent unauthorized access.
CRITICAL: This server implements defense-in-depth security with 10 layers of path validation. All operations are confined to a configured workspace root. See SECURITY.md for complete security documentation.
npm install -g @ai-capabilities-suite/mcp-filesystemyarn global add @ai-capabilities-suite/mcp-filesystemdocker pull ghcr.io/digital-defiance/mcp-filesystem:latestSee DOCKER.md for Docker deployment guide.
Create a mcp-filesystem-config.json file:
{
"workspaceRoot": "/path/to/your/workspace",
"blockedPaths": [".git", ".env", "node_modules"],
"blockedPatterns": ["*.key", "*.pem", "*.env"],
"maxFileSize": 104857600,
"maxBatchSize": 1073741824,
"maxOperationsPerMinute": 100,
"enableAuditLog": true,
"readOnly": false
}mcp-filesystem --config ./mcp-filesystem-config.jsonAdd to your MCP client configuration (e.g., Claude Desktop, Kiro):
{
"mcpServers": {
"filesystem": {
"command": "mcp-filesystem",
"args": ["--config", "/path/to/mcp-filesystem-config.json"]
}
}
}The server exposes 12 MCP tools for filesystem operations:
Execute multiple filesystem operations atomically with rollback support.
Parameters:
operations: Array of operations (copy, move, delete)atomic: Boolean (default: true) - rollback all on failure
Example:
{
"operations": [
{ "type": "copy", "source": "file1.txt", "destination": "backup/file1.txt" },
{ "type": "move", "source": "temp.txt", "destination": "archive/temp.txt" },
{ "type": "delete", "source": "old.txt" }
],
"atomic": true
}Monitor a directory for filesystem changes.
Parameters:
path: Directory to watchrecursive: Boolean - watch subdirectoriesfilters: Array of glob patterns to filter events
Returns: Session ID for retrieving events
Example:
{
"path": "src",
"recursive": true,
"filters": ["*.ts", "*.js"]
}Retrieve accumulated events from a watch session.
Parameters:
sessionId: Watch session ID from fs_watch_directory
Returns: Array of filesystem events (create, modify, delete, rename)
Stop a directory watch session and clean up resources.
Parameters:
sessionId: Watch session ID to stop
Search for files by name, content, or metadata.
Parameters:
query: Search query stringsearchType: "name", "content", or "both"fileTypes: Array of file extensions to filterminSize,maxSize: Size constraints in bytesmodifiedAfter: ISO date stringuseIndex: Boolean - use file index for faster search
Example:
{
"query": "TODO",
"searchType": "content",
"fileTypes": [".ts", ".js"],
"useIndex": true
}Build a searchable index of files for fast searching.
Parameters:
path: Directory to indexincludeContent: Boolean - index file contents (text files only)
Returns: Index statistics (file count, total size, index size)
Create a symbolic link within the workspace.
Parameters:
linkPath: Path where symlink will be createdtargetPath: Path the symlink points to (must be within workspace)
Compute file checksum for integrity verification.
Parameters:
path: File pathalgorithm: "md5", "sha1", "sha256", or "sha512"
Returns: Checksum hex string
Verify a file's checksum matches expected value.
Parameters:
path: File pathchecksum: Expected checksum hex stringalgorithm: Hash algorithm used
Returns: Boolean verification result
Analyze disk usage and identify large files/directories.
Parameters:
path: Directory to analyzedepth: Maximum depth to traversegroupByType: Boolean - group results by file extension
Returns: Usage report with sizes, largest files, and type breakdown
Recursively copy a directory with options.
Parameters:
source: Source directorydestination: Destination directorypreserveMetadata: Boolean - preserve timestamps and permissionsexclusions: Array of glob patterns to exclude
Returns: Copy statistics (files copied, bytes transferred, duration)
Sync directories by copying only newer or missing files.
Parameters:
source: Source directorydestination: Destination directoryexclusions: Array of glob patterns to exclude
Returns: Sync statistics (files copied, files skipped, bytes transferred)
- workspaceRoot: Absolute path to workspace directory (REQUIRED)
- All operations are confined to this directory
- Cannot be changed after server starts
-
allowedSubdirectories: Array of subdirectories within workspace (optional)
- If specified, operations are further restricted to these paths
- Example:
["src", "tests", "docs"]
-
blockedPaths: Array of paths to block (relative to workspace)
- Example:
[".git", ".env", "node_modules", ".ssh"]
- Example:
-
blockedPatterns: Array of regex patterns to block
- Example:
["*.key", "*.pem", "*.env", "*secret*", "*password*"]
- Example:
- maxFileSize: Maximum file size in bytes (default: 100MB)
- maxBatchSize: Maximum total size for batch operations (default: 1GB)
- maxOperationsPerMinute: Rate limit per agent (default: 100)
- enableAuditLog: Enable operation logging (default: true)
- requireConfirmation: Require confirmation for destructive operations (default: true)
- readOnly: Enable read-only mode (default: false)
The server implements 10 layers of path validation:
- Absolute Path Resolution: Prevents relative path tricks
- Workspace Boundary Check: Ensures path is within workspace
- Path Traversal Detection: Blocks
..and./sequences - System Path Blocklist: Hardcoded system directories (cannot be overridden)
- Sensitive Pattern Blocklist: Hardcoded sensitive files (cannot be overridden)
- Subdirectory Restrictions: Optional allowlist within workspace
- User Blocklist: Custom blocked paths
- User Pattern Blocklist: Custom blocked patterns
- Read-Only Mode: Prevents write/delete operations
- Symlink Validation: Validates symlink targets are within workspace
System Paths (Always Blocked):
/etc,/sys,/proc,/dev,/boot,/rootC:\Windows,C:\Program Files/System,/Library,/Applications(macOS)/bin,/sbin,/usr/bin,/usr/sbin
Sensitive Patterns (Always Blocked):
.ssh/,.aws/,.kube/id_rsa,*.pem,*.key,*.p12,*.pfx- Files containing:
password,secret,token .envfiles
All operations are logged with:
- Timestamp
- Operation type
- Paths involved
- Result (success/failure)
- Security violations logged separately
// Copy multiple files atomically
const result = await mcpClient.callTool("fs_batch_operations", {
operations: [
{ type: "copy", source: "src/file1.ts", destination: "backup/file1.ts" },
{ type: "copy", source: "src/file2.ts", destination: "backup/file2.ts" },
{ type: "copy", source: "src/file3.ts", destination: "backup/file3.ts" },
],
atomic: true, // All succeed or all rollback
});// Start watching
const watchResult = await mcpClient.callTool("fs_watch_directory", {
path: "src",
recursive: true,
filters: ["*.ts", "*.tsx"],
});
const sessionId = watchResult.sessionId;
// Later, get events
const events = await mcpClient.callTool("fs_get_watch_events", {
sessionId,
});
// Stop watching
await mcpClient.callTool("fs_stop_watch", { sessionId });// Build index first
await mcpClient.callTool("fs_build_index", {
path: "src",
includeContent: true,
});
// Fast search using index
const results = await mcpClient.callTool("fs_search_files", {
query: "TODO",
searchType: "content",
fileTypes: [".ts", ".js"],
useIndex: true,
});// Compute checksum
const checksumResult = await mcpClient.callTool("fs_compute_checksum", {
path: "important-file.zip",
algorithm: "sha256",
});
// Later, verify integrity
const verifyResult = await mcpClient.callTool("fs_verify_checksum", {
path: "important-file.zip",
checksum: checksumResult.checksum,
algorithm: "sha256",
});// Sync only newer/missing files
const syncResult = await mcpClient.callTool("fs_sync_directory", {
source: "src",
destination: "backup",
exclusions: ["*.test.ts", "node_modules/**"],
});
console.log(
`Copied: ${syncResult.filesCopied}, Skipped: ${syncResult.filesSkipped}`
);Cause: Attempting to access files outside the configured workspace root.
Solution:
- Verify your
workspaceRootconfiguration is correct - Ensure all paths are relative to the workspace root
- Check for
..sequences in paths
Cause: Attempting to access hardcoded system paths.
Solution: These paths are always blocked for security. Configure your workspace to avoid system directories.
Cause: Attempting to access files matching sensitive patterns (.ssh/, *.key, etc.).
Solution: These patterns are always blocked. If you need to access these files, they must be renamed or moved outside sensitive patterns.
Cause: Too many operations in a short time period.
Solution:
- Increase
maxOperationsPerMinutein configuration - Batch operations together using
fs_batch_operations - Add delays between operations
Cause: File size exceeds maxFileSize configuration.
Solution: Increase maxFileSize in configuration or split large files.
Cause: Events may be filtered or watch session not active.
Solution:
- Verify watch session is active with correct
sessionId - Check
filtersparameter - ensure patterns match your files - Ensure files are within watched directory (check
recursivesetting)
Cause: Index may be outdated or search parameters too restrictive.
Solution:
- Rebuild index with
fs_build_index - Check
fileTypesfilter isn't excluding your files - Verify
querymatches file content/names - Try with
useIndex: falsefor filesystem search
Cause: Symlink target is outside workspace.
Solution: All symlink targets must be within the workspace root. This is a security requirement and cannot be disabled.
- Use Indexing for Large Codebases: Build an index with
fs_build_indexfor faster searches - Batch Operations: Use
fs_batch_operationsinstead of individual operations - Filter Watch Events: Use specific glob patterns to reduce event volume
- Limit Search Scope: Use
fileTypesand size filters to narrow search results - Incremental Sync: Use
fs_sync_directoryinstead of full copy when possible
git clone https://github.com/Digital-Defiance/ai-capabilities-suite.git
cd ai-capabilities-suite/packages/mcp-filesystem
yarn install
yarn buildyarn test # Run all tests
yarn test:coverage # Run with coverage
yarn test:watch # Watch modeyarn build
node dist/cli.js --config ./config.jsonContributions are welcome! Please see CONTRIBUTING.md in the root repository.
MIT License - see LICENSE for details.
- Issues: GitHub Issues
- Email: info@digitaldefiance.org
- Documentation: Full Documentation
- MCP ACS Debugger - Debug Node.js applications via MCP
- MCP ACS Process - Process management via MCP
- MCP ACS Screenshot - Screenshot capture via MCP
Built with:
- Model Context Protocol SDK
- Chokidar - File watching
- Lunr - Full-text search
- fast-glob - Fast file pattern matching