Filesystem MCP server

Read, write, and manipulate local files through a controlled API.
Back to servers
Setup instructions
Provider
Mark III Labs
Release date
Nov 28, 2024
Language
Go
Stats
442 stars

The MCP Filesystem Server provides secure access to your local file system through the Model Context Protocol (MCP). It allows you to perform various operations on files and directories from applications that support MCP, with built-in security features to prevent unauthorized access.

Installation

Using Go Install

The simplest way to install the MCP Filesystem Server is using Go's install command:

go install github.com/mark3labs/mcp-filesystem-server@latest

Using Docker

You can also run the server using Docker:

docker run -i --rm ghcr.io/mark3labs/mcp-filesystem-server:latest /path/to/allowed/directory

Usage

Running as a Standalone Server

Start the MCP server with one or more allowed directories:

mcp-filesystem-server /path/to/allowed/directory [/another/allowed/directory ...]

The server will only provide access to the directories you specify, preventing access to other parts of your file system.

Using as a Library in Go Projects

You can integrate the server into your Go applications:

package main

import (
	"log"
	"os"

	"github.com/mark3labs/mcp-filesystem-server/filesystemserver"
)

func main() {
	// Create a new filesystem server with allowed directories
	allowedDirs := []string{"/path/to/allowed/directory", "/another/allowed/directory"}
	fs, err := filesystemserver.NewFilesystemServer(allowedDirs)
	if err != nil {
		log.Fatalf("Failed to create server: %v", err)
	}

	// Serve requests
	if err := fs.Serve(); err != nil {
		log.Fatalf("Server error: %v", err)
	}
}

Integration with MCP-Supporting Applications

To use this server with applications that support the Model Context Protocol:

{
  "mcpServers": {
    "filesystem": {
      "command": "mcp-filesystem-server",
      "args": ["/path/to/allowed/directory", "/another/allowed/directory"]
    }
  }
}

Docker Integration with MCP

When using Docker with MCP-supporting applications:

{
  "mcpServers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "ghcr.io/mark3labs/mcp-filesystem-server:latest",
        "/path/to/allowed/directory"
      ]
    }
  }
}

To allow the Docker container to access and modify files on your host system:

{
  "mcpServers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--volume=/allowed/directory/in/host:/allowed/directory/in/container",
        "ghcr.io/mark3labs/mcp-filesystem-server:latest",
        "/allowed/directory/in/container"
      ]
    }
  }
}

Available Operations

File Operations

  • read_file: Read a file's contents

    • Parameters: path (required): Path to the file
  • read_multiple_files: Read multiple files at once

    • Parameters: paths (required): List of file paths
  • write_file: Create or overwrite a file

    • Parameters: path (required), content (required)
  • copy_file: Copy files or directories

    • Parameters: source (required), destination (required)
  • move_file: Move or rename files or directories

    • Parameters: source (required), destination (required)
  • delete_file: Delete a file or directory

    • Parameters: path (required), recursive (optional, default: false)
  • modify_file: Update file contents by finding and replacing text

    • Parameters: path (required), find (required), replace (required), all_occurrences (optional, default: true), regex (optional, default: false)

Directory Operations

  • list_directory: Get contents of a directory

    • Parameters: path (required)
  • create_directory: Create a new directory

    • Parameters: path (required)
  • tree: Get a hierarchical representation of a directory structure

    • Parameters: path (required), depth (optional, default: 3), follow_symlinks (optional, default: false)

Search and Information

  • search_files: Find files matching a pattern

    • Parameters: path (required), pattern (required)
  • search_within_files: Search for text within file contents

    • Parameters: path (required), substring (required), depth (optional), max_results (optional, default: 1000)
  • get_file_info: Get metadata about a file or directory

    • Parameters: path (required)
  • list_allowed_directories: Show directories the server can access

    • Parameters: None

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":"mcp-filesystem-server","args":["/path/to/allowed/directory","/another/allowed/directory"]}'

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": "mcp-filesystem-server",
            "args": [
                "/path/to/allowed/directory",
                "/another/allowed/directory"
            ]
        }
    }
}

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": "mcp-filesystem-server",
            "args": [
                "/path/to/allowed/directory",
                "/another/allowed/directory"
            ]
        }
    }
}

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