The Filesystem module provides comprehensive file and directory operations with advanced features like snapshot management, permission handling, and real-time monitoring. Built with safety and reliability in mind, it's perfect for managing codebases, configuration files, and data storage.
The Filesystem module includes 13 powerful tools for complete file system control:
Read file contents, optionally reading specific line ranges.
Parameters:
path (string, required) - Absolute or relative path to the filelines (array, optional) - Array of line ranges to read, e.g. [[1,10], [15,20]] reads lines 1-10 and 15-20Example - Read Entire File:
{
"name": "fs_read",
"arguments": {
"path": "/etc/hosts"
}
}
Example - Read Specific Lines:
{
"name": "fs_read",
"arguments": {
"path": "/var/log/app.log",
"lines": [[1, 10], [50, 60]]
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": "Line 1\nLine 2\n...\nLine 10\nLine 50\n...\nLine 60",
"size": 150,
"path": "/var/log/app.log"
}
}
Use Cases:
Notes:
[1,5] includes lines 1, 2, 3, 4, 5lines parameter, reads entire fileWrite content to files, optionally replacing specific line ranges.
Parameters:
path (string, required) - Target file pathcontent (string, required) - Content to writelines (array, optional) - Array of line ranges to replace, e.g. [[1,10], [15,20]]. Content is split and distributed across ranges.Example - Write Entire File:
{
"name": "fs_write",
"arguments": {
"path": "/tmp/config.json",
"content": "{\"api_key\": \"secret\"}"
}
}
Example - Replace Specific Lines:
{
"name": "fs_write",
"arguments": {
"path": "/tmp/script.sh",
"content": "# Updated header\n# Version 2.0",
"lines": [[1, 2]]
}
}
Example - Replace Multiple Ranges:
{
"name": "fs_write",
"arguments": {
"path": "/etc/config.conf",
"content": "new_setting=1\nother_setting=2\nfooter_line=end",
"lines": [[5, 6], [20, 20]]
}
}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"success": true,
"path": "/tmp/config.json",
"bytes_written": 24
}
}
Best Practices:
lines parameter for surgical edits to large filesNotes:
[3,5] replaces lines 3, 4, 5lines parameter, overwrites entire filelines, existing file content is preserved except for specified rangesMove files or directories to a new location.
Parameters:
source (string, required) - Source pathdestination (string, required) - Destination pathoverwrite (boolean, optional) - Overwrite if destination exists (default: false)Example:
{
"name": "fs_move",
"arguments": {
"source": "/tmp/old_name.txt",
"destination": "/tmp/new_name.txt",
"overwrite": false
}
}
Important:
overwrite: true carefully to avoid data lossCopy files or directories recursively.
Parameters:
source (string, required) - Source pathdestination (string, required) - Destination pathrecursive (boolean, optional) - Copy directories recursively (default: true)preserve_permissions (boolean, optional) - Preserve file permissions (default: true)Example:
{
"name": "fs_copy",
"arguments": {
"source": "/home/user/project",
"destination": "/backup/project",
"recursive": true,
"preserve_permissions": true
}
}
Use Cases:
Create new files or directories.
Parameters:
path (string, required) - Path to createtype (string, required) - "file" or "directory"parents (boolean, optional) - Create parent directories (default: false)Example - Create Directory:
{
"name": "fs_create",
"arguments": {
"path": "/tmp/my_project/src/components",
"type": "directory",
"parents": true
}
}
Example - Create File:
{
"name": "fs_create",
"arguments": {
"path": "/tmp/README.md",
"type": "file"
}
}
Notes:
parents: true to create intermediate directoriesDelete files or directories.
Parameters:
path (string, required) - Path to deleterecursive (boolean, optional) - Delete directories recursively (default: false)Example:
{
"name": "fs_delete",
"arguments": {
"path": "/tmp/old_project",
"recursive": true
}
}
⚠️ Warning:
recursive: true is required for non-empty directoriesCreate timestamped backups with automatic rotation.
Parameters:
path (string, required) - Path to snapshotmax_snapshots (number, optional) - Maximum snapshots to keep (default: 5)compression (boolean, optional) - Compress snapshot (default: false)Example:
{
"name": "fs_snapshot",
"arguments": {
"path": "/important/project",
"max_snapshots": 10,
"compression": true
}
}
Snapshot Format:
/important/project.snapshot.2024-01-20T15-30-45.tar.gz
Features:
Best Practices:
max_snapshots based on disk spaceSearch for files using glob patterns.
Parameters:
path (string, required) - Directory to searchpattern (string, required) - Glob pattern (e.g., ".ts", "**/.json")max_depth (number, optional) - Maximum directory depth (default: unlimited)case_sensitive (boolean, optional) - Case-sensitive matching (default: true)Example - Find TypeScript Files:
{
"name": "fs_find",
"arguments": {
"path": "./src",
"pattern": "**/*.{ts,tsx}",
"max_depth": 5
}
}
Example - Find Config Files:
{
"name": "fs_find",
"arguments": {
"path": ".",
"pattern": "*config.{json,yaml,toml}",
"case_sensitive": false
}
}
Pattern Syntax:
* - Match any characters except /** - Match any characters including / (recursive)? - Match single character[abc] - Match any character in brackets{js,ts} - Match either extensionDetailed directory listing (like ls -la).
Parameters:
path (string, required) - Directory pathshow_hidden (boolean, optional) - Include hidden files (default: true)sort_by (string, optional) - Sort by "name", "size", "modified" (default: "name")Example:
{
"name": "fs_ld",
"arguments": {
"path": "/home/user/project",
"show_hidden": true,
"sort_by": "modified"
}
}
Response:
{
"entries": [
{
"name": "src",
"type": "directory",
"size": 4096,
"permissions": "755",
"modified": "2024-01-20T15:30:45Z",
"owner": "user",
"group": "user"
},
{
"name": "README.md",
"type": "file",
"size": 2048,
"permissions": "644",
"modified": "2024-01-20T14:20:30Z"
}
]
}
Get detailed metadata for files or directories.
Parameters:
path (string, required) - Path to inspectExample:
{
"name": "fs_stat",
"arguments": {
"path": "/etc/passwd"
}
}
Response:
{
"type": "file",
"size": 2048,
"permissions": "644",
"owner": "root",
"group": "root",
"created": "2024-01-01T00:00:00Z",
"modified": "2024-01-20T15:30:45Z",
"accessed": "2024-01-20T16:00:00Z",
"is_symlink": false,
"is_readonly": false
}
Get or set Unix file permissions.
Parameters:
path (string, required) - File pathmode (string, optional) - Permissions in octal (e.g., "755", "644")recursive (boolean, optional) - Apply recursively to directories (default: false)Example - Get Permissions:
{
"name": "fs_permissions",
"arguments": {
"path": "/tmp/script.sh"
}
}
Example - Set Permissions:
{
"name": "fs_permissions",
"arguments": {
"path": "/tmp/script.sh",
"mode": "755"
}
}
Common Permission Modes:
755 - Owner: rwx, Group: r-x, Others: r-x (executable scripts)644 - Owner: rw-, Group: r--, Others: r-- (data files)600 - Owner: rw-, Group: ---, Others: --- (private files)777 - Full access for everyone (⚠️ use with caution)Monitor file or directory changes in real-time.
Parameters:
path (string, required) - Path to watchrecursive (boolean, optional) - Watch subdirectories (default: false)events (array, optional) - Event types to monitor: ["create", "modify", "delete", "rename"]Example:
{
"name": "fs_watch",
"arguments": {
"path": "./src",
"recursive": true,
"events": ["modify", "create", "delete"]
}
}
Events:
create - New file or directory createdmodify - File content changeddelete - File or directory removedrename - File or directory renamed/movedUse Cases:
Organize items within Desktop directory automatically.
Parameters:
action (string, required) - "organize_by_type" or "organize_by_date"dry_run (boolean, optional) - Preview changes without applying (default: false)Example:
{
"name": "fs_move_desktop",
"arguments": {
"action": "organize_by_type",
"dry_run": true
}
}
Organization Strategies:
By Type:
By Date:
Always use this pattern for safe file updates:
// 1. Create snapshot
{"name": "fs_snapshot", "arguments": {"path": "/config/app.conf"}}
// 2. Read current content
{"name": "fs_read", "arguments": {"path": "/config/app.conf"}}
// 3. Modify content (in memory)
// 4. Write new content
{"name": "fs_write", "arguments": {"path": "/config/app.conf", "content": "..."}}
// 5. Verify write
{"name": "fs_read", "arguments": {"path": "/config/app.conf"}}
Process multiple files efficiently:
// 1. Find all target files
{"name": "fs_find", "arguments": {"path": "./src", "pattern": "*.ts"}}
// 2. For each file:
// - Read content
// - Process
// - Write back
// 1. Create snapshot of parent directory
{"name": "fs_snapshot", "arguments": {"path": "/parent"}}
// 2. List contents to verify
{"name": "fs_ld", "arguments": {"path": "/parent/to_delete"}}
// 3. Delete if confirmed
{"name": "fs_delete", "arguments": {"path": "/parent/to_delete", "recursive": true}}
Common errors and solutions:
Error: Permission denied: /etc/secure_file
Solution: Run with appropriate permissions or modify file ownership
Error: No such file or directory: /missing/path
Solution: Verify path exists, check for typos, create parent directories
Error: No space left on device
Solution: Free up disk space, use compression, clean snapshots
Error: Invalid path: /path/with/../traversal
Solution: Use absolute paths, avoid path traversal
max_depth for fs_find to limit scopefs_ld instead of recursive fs_statsilent_resourcesmax_depth and patterns to limit operation scope