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
909.9K downloads
60.2K stars

The Filesystem MCP Server is a Node.js server implementing the Model Context Protocol for filesystem operations. It provides a secure way to perform file and directory operations within specified directories, offering both command-line and dynamic directory access control.

Installation

Using Docker

You can run the Filesystem MCP server using Docker:

docker run -i --rm \
  --mount type=bind,src=/Users/username/Desktop,dst=/projects/Desktop \
  --mount type=bind,src=/path/to/other/dir,dst=/projects/other/dir,ro \
  --mount type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt \
  mcp/filesystem \
  /projects

Note: All directories must be mounted to /projects. Adding the ro flag makes the directory read-only.

Using NPX

Alternatively, you can run it directly using NPX:

npx -y @modelcontextprotocol/server-filesystem /path/to/dir1 /path/to/dir2

Directory Access Control

The server uses a flexible directory access control system through two methods:

Command-line Arguments

Specify allowed directories when starting the server:

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

MCP Roots (Recommended)

This method enables runtime directory updates without server restart:

  1. The server starts with directories from command-line arguments (if provided)
  2. When a client connects, the server checks if it supports roots protocol
  3. If supported, the server requests roots from the client via roots/list
  4. The server replaces all allowed directories with the client's roots
  5. The client can send runtime updates using notifications/roots/list_changed

Note: The server requires at least ONE allowed directory to operate.

Integration with Tools

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",
        "mcp/filesystem",
        "/projects"
      ]
    }
  }
}

Or using NPX:

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

VS Code

For manual installation, add the following to your User Settings (JSON) file in VS Code:

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

Or using NPX:

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

Available Tools

File Operations

  • read_file: Read complete contents of a file

    • Input: path (string)
  • read_multiple_files: Read multiple files simultaneously

    • Input: paths (string[])
  • write_file: Create new file or overwrite existing

    • Inputs: path (string), content (string)
  • edit_file: Make selective edits with pattern matching

    • Inputs:
      • path (string): File to edit
      • edits (array): List of edit operations
        • oldText (string): Text to search for
        • newText (string): Text to replace with
      • dryRun (boolean): Preview changes without applying

Directory Operations

  • create_directory: Create new directory or ensure it exists

    • Input: path (string)
  • list_directory: List directory contents

    • Input: path (string)
  • move_file: Move or rename files and directories

    • Inputs: source (string), destination (string)
  • search_files: Recursively search for files/directories

    • Inputs:
      • path (string): Starting directory
      • pattern (string): Search pattern
      • excludePatterns (string[]): Exclude patterns
  • get_file_info: Get detailed file/directory metadata

    • Input: path (string)
  • list_allowed_directories: List all directories the server can access

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