Skip to main content
Glama
Secure File System MCP Server

Secure File System MCP Server

by shishirsng

Secure File System MCP Server

A production-grade Model Context Protocol (MCP) server that exposes safe file system operations with comprehensive security guardrails.

Features

  • File Operations: read_file, write_file, list_dir, search_files

  • Path Traversal Protection: Blocks ../ attacks and symlink escapes

  • Allowlisted Root Directories: Only configured directories are accessible

  • File Size Limits: Configurable maximum file sizes for reads and writes

  • Proper MCP Error Codes: Returns -32602 (invalid params) and -32603 (internal error) instead of raw exceptions

  • Structured Logging: JSON-formatted logs with correlation IDs

  • Encoding Handling: Safe handling of text encodings with fallback

  • Comprehensive Tests: Unit tests with mocked FS + integration tests with MCP client

Related MCP server: Local Files MCP Server

Quick Start

Installation

pip install -e ".[dev]"

Configuration

Create a .env file or set environment variables:

SECURE_FS_ALLOWED_ROOTS=/path/to/dir1,/path/to/dir2
SECURE_FS_MAX_FILE_SIZE=10485760
SECURE_FS_DEFAULT_ENCODING=utf-8
SECURE_FS_LOG_LEVEL=INFO

Running the Server

python -m secure_fs_mcp.server

Running Tests

pytest
pytest --cov=secure_fs_mcp

Architecture

secure_fs_mcp/
├── __init__.py
├── server.py          # MCP server setup and tool registration
├── config.py          # Configuration management via env vars
├── fs_operations.py   # Core file system operations with safety rails
├── errors.py          # MCP error codes and custom exceptions
├── logging_config.py  # Structured logging setup
└── validators.py      # Input validation and path safety checks

MCP Tools

Tool

Description

read_file

Read file contents with encoding detection

write_file

Write content to a file (within allowed roots)

list_dir

List directory contents with metadata

search_files

Search for files by name pattern

Security

  • All paths are resolved to absolute paths and validated against allowlisted roots

  • Symlinks are resolved before validation to prevent symlink-based escapes

  • Path components are checked for traversal patterns (.., ~)

  • File size is checked before reading to prevent memory exhaustion

  • Write operations enforce size limits

License

MIT

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables file system operations such as listing, reading, and creating files within a scoped local project directory. It provides a secure way to manage local files through standardized MCP tools built with FastMCP.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables file system operations such as listing directories, reading, writing, creating, and deleting files or directories through MCP.
    20 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Exposes file system operations to AI clients via MCP, enabling secure read, write, and management of files and folders.
    7 npm
    MIT