Filesystem MCP server

Read, write, and manipulate local files through a controlled API.
Back to servers
Setup instructions
Provider
Anthropic
Release date
Nov 19, 2024
Language
TypeScript
Package
Stats
3.78M downloads
74.8K stars

The Filesystem MCP Server implements the Model Context Protocol for filesystem operations, allowing AI assistants to read, write, and manipulate files and directories through a structured API. It provides secure access control via command-line arguments or dynamic directory access through the Roots protocol.

Installation

Using with Claude Desktop

You can add the MCP Filesystem server to your Claude Desktop configuration in two ways:

Using Docker

{
  "mcpServers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
        "--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
        "--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
        "mcp/filesystem",
        "/projects"
      ]
    }
  }
}

Using NPX

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

Using with VS Code

For manual installation in VS Code, you can configure the MCP server using one of these methods:

Method 1: User Configuration (Recommended) Add the configuration to your user-level MCP configuration file through the Command Palette (Ctrl + Shift + P) by running MCP: Open User Configuration.

Method 2: Workspace Configuration Add the configuration to a file called .vscode/mcp.json in your workspace.

Docker Configuration for VS Code

{
  "servers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--mount", "type=bind,src=${workspaceFolder},dst=/projects/workspace",
        "mcp/filesystem",
        "/projects"
      ]
    }
  }
}

NPX Configuration for VS Code

{
  "servers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "${workspaceFolder}"
      ]
    }
  }
}

Directory Access Control

The server provides two methods for controlling which directories it can access:

Method 1: Command-line Arguments

Specify allowed directories when starting the server:

mcp-server-filesystem /path/to/dir1 /path/to/dir2

Method 2: MCP Roots (Recommended)

MCP clients that support Roots can dynamically update the allowed directories. This is the recommended method as it enables runtime directory updates without server restart.

Access Control Workflow

  1. Server Startup

    • Starts with directories from command-line arguments if provided
    • Otherwise starts with empty allowed directories
  2. Client Connection & Initialization

    • Client connects and sends capabilities
    • Server checks if client supports roots protocol
  3. Roots Protocol Handling (if supported)

    • Server requests roots from client
    • Client responds with configured roots
    • Server replaces allowed directories with client's roots
    • Client can send runtime updates to change allowed directories
  4. Fallback Behavior

    • If client doesn't support roots, server uses only command-line directories
    • No dynamic updates possible
  5. Access Control

    • All filesystem operations are restricted to allowed directories
    • Server requires at least one allowed directory to operate

Available Tools

Read Operations

  • read_text_file: Read a file as text (optionally just the head or tail)
  • read_media_file: Read an image or audio file (returns base64 data with MIME type)
  • read_multiple_files: Read multiple files simultaneously
  • list_directory: List directory contents with [FILE] or [DIR] prefixes
  • list_directory_with_sizes: List directory contents with file sizes and summary statistics
  • directory_tree: Get recursive JSON tree structure of directory contents
  • search_files: Recursively search for files/directories that match patterns
  • get_file_info: Get detailed file/directory metadata
  • list_allowed_directories: List all directories the server can access

Write Operations

  • write_file: Create new file or overwrite existing
  • edit_file: Make selective edits using advanced pattern matching and formatting
  • create_directory: Create new directory or ensure it exists
  • move_file: Move or rename files and directories

Tool Annotations

The server provides MCP ToolAnnotations to help clients understand tool behavior:

  • readOnlyHint: Distinguishes read-only tools from write-capable ones
  • idempotentHint: Identifies operations that are safe to retry with the same arguments
  • destructiveHint: Highlights operations that may overwrite or heavily mutate data

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "filesystem" '{"command":"npx","args":["-y","@modelcontextprotocol/server-filesystem","${workspaceFolder}"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "filesystem": {
            "command": "npx",
            "args": [
                "-y",
                "@modelcontextprotocol/server-filesystem",
                "${workspaceFolder}"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "filesystem": {
            "command": "npx",
            "args": [
                "-y",
                "@modelcontextprotocol/server-filesystem",
                "${workspaceFolder}"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later