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
1.74M downloads
68.1K stars

The Filesystem MCP Server provides file system operations through the Model Context Protocol, allowing you to read, write, manipulate files and directories with strong access control mechanisms.

Installation

You can install and use the Filesystem MCP Server using either Docker or NPX.

Using Docker

For Claude Desktop, add this to your claude_desktop_config.json:

{
  "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

For Claude Desktop, add this to your claude_desktop_config.json:

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

Directory Access Control

The server provides flexible directory access control through two methods:

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.

Using with VS Code

You can configure the MCP server in VS Code using one of these methods:

User Configuration (Recommended)

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

Docker Configuration

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

NPX Configuration

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

Available Tools

File Operations

read_text_file

Reads a file as text with optional head/tail limits.

// Example: Read first 10 lines of a file
{
  "path": "/path/to/file.txt",
  "head": 10
}

read_media_file

Reads an image or audio file and returns base64 data with MIME type.

{
  "path": "/path/to/image.jpg"
}

write_file

Creates or overwrites a file.

{
  "path": "/path/to/file.txt",
  "content": "Hello, world!"
}

edit_file

Makes selective edits with pattern matching and formatting.

{
  "path": "/path/to/file.js",
  "edits": [
    {
      "oldText": "function hello() {",
      "newText": "function helloWorld() {"
    }
  ],
  "dryRun": true
}

Directory Operations

create_directory

Creates a new directory or ensures it exists.

{
  "path": "/path/to/new/directory"
}

list_directory

Lists directory contents with [FILE] or [DIR] prefixes.

{
  "path": "/path/to/directory"
}

list_directory_with_sizes

Lists directory contents with sizes and summary statistics.

{
  "path": "/path/to/directory",
  "sortBy": "size"
}

move_file

Moves or renames files and directories.

{
  "source": "/path/to/source",
  "destination": "/path/to/destination"
}

search_files

Recursively searches for files/directories matching patterns.

{
  "path": "/path/to/start",
  "pattern": "*.js",
  "excludePatterns": ["node_modules/**"]
}

directory_tree

Gets a recursive JSON tree structure of directory contents.

{
  "path": "/path/to/directory",
  "excludePatterns": ["node_modules/**", "*.log"]
}

get_file_info

Gets detailed file/directory metadata.

{
  "path": "/path/to/file.txt"
}

list_allowed_directories

Lists all directories the server is allowed to access.

{}

Advanced Usage

Reading Multiple Files

The read_multiple_files tool allows reading multiple files at once:

{
  "paths": [
    "/path/to/file1.txt",
    "/path/to/file2.txt"
  ]
}

File Editing with Preview

Always use dryRun: true first to preview changes:

{
  "path": "/path/to/file.js",
  "edits": [
    {
      "oldText": "const oldVariable",
      "newText": "const newVariable"
    }
  ],
  "dryRun": true
}

Then apply changes by setting dryRun: false or omitting it.

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