Filesystem MCP server

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

The Filesystem MCP Server provides functionality for filesystem operations through the Model Context Protocol. It allows you to perform common file and directory operations like reading, writing, creating, listing, moving, and searching files within specified directories.

Installation

You can use the Filesystem MCP Server either via Docker or directly with NPX. Both methods require you to specify which directories the server is allowed to access.

Docker Installation

The Docker method requires mounting directories to /projects within the container:

docker 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

Note that adding the ro flag makes a directory read-only.

NPX Installation

Alternatively, use NPX to run the server directly:

npx -y @modelcontextprotocol/server-filesystem \
  /Users/username/Desktop \
  /path/to/other/allowed/dir

Configuration with Claude Desktop

To use the Filesystem MCP Server with Claude Desktop, add the configuration to your claude_desktop_config.json file.

Docker Configuration

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

NPX Configuration

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

Available Tools

The server exposes several filesystem operations through the file://system resource:

File Operations

  • read_file: Read complete contents of a file

    {"path": "/path/to/file.txt"}
    
  • read_multiple_files: Read multiple files simultaneously

    {"paths": ["/path/to/file1.txt", "/path/to/file2.txt"]}
    
  • write_file: Create new file or overwrite existing

    {
      "path": "/path/to/file.txt",
      "content": "New file content"
    }
    
  • edit_file: Make selective edits using pattern matching

    {
      "path": "/path/to/file.txt",
      "edits": [
        {
          "oldText": "text to replace",
          "newText": "replacement text"
        }
      ],
      "dryRun": true
    }
    

Directory Operations

  • create_directory: Create new directory

    {"path": "/path/to/new/directory"}
    
  • list_directory: List directory contents

    {"path": "/path/to/directory"}
    
  • move_file: Move or rename files and directories

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

Search and Information

  • search_files: Recursively search for files/directories

    {
      "path": "/path/to/search",
      "pattern": "*.txt",
      "excludePatterns": ["node_modules/**"]
    }
    
  • get_file_info: Get detailed file/directory metadata

    {"path": "/path/to/file.txt"}
    
  • list_allowed_directories: List all directories the server can access

    {}
    

Security Note

The server only allows operations within directories explicitly specified through the args parameter during initialization. Be cautious when using tools like write_file and move_file as they can overwrite existing content.

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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