Skip to content

rosalinatorres888/filesystem-mcp

Repository files navigation

πŸ—‚οΈ Filesystem MCP Server

Python 3.10+ MCP License: MIT Tests Code style: black

A production-ready Model Context Protocol (MCP) server that enables AI assistants like Claude to perform sophisticated file system operations safely and efficiently.

Filesystem MCP Demo

✨ Features

Category Capabilities
πŸ“„ File Operations Read, write, append, copy, move, delete files with encoding support
πŸ“ Directory Operations List, create, delete, copy directories with recursive options
πŸ” Search & Discovery Pattern matching, filters by size/date/type, duplicate detection
⚑ Batch Operations Bulk rename, directory sync, statistics generation
πŸ”’ Security Path validation, size limits, safe defaults, preview modes
πŸ“ Prompts Built-in workflows for organizing, cleanup, and backup

πŸš€ Quick Start

Installation

# Using pip
pip install filesystem-mcp

# Using uv (recommended)
uv pip install filesystem-mcp

# From source
git clone https://github.com/yourusername/filesystem-mcp.git
cd filesystem-mcp
pip install -e .

Configure Claude Desktop

Add to your Claude Desktop configuration:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "filesystem": {
      "command": "filesystem-mcp",
      "env": {
        "FILESYSTEM_MCP_ALLOWED_DIRS": "/Users/yourname/Documents:/Users/yourname/Projects"
      }
    }
  }
}

Start Using

Once configured, you can ask Claude things like:

"Organize my Downloads folder by file type"

"Find all Python files modified this week in my projects"

"Show me duplicate files in my Photos folder"

"Sync my project folder to my backup drive"

πŸ“– Documentation

Available Tools (18)

File Operations
Tool Description
read_file Read text file contents with encoding support
write_file Write content to file, create if doesn't exist
append_file Append content to existing file
delete_file Delete a file
copy_file Copy file to new location
move_file Move or rename a file
Directory Operations
Tool Description
list_directory List contents with filtering and recursion
create_directory Create new directory with parent creation
delete_directory Delete directory (with recursive option)
copy_directory Copy directory tree
Search & Analysis
Tool Description
search_files Search with pattern, size, date filters
get_file_metadata Get detailed file info including hashes
find_duplicates Find duplicate files by content hash
get_directory_stats Directory statistics and analysis
Batch Operations
Tool Description
batch_rename Rename multiple files with regex patterns
sync_directories Synchronize directories with preview

Resources

URI Description
filesystem://config Server configuration
filesystem://home User's home directory
filesystem://cwd Current working directory

Prompts

Prompt Description
organize_files Guide for organizing files by extension, date, or size
cleanup_directory Find duplicates, empty dirs, temp files
backup_directory Backup workflow with verification

πŸ”§ Configuration

Environment Variables

Variable Description Default
FILESYSTEM_MCP_ALLOWED_DIRS Colon-separated allowed directories User home
FILESYSTEM_MCP_MAX_FILE_SIZE Maximum file size in MB 50

Security Model

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MCP Client (Claude)                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚ MCP Protocol
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Filesystem MCP Server                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              Path Validator                      β”‚    β”‚
β”‚  β”‚  β€’ Resolves all paths to absolute               β”‚    β”‚
β”‚  β”‚  β€’ Validates against allowed directories        β”‚    β”‚
β”‚  β”‚  β€’ Prevents path traversal attacks              β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              Resource Limits                     β”‚    β”‚
β”‚  β”‚  β€’ Max file size: 50MB (configurable)           β”‚    β”‚
β”‚  β”‚  β€’ Max search results: 100                      β”‚    β”‚
β”‚  β”‚  β€’ Preview mode for destructive ops             β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚ Validated Operations Only
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    File System                           β”‚
β”‚              (Allowed Directories Only)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ§ͺ Development

Setup

git clone https://github.com/yourusername/filesystem-mcp.git
cd filesystem-mcp
python -m venv .venv
source .venv/bin/activate  # or `.venv\Scripts\activate` on Windows
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=filesystem_mcp --cov-report=html

# Run specific test file
pytest tests/test_server.py -v

Code Quality

# Format code
black src/ tests/

# Lint
ruff check src/ tests/

# Type check
mypy src/

Running Locally

# Start the server (stdio mode)
filesystem-mcp

# Or run directly
python -m filesystem_mcp.server

πŸ—οΈ Architecture

filesystem-mcp/
β”œβ”€β”€ src/filesystem_mcp/
β”‚   β”œβ”€β”€ __init__.py          # Package exports
β”‚   └── server.py            # Main MCP server implementation
β”œβ”€β”€ tests/
β”‚   └── test_server.py       # Comprehensive test suite
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ claude_desktop_config.json
β”‚   └── example_client.py    # Programmatic usage example
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ API.md               # Full API documentation
β”‚   └── SECURITY.md          # Security considerations
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── tests.yml        # CI/CD pipeline
β”œβ”€β”€ pyproject.toml           # Package configuration
└── README.md

πŸ“Š Example Usage

Programmatic Client

import asyncio
from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters, stdio_client

async def main():
    server_params = StdioServerParameters(
        command="filesystem-mcp",
        env={"FILESYSTEM_MCP_ALLOWED_DIRS": "/tmp"}
    )
    
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            
            # List directory
            result = await session.call_tool(
                "list_directory",
                arguments={"path": "/tmp", "pattern": "*.txt"}
            )
            print(result)

asyncio.run(main())

Claude Desktop Interactions

User: "Find all files larger than 10MB in my Documents folder"

Claude: I'll search for large files in your Documents folder.

[Calls search_files with min_size=10485760]

Found 7 files larger than 10MB:
1. video_project.mp4 (245 MB) - Modified: 2024-01-15
2. dataset.csv (89 MB) - Modified: 2024-01-10
...

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide first.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Anthropic for creating the Model Context Protocol
  • FastMCP for the excellent Python SDK
  • The MCP community for inspiration and feedback

πŸ“¬ Contact

Rosalina Torres - MS Data Analytics Engineering, Northeastern University


Made with ❀️ for the AI community

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages