mcp-filesystem-server

command module
v0.0.0-...-2a90652 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 11 Imported by: 0

README

MCP Filesystem Server

This MCP server provides secure access to the local filesystem via the Model Context Protocol (MCP).

Components

Resources
  • file://
    • Name: File System
    • Description: Access to files and directories on the local file system
Tools
File Operations
  • read_file

    • Read the complete contents of a file from the file system
    • Parameters: path (required): Path to the file to read
  • read_multiple_files

    • Read the contents of multiple files in a single operation
    • Parameters: paths (required): List of file paths to read
  • write_file

    • Create a new file or overwrite an existing file with new content
    • Parameters: path (required): Path where to write the file, content (required): Content to write to the file
  • copy_file

    • Copy files and directories
    • Parameters: source (required): Source path of the file or directory, destination (required): Destination path
  • move_file

    • Move or rename files and directories
    • Parameters: source (required): Source path of the file or directory, destination (required): Destination path
  • delete_file

    • Delete a file or directory from the file system
    • Parameters: path (required): Path to the file or directory to delete, recursive (optional): Whether to recursively delete directories (default: false)
  • modify_file

    • Update file by finding and replacing text using string matching or regex
    • Parameters: path (required): Path to the file to modify, find (required): Text to search for, replace (required): Text to replace with, all_occurrences (optional): Replace all occurrences (default: true), regex (optional): Treat find pattern as regex (default: false)
Directory Operations
  • list_directory

    • Get a detailed listing of all files and directories in a specified path
    • Parameters: path (required): Path of the directory to list
  • create_directory

    • Create a new directory or ensure a directory exists
    • Parameters: path (required): Path of the directory to create
  • tree

    • Returns a hierarchical JSON representation of a directory structure
    • Parameters: path (required): Path of the directory to traverse, depth (optional): Maximum depth to traverse (default: 3), follow_symlinks (optional): Whether to follow symbolic links (default: false)
Search and Information
  • search_files

    • Recursively search for files and directories matching a pattern
    • Parameters: path (required): Starting path for the search, pattern (required): Search pattern to match against file names
  • search_within_files

    • Search for text within file contents across directory trees
    • Parameters: path (required): Starting directory for the search, substring (required): Text to search for within file contents, depth (optional): Maximum directory depth to search, max_results (optional): Maximum number of results to return (default: 1000)
  • get_file_info

    • Retrieve detailed metadata about a file or directory
    • Parameters: path (required): Path to the file or directory
  • list_allowed_directories

    • Returns the list of directories that this server is allowed to access
    • Parameters: None

Features

  • Secure access to specified directories
  • Path validation to prevent directory traversal attacks
  • Symlink resolution with security checks
  • MIME type detection
  • Support for text, binary, and image files
  • Size limits for inline content and base64 encoding

Getting Started

Installation
Using Go Install
go install github.com/bobmcallan/mcp-filesystem-server@latest
Configuration

Create a config.toml file in the same directory as the executable:

# MCP Filesystem Server Configuration

[directories]
# List of directories that the server is allowed to access
allowed = [
    "/path/to/allowed/directory",
    "/another/allowed/directory"
]

[logging]
# Log level: debug, info, warn, error
level = "info"
# Log format: json, text
format = "json"
# Log output: file, stderr  
output = "file"
# Log file path (relative to executable directory)
file_path = "mcp-filesystem-server.log"
Usage
As a standalone server

Start the MCP server (directories are configured in config.toml):

mcp-filesystem-server
As a library in your Go project
package main

import (
	"log"
	"os"

	"github.com/bobmcallan/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)
	}
}
Usage with Model Context Protocol

To integrate this server with apps that support MCP:

{
  "mcpServers": {
    "filesystem": {
      "command": "mcp-filesystem-server",
      "args": []
    }
  }
}

Note: Allowed directories are now configured in config.toml instead of command line arguments.

Usage with Warp Terminal

For Warp terminal integration, use the provided configuration:

{
  "mcpServers": {
    "filesystem": {
      "command": "mcp-filesystem-server",
      "args": [],
      "env": {},
      "description": "Secure filesystem operations via MCP"
    }
  }
}

This configuration allows Warp to use the filesystem server for secure file operations. Configure allowed directories in config.toml.

Docker
Running with Docker

You can run the Filesystem MCP server using Docker (mount config.toml):

docker run -i --rm -v /path/to/config.toml:/app/config.toml ghcr.io/bobmcallan/mcp-filesystem-server:latest
Docker Configuration with MCP

To integrate the Docker image with apps that support MCP:

{
  "mcpServers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v", "/path/to/config.toml:/app/config.toml",
        "-v", "/host/directory:/container/directory",
        "ghcr.io/bobmcallan/mcp-filesystem-server:latest"
      ]
    }
  }
}

Note: Mount your config.toml file and any directories you want to access inside the container.

License

See the LICENSE file for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL