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.61M downloads
66.7K stars

The Filesystem MCP Server provides a Node.js implementation of the Model Context Protocol for filesystem operations, allowing AI assistants to read, write, and manipulate files and directories on your system through a secure, controlled interface.

Installation

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

Using Docker

To run the server with Docker, mount your directories to /projects inside the container:

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 \
  mcp/filesystem \
  /projects

The optional ro flag makes directories read-only.

Using NPX

You can run the server directly with NPX:

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

Directory Access Control

The server supports two methods for controlling which directories can be accessed:

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)

This method enables runtime directory updates without server restart. MCP clients can dynamically update the allowed directories through the Roots protocol.

How it works:

  1. Server starts with directories from command-line arguments (if provided)
  2. When a client connects, the server checks if it supports the roots protocol
  3. If supported, the server requests roots from the client and replaces all allowed directories
  4. The client can send notifications to update roots at any time

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

Integration with AI Assistants

Claude Desktop Integration

Add this configuration to your claude_desktop_config.json:

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/dir,dst=/projects/other/dir,ro",
        "mcp/filesystem",
        "/projects"
      ]
    }
  }
}

Using NPX:

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

VS Code Integration

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

Method 1: User Configuration (Recommended)
Open the Command Palette (Ctrl + Shift + P) and run MCP: Open User Configuration. Add the server configuration to your user mcp.json file.

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

Using Docker:

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

Using NPX:

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

Available Features

The server provides the following tools for file operations:

File Reading and Writing

  • read_text_file: Read a file as text with optional head/tail limits
  • read_media_file: Read image or audio files (returns base64 data)
  • read_multiple_files: Read multiple files simultaneously
  • write_file: Create or overwrite files
  • edit_file: Make selective edits with pattern matching and formatting

Directory Operations

  • create_directory: Create new directories
  • list_directory: List directory contents
  • list_directory_with_sizes: List with file sizes and statistics
  • directory_tree: Get recursive JSON tree structure
  • move_file: Move or rename files and directories
  • search_files: Find files/directories matching patterns
  • get_file_info: Get detailed file/directory metadata
  • list_allowed_directories: Show all accessible directories

Each tool accepts specific parameters and provides structured output to help AI assistants work with your filesystem in a controlled, predictable manner.

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