Skip to content

Commit 7a9d229

Browse files
authored
Feat/cleanup (#1)
[feat] Streamline CLI + Update docs This PR streamlines the user experience by refactoring the CLI interface and adding direct script execution. Key updates include: - Remove nested run subcommand for more intuitive usage - Add standalone run_server.py entry point for easier invocation - Expand README with clear examples and token-efficient workflow patterns - Highlight advantages over standard filesystem MCP servers - Add CLI-specific behavior tests
1 parent a4a792d commit 7a9d229

File tree

8 files changed

+466
-92
lines changed

8 files changed

+466
-92
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ docker/.env
1717
.aider*
1818
CLAUDE.md
1919
docs/**
20+
21+
# AI conversation artifacts
22+
context/**
23+
AI_CHANGELOG.md

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Contributing to Python Collab Template
1+
# Contributing to MCP Filesystem
22

33
Thank you for your interest in contributing to this project!
44

55
## Getting Started
66

77
1. Fork the repository
8-
2. Clone your fork: `git clone [email protected]:your-username/python-collab-template.git`
8+
2. Clone your fork: `git clone [email protected]:your-username/mcp-filesystem.git`
99
3. Create a new branch: `git checkout -b feature-name`
1010
4. Make your changes
1111
5. Run quality checks: `make check`

README.md

Lines changed: 220 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,174 @@
11
# MCP Filesystem Server
22

3-
[![PyPI - Version](https://img.shields.io/pypi/v/mcp-filesystem.svg)](https://pypi.org/project/mcp-filesystem)
43
[![License](https://img.shields.io/github/license/safurrier/mcp-filesystem.svg)](https://github.com/safurrier/mcp-filesystem/blob/main/LICENSE)
54

6-
A powerful Model Context Protocol (MCP) server for filesystem operations that provides Claude and other MCP clients with secure access to files and directories.
5+
A powerful Model Context Protocol (MCP) server for filesystem operations optimized for intelligent interaction with large files and filesystems. It provides secure access to files and directories with smart context management to maximize efficiency when working with extensive data.
76

8-
## Features
7+
## Why MCP-Filesystem?
8+
9+
- **Smart Context Management**: Work efficiently with large files and filesystems
10+
- Partial reading to focus only on relevant content
11+
- Precise context control for finding exactly what you need
12+
- Token-efficient search results with pagination
13+
- Multi-file operations to reduce request overhead
14+
15+
- **Intelligent File Operations**:
16+
- Line-targeted reading with configurable context windows
17+
- Advanced editing with content verification to prevent conflicts
18+
- Fine-grained search capabilities that exceed standard grep
19+
- Relative line references for precise file manipulation
20+
21+
## Key Features
922

1023
- **Secure File Access**: Only allows operations within explicitly allowed directories
1124
- **Comprehensive Operations**: Full set of file system capabilities
1225
- Standard operations (read, write, list, move, delete)
1326
- Enhanced operations (tree visualization, duplicate finding, etc.)
1427
- Advanced search with grep integration (uses ripgrep when available)
15-
- Context control (like grep's -A/-B/-C options)
28+
- Context control (like grep's -A/-B/-C options)
1629
- Result pagination for large result sets
1730
- Line-targeted operations with content verification and relative line numbers
1831
- **Performance Optimized**:
1932
- Efficiently handles large files and directories
2033
- Ripgrep integration for blazing fast searches
2134
- Line-targeted operations to avoid loading entire files
22-
- **Claude Integration**: Easily installs in Claude Desktop
35+
- **Comprehensive Testing**: 75+ tests with behavior-driven approach
2336
- **Cross-Platform**: Works on Windows, macOS, and Linux
2437

25-
## Installation
38+
## Quickstart Guide
39+
40+
### 1. Clone and Setup
41+
42+
First, install uv if you haven't already:
2643

27-
### From PyPI
2844
```bash
29-
# With pip
30-
pip install mcp-filesystem
45+
# Install uv using the official installer
46+
curl -fsSL https://raw.githubusercontent.com/astral-sh/uv/main/install.sh | bash
3147

32-
# With uv (recommended for Claude Desktop)
33-
uv pip install mcp-filesystem
48+
# Or with pipx
49+
pipx install uv
3450
```
3551

36-
### From Source
52+
Then clone the repository and install dependencies:
53+
3754
```bash
38-
# With pip
55+
# Clone the repository
3956
git clone https://github.com/safurrier/mcp-filesystem.git
4057
cd mcp-filesystem
41-
pip install -e .
4258

43-
# With uv (recommended for Claude Desktop)
44-
git clone https://github.com/safurrier/mcp-filesystem.git
45-
cd mcp-filesystem
46-
uv pip install -e .
59+
# Install dependencies with uv
60+
uv pip sync requirements.txt requirements-dev.txt
4761
```
4862

49-
## Quick Start
63+
### 2. Get Absolute Paths
5064

51-
Run the server with access to the current directory:
65+
You'll need absolute paths both for the repository location and any directories you want to access:
5266

5367
```bash
54-
mcp-filesystem run
68+
# Get the absolute path to the repository
69+
REPO_PATH=$(pwd)
70+
echo "Repository path: $REPO_PATH"
71+
72+
# Get absolute paths to directories you want to access
73+
realpath ~/Documents
74+
realpath ~/Downloads
75+
# Or on systems without realpath:
76+
echo "$(cd ~/Documents && pwd)"
5577
```
5678

57-
Allow access to specific directories:
79+
### 3. Configure Claude Desktop
5880

59-
```bash
60-
mcp-filesystem run /path/to/dir1 /path/to/dir2
81+
Open your Claude Desktop configuration file:
82+
- On macOS: `~/Library/Application\ Support/Claude/claude_desktop_config.json`
83+
- On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
84+
85+
Add the following configuration (substitute your actual paths):
86+
87+
```json
88+
{
89+
"mcpServers": {
90+
"mcp-filesystem": {
91+
"command": "uv",
92+
"args": [
93+
"--directory",
94+
"/absolute/path/to/mcp-filesystem",
95+
"run",
96+
"run_server.py",
97+
"/absolute/path/to/dir1",
98+
"/absolute/path/to/dir2"
99+
]
100+
}
101+
}
102+
}
61103
```
62104

63-
Use SSE transport instead of stdio:
105+
> **Important**: All paths must be absolute (full paths from root directory).
106+
> Use `realpath` or `pwd` to ensure you have the correct absolute paths.
107+
108+
### 4. Restart Claude Desktop
109+
110+
After saving your configuration, restart Claude Desktop for the changes to take effect.
111+
112+
## Installation
113+
114+
## Usage
115+
116+
### Watch Server Logs
117+
118+
You can monitor the server logs from Claude Desktop with:
64119

65120
```bash
66-
mcp-filesystem run --transport sse --port 8000
121+
# On macOS
122+
tail -n 20 -f ~/Library/Logs/Claude/mcp-server-mcp-filesystem.log
123+
124+
# On Windows (PowerShell)
125+
Get-Content -Path "$env:APPDATA\Claude\Logs\mcp-server-mcp-filesystem.log" -Tail 20 -Wait
67126
```
68127

69-
## MCP Inspector Usage
128+
This is particularly useful for debugging issues or seeing exactly what Claude is requesting.
70129

71-
When using with MCP Inspector:
130+
### Running the Server
72131

73-
```
74-
Command: uv
75-
Arguments: --directory /path/to/mcp-filesystem run mcp-filesystem run
132+
Run the server with access to specific directories:
133+
134+
```bash
135+
# Using uv (recommended)
136+
uv run run_server.py /path/to/dir1 /path/to/dir2
137+
138+
# Or using standard Python
139+
python run_server.py /path/to/dir1 /path/to/dir2
140+
141+
# Example with actual paths
142+
uv run run_server.py /Users/username/Documents /Users/username/Downloads
76143
```
77144

78-
Note: The trailing `run` is required as it specifies the subcommand to execute.
145+
#### Options
79146

80-
This server has been refactored to use the new FastMCP SDK for better alignment with current MCP best practices. It now uses a more efficient component caching system and direct decorator pattern rather than a class-based approach.
147+
- `--transport` or `-t`: Transport protocol (stdio or sse, default: stdio)
148+
- `--port` or `-p`: Port for SSE transport (default: 8000)
149+
- `--debug` or `-d`: Enable debug logging
150+
- `--version` or `-v`: Show version information
81151

82-
## Claude Desktop Integration
152+
### Using with MCP Inspector
83153

84-
To install in Claude Desktop:
154+
For interactive testing and debugging with the MCP Inspector:
85155

86156
```bash
87-
# Using mcp CLI
88-
mcp install mcp-filesystem
157+
# Basic usage
158+
npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory
159+
160+
# With SSE transport
161+
npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory --transport sse --port 8080
89162

90-
# With access to specific directories
91-
mcp install mcp-filesystem --args="/path/to/dir1 /path/to/dir2"
163+
# With debug output
164+
npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory --debug
92165
```
93166

94-
Or manually edit your Claude Desktop config file:
167+
This server has been built with the FastMCP SDK for better alignment with current MCP best practices. It uses an efficient component caching system and direct decorator pattern.
168+
169+
## Claude Desktop Integration
170+
171+
Edit your Claude Desktop config file to integrate MCP-Filesystem:
95172

96173
**Config file location:**
97174
- On macOS: `~/Library/Application\ Support/Claude/claude_desktop_config.json`
@@ -104,10 +181,9 @@ Or manually edit your Claude Desktop config file:
104181
"command": "uv",
105182
"args": [
106183
"--directory",
107-
"/path/to/mcp-filesystem",
184+
"/path/to/mcp-filesystem/repo",
108185
"run",
109-
"mcp-filesystem",
110-
"run"
186+
"run_server.py"
111187
]
112188
}
113189
}
@@ -123,10 +199,9 @@ To allow access to specific directories, add them as additional arguments:
123199
"command": "uv",
124200
"args": [
125201
"--directory",
126-
"/path/to/mcp-filesystem",
127-
"run",
128-
"mcp-filesystem",
202+
"/path/to/mcp-filesystem/repo",
129203
"run",
204+
"run_server.py",
130205
"/Users/yourusername/Projects",
131206
"/Users/yourusername/Documents"
132207
]
@@ -135,7 +210,41 @@ To allow access to specific directories, add them as additional arguments:
135210
}
136211
```
137212

138-
Note: The trailing `run` at the end of the args is required as it specifies the subcommand to execute.
213+
> Note: The `--directory` flag is important as it tells uv where to find the repository containing run_server.py. Replace `/path/to/mcp-filesystem/repo` with the actual path to where you cloned the repository on your system.
214+
215+
## Development
216+
217+
### Running Tests
218+
219+
```bash
220+
# Run all tests
221+
uv run -m pytest tests/
222+
223+
# Run specific test file
224+
uv run -m pytest tests/test_operations_unit.py
225+
226+
# Run with coverage
227+
uv run -m pytest tests/ --cov=mcp_filesystem --cov-report=term-missing
228+
```
229+
230+
### Code Style and Quality
231+
232+
```bash
233+
# Format code
234+
uv run -m ruff format mcp_filesystem
235+
236+
# Lint code
237+
uv run -m ruff check --fix mcp_filesystem
238+
239+
# Type check
240+
uv run -m mypy mcp_filesystem
241+
242+
# Run all checks
243+
uv run -m ruff format mcp_filesystem && \
244+
uv run -m ruff check --fix mcp_filesystem && \
245+
uv run -m mypy mcp_filesystem && \
246+
uv run -m pytest tests --cov=mcp_filesystem
247+
```
139248

140249
## Available Tools
141250

@@ -245,28 +354,74 @@ Arguments: {
245354
}
246355
```
247356

248-
## Efficient Workflow
249-
250-
The tools are designed to work together efficiently:
251-
252-
1. Use `grep_files` to find relevant content with precise context control
253-
- Fine-grained control over context lines before/after matches
254-
- Paginate through large result sets efficiently
255-
2. Examine specific sections with `read_file_lines` using offset/limit
256-
- Zero-based indexing with simple offset/limit parameters
257-
- Control exactly how many lines to read
258-
3. Make targeted edits with `edit_file_at_line` with content verification
259-
- Verify content hasn't changed before editing
260-
- Use relative line numbers for regional editing
261-
- Multiple edit actions in a single operation
262-
263-
This workflow allows Claude to work effectively even with very large codebases by focusing on just the relevant parts while ensuring edits are safe and precise.
357+
## Efficient Workflow for Large Files and Filesystems
358+
359+
MCP-Filesystem is designed for intelligent interaction with large files and complex filesystems:
360+
361+
1. **Smart Context Discovery**
362+
- Use `grep_files` to find exactly what you need with precise context control
363+
- Fine-grained control over context lines before/after matches prevents token waste
364+
- Paginate through large result sets efficiently without overwhelming token limits
365+
- Ripgrep integration handles massive filesystems with millions of files and lines
366+
367+
2. **Targeted Reading**
368+
- Examine only relevant sections with `read_file_lines` using offset/limit
369+
- Zero-based indexing with simple offset/limit parameters for precise content retrieval
370+
- Control exactly how many lines to read to maximize token efficiency
371+
- Read multiple files simultaneously to reduce round-trips
372+
373+
3. **Precise Editing**
374+
- Make targeted edits with `edit_file_at_line` with content verification
375+
- Verify content hasn't changed before editing to prevent conflicts
376+
- Use relative line numbers for regional editing in complex files
377+
- Multiple edit actions in a single operation for complex changes
378+
- Dry-run capability to preview changes before applying
379+
380+
4. **Advanced Analysis**
381+
- Use specialized tools like `find_duplicate_files` and `compare_files`
382+
- Generate directory trees with `directory_tree` for quick navigation
383+
- Identify problematic areas with `find_large_files` and `find_empty_directories`
384+
385+
This workflow is particularly valuable for AI-powered tools that need to work with large files and filesystems. For example, Claude and other advanced AI assistants can leverage these capabilities to efficiently navigate codebases, analyze log files, or work with any large text-based datasets while maintaining token efficiency.
386+
387+
## Advantages Over Standard Filesystem MCP Servers
388+
389+
Unlike basic filesystem MCP servers, MCP-Filesystem offers:
390+
391+
1. **Token Efficiency**
392+
- Smart line-targeted operations avoid loading entire files into context
393+
- Pagination controls for large results prevent context overflow
394+
- Precise grep with context controls (not just whole file searches)
395+
- Multi-file reading reduces round-trip requests
396+
397+
2. **Intelligent Editing**
398+
- Content verification to prevent edit conflicts
399+
- Line-targeted edits that don't require the entire file
400+
- Relative line number support for easier regional editing
401+
- Dry-run capability to preview changes before applying
402+
403+
3. **Advanced Search**
404+
- Ripgrep integration for massive filesystem performance
405+
- Context-aware results (not just matches)
406+
- Fine-grained control over what gets returned
407+
- Pattern-based file finding with exclusion support
408+
409+
4. **Additional Utilities**
410+
- File comparison and deduplication
411+
- Directory size calculation and analysis
412+
- Empty directory identification
413+
- Tree-based directory visualization
414+
415+
5. **Security Focus**
416+
- Robust path validation and sandboxing
417+
- Protection against path traversal attacks
418+
- Symlink validation and security
419+
- Detailed error reporting without sensitive exposure
264420

265421
## Known Issues and Limitations
266422

267-
- **Regex Escaping**: When using regex patterns with special characters like `\d`, `\w`, or `\s`, you may need to double-escape backslashes (e.g., `\\d`, `\\w`, `\\s`). This is due to how JSON processes escape characters.
268423
- **Path Resolution**: Always use absolute paths for the most consistent results. Relative paths might be interpreted relative to the server's working directory rather than the allowed directories.
269-
- **Performance**: For large directories, operations like `find_duplicate_files` might take significant time to complete.
424+
- **Performance**: For large directories, operations like `find_duplicate_files` or recusrive search might take significant time to complete.
270425
- **Permission Handling**: The server operates with the same permissions as the user running it. Make sure the server has appropriate permissions for the directories it needs to access.
271426

272427
## Security

0 commit comments

Comments
 (0)