Filesystem MCP Server

Filesystem MCP servers enable AI models to interact with local file systems, providing capabilities for file operations, directory management, and secure file access within specified boundaries.

GitHub starsnpm versionnpm downloads

Overview

The MCP Filesystem Server enables AI models to safely interact with local file systems through the Model Context Protocol. It provides controlled access to read, write, and manage files within specified directories, making it essential for AI-powered file management and code editing tasks.

Official Server:

Developed and maintained by Anthropic

Key Features

📁

File Operations

Read, write, and edit files with UTF-8 encoding support

🗂️

Directory Management

Create, list, and navigate directory structures

🔍

Search & Metadata

Search files recursively and retrieve detailed file metadata

🔒

Secure Boundaries

Operations restricted to specified allowed directories only

Available Tools

Quick Reference

ToolPurposeCategory
read_fileRead complete file contentsRead
read_multiple_filesRead multiple files at onceRead
write_fileCreate or overwrite fileWrite
edit_fileMake selective edits to fileWrite
create_directoryCreate new directoryDirectory
list_directoryList directory contentsDirectory
move_fileMove or rename filesFile Ops
search_filesSearch for files recursivelySearch
get_file_infoGet file metadataMetadata
list_allowed_directoriesList accessible directoriesInfo

Detailed Usage

read_file

Read complete file contents with UTF-8 encoding.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "read_file",
  arguments: {
    path: "/path/to/file.txt"
  }
});

Returns full file contents as string.

read_multiple_files

Read multiple files simultaneously for efficiency.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "read_multiple_files",
  arguments: {
    paths: [
      "/path/to/file1.txt",
      "/path/to/file2.js",
      "/path/to/file3.md"
    ]
  }
});

Returns array of file contents.

write_file

Create new file or overwrite existing file with content.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "write_file",
  arguments: {
    path: "/path/to/output.txt",
    content: "Hello, World!\nThis is a new file."
  }
});

Exercise caution - overwrites existing files without warning.

edit_file

Make selective edits using pattern matching with indentation preservation.

// Preview changes first (dry run)
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "edit_file",
  arguments: {
    path: "/path/to/code.js",
    edits: [
      {
        oldText: "const foo = 'bar';",
        newText: "const foo = 'baz';"
      }
    ],
    dryRun: true
  }
});

// Apply edits
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "edit_file",
  arguments: {
    path: "/path/to/code.js",
    edits: [
      {
        oldText: "const foo = 'bar';",
        newText: "const foo = 'baz';"
      }
    ],
    dryRun: false
  }
});

Always use dryRun: true first to preview changes.

create_directory

Create new directory with automatic parent directory creation.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "create_directory",
  arguments: {
    path: "/path/to/new/nested/directory"
  }
});

Succeeds silently if directory already exists.

list_directory

List directory contents with file/directory type indicators.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "list_directory",
  arguments: {
    path: "/path/to/directory"
  }
});

Returns items prefixed with [FILE] or [DIR].

move_file

Move or rename files and directories.

// Rename file
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "move_file",
  arguments: {
    source: "/path/to/old-name.txt",
    destination: "/path/to/new-name.txt"
  }
});

// Move to different directory
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "move_file",
  arguments: {
    source: "/path/to/file.txt",
    destination: "/new/path/file.txt"
  }
});

Fails if destination already exists.

search_files

Recursively search for files and directories by pattern.

// Search for JavaScript files
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "search_files",
  arguments: {
    path: "/path/to/project",
    pattern: "*.js"
  }
});

// Search with exclusions
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "search_files",
  arguments: {
    path: "/path/to/project",
    pattern: "*.ts",
    excludePatterns: ["node_modules/**", "dist/**", "*.test.ts"]
  }
});

Supports glob patterns for matching and exclusion.

get_file_info

Get detailed metadata for files or directories.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "get_file_info",
  arguments: {
    path: "/path/to/file.txt"
  }
});

Returns size, timestamps, type, and permissions.

list_allowed_directories

List all directories the server is allowed to access.

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "list_allowed_directories",
  arguments: {}
});

Returns configured allowed directory paths.

Installation

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/username/Desktop",
        "/path/to/other/allowed/dir"
      ]
    }
  }
}

Security:

Only directories listed in args will be accessible. Operations outside these paths will be blocked.

Common Use Cases

Code Editing

Make surgical edits to source files:

use_mcp_tool({
  server_name: "filesystem",
  tool_name: "edit_file",
  arguments: {
    path: "/project/src/config.js",
    edits: [
      {
        oldText: "API_URL = 'http://localhost:3000'",
        newText: "API_URL = 'https://api.production.com'"
      }
    ],
    dryRun: true  // Preview first
  }
});

Project Exploration

Search and analyze project structure:

// Find all TypeScript files
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "search_files",
  arguments: {
    path: "/project",
    pattern: "*.ts",
    excludePatterns: ["node_modules/**", "dist/**"]
  }
});

// Read configuration files
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "read_multiple_files",
  arguments: {
    paths: [
      "/project/package.json",
      "/project/tsconfig.json",
      "/project/.env"
    ]
  }
});

File Organization

Organize and structure files:

// Create directory structure
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "create_directory",
  arguments: {
    path: "/project/src/components/ui"
  }
});

// Move files to new structure
use_mcp_tool({
  server_name: "filesystem",
  tool_name: "move_file",
  arguments: {
    source: "/project/Button.tsx",
    destination: "/project/src/components/ui/Button.tsx"
  }
});

Security Model

The filesystem server implements strict security boundaries:

  1. Allowed Directories: Only paths specified in server args are accessible
  2. Path Validation: All paths are validated to prevent directory traversal attacks
  3. No Deletion: Server does not provide file deletion capabilities
  4. Read-Only Mounts: Docker supports read-only directory mounting

Sources