Secure Filesystem MCP server

Provides secure filesystem operations within specified directories, enabling safe reading, writing, editing, and searching of files for code analysis, document management, or automated file tasks.
Back to servers
Provider
Legaltime
Release date
Mar 04, 2025
Language
TypeScript

This MCP server implements the Model Context Protocol for filesystem operations, allowing you to perform various file system tasks through a standardized API. It provides secure access to files and directories by restricting operations to explicitly allowed locations.

Installation

You can run the Filesystem MCP Server using either Docker or NPX. Choose the method that works best for your environment.

Using Docker

  1. Pull and run the Docker image:
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: All directories must be mounted to /projects by default. The ro flag makes a directory read-only.

Using NPX

Install and run directly using NPX:

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

Configuration with Claude Desktop

To use this server with Claude Desktop, add the MCP server 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 Filesystem MCP Server provides the following tools for file operations:

File Operations

  • read_file: Read a file's contents
  • read_multiple_files: Read multiple files simultaneously
  • write_file: Create or overwrite a file
  • edit_file: Make selective edits to files with pattern matching

Directory Operations

  • create_directory: Create a new directory
  • list_directory: List contents of a directory
  • move_file: Move or rename files and directories
  • search_files: Search for files matching a pattern

Information Tools

  • get_file_info: Get detailed file metadata
  • list_allowed_directories: List directories the server can access

Usage Examples

Reading a File

// Read a file's contents
const fileContent = await resource.file.system.read_file({
  path: "/projects/Desktop/example.txt"
});

Writing to a File

// Create or overwrite a file
await resource.file.system.write_file({
  path: "/projects/Desktop/new-file.txt",
  content: "This is the content of the file."
});

Editing a File

// Edit a file with pattern matching
const editResult = await resource.file.system.edit_file({
  path: "/projects/Desktop/config.json",
  edits: [
    {
      oldText: '"debug": false',
      newText: '"debug": true'
    }
  ],
  dryRun: true // Preview changes first
});

// Apply the changes after review
if (editResult.changes) {
  await resource.file.system.edit_file({
    path: "/projects/Desktop/config.json",
    edits: [
      {
        oldText: '"debug": false',
        newText: '"debug": true'
      }
    ],
    dryRun: false
  });
}

Working with Directories

// Create a directory
await resource.file.system.create_directory({
  path: "/projects/Desktop/new-folder"
});

// List directory contents
const contents = await resource.file.system.list_directory({
  path: "/projects/Desktop"
});

// Search for files
const results = await resource.file.system.search_files({
  path: "/projects/Desktop",
  pattern: "*.json",
  excludePatterns: ["node_modules", ".git"]
});

Getting File Information

// Get file metadata
const fileInfo = await resource.file.system.get_file_info({
  path: "/projects/Desktop/example.txt"
});

Security Considerations

The server only allows operations within directories that are explicitly specified via the args parameter in your configuration. For maximum security, only mount directories that you need the server to access.

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