Filesystem MCP server

Provides a secure interface for interacting with local filesystems, enabling file reading, writing, updating, and directory management with robust path resolution and security measures.
Back to servers
Setup instructions
Provider
cyanheads
Release date
Apr 13, 2025
Language
TypeScript
Package
Stats
1.6K downloads
15 stars

The Filesystem MCP Server provides a secure interface for AI agents to interact with the local filesystem through the Model Context Protocol (MCP). It supports both STDIO and HTTP transport options, allowing AI agents to read, write, manage files and directories, and perform targeted file updates with robust security measures.

Installation

To get started with the Filesystem MCP Server:

  1. Clone the repository:

    git clone https://github.com/cyanheads/filesystem-mcp-server.git
    cd filesystem-mcp-server
    
  2. Install dependencies:

    npm install
    
  3. Build the project:

    npm run build
    

Configuration

The server can be configured using environment variables (you can use a .env file):

Core Settings

  • MCP_LOG_LEVEL (Optional): Set logging level (debug, info, warn, error). Default: debug
  • LOGS_DIR (Optional): Directory for log files. Default: ./logs
  • NODE_ENV (Optional): Runtime environment. Default: development

Transport Configuration

  • MCP_TRANSPORT_TYPE (Optional): Choose stdio or http. Default: stdio

HTTP Transport Options

  • MCP_HTTP_PORT (Optional): HTTP server port. Default: 3010
  • MCP_HTTP_HOST (Optional): HTTP server host. Default: 127.0.0.1
  • MCP_ALLOWED_ORIGINS (Optional): Comma-separated CORS origins
  • MCP_AUTH_SECRET_KEY (Required for HTTP): JWT authentication secret key (32+ characters)

Security Settings

  • FS_BASE_DIRECTORY (Optional but recommended): Root directory for all filesystem operations, restricting access to only this directory and its subdirectories

Usage

Starting the Server

Start the server from your terminal:

node dist/index.js
# Or from project root:
npm start

Configuring MCP Clients

For STDIO Transport (Default)

Configure your MCP client with:

  • Command: node
  • Arguments: The absolute path to the server executable (e.g., /path/to/filesystem-mcp-server/dist/index.js)

Example configuration:

{
  "mcpServers": {
    "filesystem_stdio": {
      "command": "node",
      "args": ["/path/to/filesystem-mcp-server/dist/index.js"],
      "env": {
        "MCP_LOG_LEVEL": "debug"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

For HTTP Transport

Configure your client with the server URL (e.g., http://localhost:3010) and authentication method (JWT Bearer token if using MCP_AUTH_SECRET_KEY).

Available Tools

The server provides these filesystem interaction tools:

Session Management

  • set_filesystem_default: Sets a default path for the session, making relative paths work from this location

File Operations

  • read_file: Reads the content of a file as UTF-8 text
  • write_file: Creates or overwrites a file with specified content
  • update_file: Performs targeted search-and-replace operations within files
  • delete_file: Permanently removes a specific file

Directory Operations

  • list_files: Lists files and directories, optionally recursively
  • create_directory: Creates a new directory (with parent directories if needed)
  • delete_directory: Removes a directory (with recursive option)
  • move_path: Moves or renames files or directories
  • copy_path: Copies files or directories (recursively by default)

Each tool accepts both absolute paths and relative paths (resolved against the default path if set).

Security Features

The server includes several security measures:

  • Path sanitization to prevent directory traversal attacks
  • JWT authentication for HTTP transport
  • Input validation using Zod
  • Optional base directory restriction to limit filesystem 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":"node","args":["/path/to/filesystem-mcp-server/dist/index.js"],"env":{"MCP_LOG_LEVEL":"debug"},"disabled":false,"autoApprove":[]}'

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": "node",
            "args": [
                "/path/to/filesystem-mcp-server/dist/index.js"
            ],
            "env": {
                "MCP_LOG_LEVEL": "debug"
            },
            "disabled": false,
            "autoApprove": []
        }
    }
}

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": "node",
            "args": [
                "/path/to/filesystem-mcp-server/dist/index.js"
            ],
            "env": {
                "MCP_LOG_LEVEL": "debug"
            },
            "disabled": false,
            "autoApprove": []
        }
    }
}

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