You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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
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.
7
6
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
9
22
10
23
-**Secure File Access**: Only allows operations within explicitly allowed directories
11
24
-**Comprehensive Operations**: Full set of file system capabilities
12
25
- Standard operations (read, write, list, move, delete)
This is particularly useful for debugging issues or seeing exactly what Claude is requesting.
70
129
71
-
When using with MCP Inspector:
130
+
### Running the Server
72
131
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
76
143
```
77
144
78
-
Note: The trailing `run` is required as it specifies the subcommand to execute.
145
+
#### Options
79
146
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
81
151
82
-
##Claude Desktop Integration
152
+
### Using with MCP Inspector
83
153
84
-
To install in Claude Desktop:
154
+
For interactive testing and debugging with the MCP Inspector:
85
155
86
156
```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
npx @modelcontextprotocol/inspector uv run run_server.py /path/to/directory --debug
92
165
```
93
166
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:
95
172
96
173
**Config file location:**
97
174
- On macOS: `~/Library/Application\ Support/Claude/claude_desktop_config.json`
@@ -104,10 +181,9 @@ Or manually edit your Claude Desktop config file:
104
181
"command": "uv",
105
182
"args": [
106
183
"--directory",
107
-
"/path/to/mcp-filesystem",
184
+
"/path/to/mcp-filesystem/repo",
108
185
"run",
109
-
"mcp-filesystem",
110
-
"run"
186
+
"run_server.py"
111
187
]
112
188
}
113
189
}
@@ -123,10 +199,9 @@ To allow access to specific directories, add them as additional arguments:
123
199
"command": "uv",
124
200
"args": [
125
201
"--directory",
126
-
"/path/to/mcp-filesystem",
127
-
"run",
128
-
"mcp-filesystem",
202
+
"/path/to/mcp-filesystem/repo",
129
203
"run",
204
+
"run_server.py",
130
205
"/Users/yourusername/Projects",
131
206
"/Users/yourusername/Documents"
132
207
]
@@ -135,7 +210,41 @@ To allow access to specific directories, add them as additional arguments:
135
210
}
136
211
```
137
212
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
+
```
139
248
140
249
## Available Tools
141
250
@@ -245,28 +354,74 @@ Arguments: {
245
354
}
246
355
```
247
356
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
- 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
264
420
265
421
## Known Issues and Limitations
266
422
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.
268
423
-**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.
270
425
-**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.
0 commit comments