Skip to main content
Glama
Filesystem MCP Server

Filesystem MCP Server

Filesystem MCP Server (v0.1)

A simple MCP server for filesystem operations with directory sandboxing and read-only mode support.

Early version (0.1) - not thoroughly tested/reviewed, use with caution

Quick Start

Install dependencies:

git clone <repo_url>
uv sync

Run the server:

# Normal mode - full filesystem access
uv run main.py /path/to/allowed/directory

# Read-only mode - no write operations  
uv run main.py --read-only /path/to/allowed/directory

Related MCP server: MCP File Server

Features

  • Directory sandboxing (operations restricted to allowed paths)

  • --read-only flag disables write operations

  • Gitignore support for searches

  • Human-readable error messages

Usage Examples

Normal Mode

uv run main.py ~/projects
# Provides: create_file, delete_file, move_file, edit_file, create_directory + read tools

Read-Only Mode

uv run main.py --read-only ~/projects
# Provides only: read_text_file, list_directory, search_files, grep, directory_tree

Multiple Directories

uv run main.py /home/user/docs /tmp/workspace
uv run main.py --read-only /var/log /etc/config

Available Tools

Read Operations (always available):

  • read_text_file - Read file contents

  • list_directory - List directory contents

  • directory_tree - JSON directory structure

  • search_files - Find files by pattern

  • grep - Search text in files

  • read_multiple_files - Bulk file reading

Write Operations (disabled in --read-only):

  • create_file - Create new files

  • delete_file - Delete files

  • move_file - Move/rename files

  • edit_file - Edit file contents

  • create_directory - Create directories

Dependencies

From pyproject.toml:

  • fastmcp>=2.11.2 - MCP framework

  • pathspec>=0.12.1 - Gitignore patterns

Security Notes

  • All paths resolved with Path.resolve() to prevent traversal

  • Operations restricted to allowed directories only

  • Binary files rejected for text operations

Available Tools

12 tools
create_directoryA

Create a directory, including any necessary parent directories.

Args: path (str): Directory path to create (absolute or relative to allowed directories)

Returns: str: Success message with created directory path, or error message if failed

Note: - Path must be within allowed directory roots - Creates parent directories if they don't exist - No error if directory already exists

Inputs: path (required). Returns: result

create_fileA

Create a new file with specified content.

Args: path (str): File path to create (absolute or relative to allowed directories) content (str): UTF-8 text content to write to the file

Returns: str: Success message with created file path, or error message if failed

Note: - Fails if the file already exists - Creates parent directories if they don't exist - Path must be within allowed directory roots

Inputs: path (required), content (required). Returns: result

delete_fileA

Delete a file from the filesystem.

Args: path (str): File path to delete (absolute or relative to allowed directories)

Returns: str: Success message with deleted file path, or error message if failed

Note: - Path must be within allowed directory roots - Fails if file doesn't exist or cannot be deleted

Inputs: path (required). Returns: result

directory_treeA

Generate a plain text tree structure of a directory.

Args: path (str): Directory path to generate tree for (absolute or relative to allowed directories)

Returns: str: Plain text representation of directory tree, or error message if failed

Inputs: path (required). Returns: result

edit_fileA

Apply multiple text replacements to a file and return a unified diff.

Args: path (str): File path to edit (absolute or relative to allowed directories) edits (List[Dict[str, str]]): List of edit operations, each with 'oldText' and 'newText' keys

Returns: str: Unified diff showing changes made, or error message if failed

Note: - Path must be within allowed directory roots - File must be a UTF-8 text file - Edits are applied sequentially in the order provided - Each 'oldText' must match exactly (first occurrence is replaced) - Returns unified diff format showing before/after changes - File is atomically updated using temporary file - If no changes made, returns 'No changes made.'

Inputs: path (required), edits (required). Returns: result

grepA

Search for text patterns inside files using regular expressions.

Args: dir (str): Directory to search in (absolute or relative to allowed directories) pattern (str): Regular expression pattern to search for in file contents exclude (str, optional): File pattern to exclude from search

Returns: str: Newline-separated matches in format 'path:lineNo: line', or error message if failed

Note: - Directory must be within allowed directory roots - Searches recursively through subdirectories - Only searches UTF-8 text files - Respects .gitignore files and skips common lock files - Each match shows file path, line number, and the matching line - Uses Python regular expression syntax

Inputs: dir (required), pattern (required), exclude. Returns: result

list_allowed_directoriesA

List all allowed directory roots for filesystem operations.

Returns: List[str]: Absolute paths of directories the server can read/write

Inputs: no named parameters. Returns: result

list_directoryA

List the contents of a directory with type annotations.

Args: path (str): Directory path to list (absolute or relative to allowed directories)

Returns: str: Newline-separated list of entries with '[DIR]' or '[FILE]' prefixes, or error message if failed

Note: - Path must be within allowed directory roots - Fails if path is not a directory - Entries are sorted alphabetically - Format: '[DIR] dirname' or '[FILE] filename'

Inputs: path (required). Returns: result

move_fileA

Move or rename a file from source to destination.

Args: src (str): Source file path (absolute or relative to allowed directories) dst (str): Destination file path (absolute or relative to allowed directories)

Returns: str: Success message with source and destination paths, or error message if failed

Note: - Both paths must be within allowed directory roots - Fails if destination already exists - Creates parent directories for destination if needed

Inputs: src (required), dst (required). Returns: result

read_multiple_filesA

Read multiple UTF-8 text files at once and return a mapping of paths to contents.

Args: paths (List[str]): List of file paths to read (absolute or relative to allowed directories)

Returns: Dict[str, str] | str: Dictionary mapping absolute file paths to their contents, or error message if any file fails

Note: - All paths must be within allowed directory roots - All files must be UTF-8 text files - If any file fails to read, entire operation returns error string - Returns dictionary for successful reads, string for errors

Inputs: paths (required). Returns: result

read_text_fileA

Read the contents of a UTF-8 text file, optionally within a line range.

Args: path (str): File path to read (absolute or relative to allowed directories) fromLine (int, optional): Starting line number (1-indexed, inclusive) toLine (int, optional): Ending line number (1-indexed, inclusive)

Returns: str: File contents as text, or error message if failed

Note: - Path must be within allowed directory roots - Only reads UTF-8 text files (binary files will return error) - If line range specified, returns only those lines - Line numbers are 1-indexed

Inputs: path (required), fromLine, toLine. Returns: result

search_filesA

Search for files by name pattern in a directory recursively.

Args: dir (str): Directory to search in (absolute or relative to allowed directories) pattern (str): Glob-style pattern to match file names (e.g., '.py', 'test_') exclude (str, optional): Glob-style pattern to exclude file names

Returns: List[str] | str: List of matching absolute file paths, or error message if failed

Note: - Directory must be within allowed directory roots - Searches recursively through subdirectories - Respects .gitignore files, and ignores hidden files and folders - Returns list for successful searches, string for errors

Inputs: dir (required), pattern (required), exclude. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 12 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no significant overlap. For example, create_directory vs. create_file, read_text_file vs. read_multiple_files, and search_files vs. grep all target different operations. The descriptions clearly differentiate their specific functions, making tool selection unambiguous.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern with snake_case throughout, such as create_directory, list_directory, and read_text_file. This uniformity makes the tool set predictable and easy to navigate, with no deviations in naming conventions.

    Tool Count5/5

    With 12 tools, the server provides a well-scoped set for filesystem operations, covering creation, deletion, reading, editing, searching, and listing. Each tool serves a specific and necessary function without redundancy, making the count appropriate for the domain.

    Completeness5/5

    The tool set offers comprehensive coverage for filesystem management, including CRUD operations (create, read, edit, delete), navigation (list, tree), and advanced features (search, grep, move). There are no obvious gaps; agents can perform all typical filesystem tasks without dead ends.

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides secure file system operations for AI assistants including directory listing, file reading/writing, deletion, searching, and copying. Features safety controls like path validation, permission checks, and file size limits.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides secure, sandboxed filesystem operations including reading, writing, listing, searching, and managing files and directories within a configurable working directory with strict security controls.
      3
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides sandboxed access to local filesystem operations including directory and file management, content search with glob and regex patterns, and binary file support with configurable safety limits.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides safe filesystem access for AI clients with root confinement, read-only mode, and file operations like read, write, search, copy, move, delete.
      MIT