@j0hanz/filesystem-context-mcp 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +532 -369
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,369 +1,532 @@
|
|
|
1
|
-
# Filesystem Context MCP Server
|
|
2
|
-
|
|
3
|
-
A secure
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
**Returns:**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
**Returns:**
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
1
|
+
# Filesystem Context MCP Server
|
|
2
|
+
|
|
3
|
+
A secure, read-only MCP server for filesystem scanning, searching, and analysis with comprehensive security validation.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@j0hanz/filesystem-context-mcp)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[](https://modelcontextprotocol.io)
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
| Feature | Description |
|
|
14
|
+
| -------------------------- | ---------------------------------------------------------------------- |
|
|
15
|
+
| 📂 **Directory Listing** | List and explore directory contents with recursive support |
|
|
16
|
+
| 🔍 **File Search** | Find files using glob patterns like `**/*.ts` |
|
|
17
|
+
| 📝 **Content Search** | Search text within files using regex with context lines |
|
|
18
|
+
| 📊 **Directory Analysis** | Get statistics, file types, largest files, and recently modified files |
|
|
19
|
+
| 🌳 **Directory Tree** | JSON tree structure optimized for AI parsing |
|
|
20
|
+
| 📄 **File Reading** | Read single or multiple files with head/tail and line range support |
|
|
21
|
+
| 🖼️ **Media File Support** | Read binary files (images, audio, video) as base64 |
|
|
22
|
+
| 🔒 **Security First** | Path validation, symlink escape protection, and access control |
|
|
23
|
+
| ⚡ **Parallel Operations** | Efficient batch file reading with configurable concurrency |
|
|
24
|
+
|
|
25
|
+
## 🎯 When to Use
|
|
26
|
+
|
|
27
|
+
| Task | Tool |
|
|
28
|
+
| -------------------------------- | -------------------------- |
|
|
29
|
+
| Explore project structure | `list_directory` |
|
|
30
|
+
| Find specific file types | `search_files` |
|
|
31
|
+
| Search for code patterns/text | `search_content` |
|
|
32
|
+
| Understand codebase statistics | `analyze_directory` |
|
|
33
|
+
| Get AI-friendly project overview | `directory_tree` |
|
|
34
|
+
| Read source code | `read_file` |
|
|
35
|
+
| Batch read multiple files | `read_multiple_files` |
|
|
36
|
+
| Get file metadata (size, dates) | `get_file_info` |
|
|
37
|
+
| Read images or binary files | `read_media_file` |
|
|
38
|
+
| Check available directories | `list_allowed_directories` |
|
|
39
|
+
|
|
40
|
+
## 🚀 Quick Start
|
|
41
|
+
|
|
42
|
+
### NPX (Recommended)
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx -y @j0hanz/filesystem-context-mcp@latest /path/to/your/project
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### VS Code
|
|
49
|
+
|
|
50
|
+
Add to your VS Code settings (`.vscode/settings.json` or User Settings):
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcp": {
|
|
55
|
+
"servers": {
|
|
56
|
+
"filesystem-context": {
|
|
57
|
+
"command": "npx",
|
|
58
|
+
"args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Claude Desktop
|
|
66
|
+
|
|
67
|
+
Add to your Claude Desktop configuration (`claude_desktop_config.json`):
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"mcpServers": {
|
|
72
|
+
"filesystem-context": {
|
|
73
|
+
"command": "npx",
|
|
74
|
+
"args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 📦 Installation
|
|
81
|
+
|
|
82
|
+
### NPX (No Installation)
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx -y @j0hanz/filesystem-context-mcp@latest /path/to/dir1 /path/to/dir2
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Global Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install -g @j0hanz/filesystem-context-mcp
|
|
92
|
+
filesystem-context-mcp /path/to/your/project
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### From Source
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git clone https://github.com/j0hanz/filesystem-context-mcp-server.git
|
|
99
|
+
cd filesystem-context-mcp-server
|
|
100
|
+
npm install
|
|
101
|
+
npm run build
|
|
102
|
+
node dist/index.js /path/to/your/project
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## ⚙️ Configuration
|
|
106
|
+
|
|
107
|
+
### Command Line Arguments
|
|
108
|
+
|
|
109
|
+
The server accepts one or more directory paths as arguments. Only these directories (and their contents) will be accessible:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
filesystem-context-mcp /home/user/project /home/user/docs
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### MCP Roots Protocol
|
|
116
|
+
|
|
117
|
+
If no CLI arguments are provided, the server will use the MCP Roots protocol to receive allowed directories from the client. This is useful for dynamic directory configuration.
|
|
118
|
+
|
|
119
|
+
### Environment Variables
|
|
120
|
+
|
|
121
|
+
| Variable | Description |
|
|
122
|
+
| ---------- | --------------------------------------------- |
|
|
123
|
+
| `NODE_ENV` | Set to `production` for optimized performance |
|
|
124
|
+
|
|
125
|
+
## 🔧 Tools
|
|
126
|
+
|
|
127
|
+
### `list_allowed_directories`
|
|
128
|
+
|
|
129
|
+
List all directories that this server is allowed to access.
|
|
130
|
+
|
|
131
|
+
| Parameter | Type | Required | Default | Description |
|
|
132
|
+
| --------- | ---- | -------- | ------- | ---------------------- |
|
|
133
|
+
| _(none)_ | - | - | - | No parameters required |
|
|
134
|
+
|
|
135
|
+
**Returns:** Array of allowed directory paths.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### `list_directory`
|
|
140
|
+
|
|
141
|
+
List contents of a directory with optional recursive listing.
|
|
142
|
+
|
|
143
|
+
| Parameter | Type | Required | Default | Description |
|
|
144
|
+
| ----------------------- | ------- | -------- | ------- | ------------------------------------------- |
|
|
145
|
+
| `path` | string | ✅ | - | Directory path to list |
|
|
146
|
+
| `recursive` | boolean | ❌ | `false` | List recursively |
|
|
147
|
+
| `includeHidden` | boolean | ❌ | `false` | Include hidden files |
|
|
148
|
+
| `maxDepth` | number | ❌ | `10` | Maximum depth for recursive listing (0-100) |
|
|
149
|
+
| `maxEntries` | number | ❌ | - | Maximum entries to return (1-100,000) |
|
|
150
|
+
| `sortBy` | string | ❌ | `name` | Sort by: `name`, `size`, `modified`, `type` |
|
|
151
|
+
| `includeSymlinkTargets` | boolean | ❌ | `false` | Include symlink target paths |
|
|
152
|
+
|
|
153
|
+
**Returns:** List of entries with name, type, size, and modified date.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
### `search_files`
|
|
158
|
+
|
|
159
|
+
Search for files using glob patterns.
|
|
160
|
+
|
|
161
|
+
| Parameter | Type | Required | Default | Description |
|
|
162
|
+
| ----------------- | -------- | -------- | ------- | --------------------------------------------- |
|
|
163
|
+
| `path` | string | ✅ | - | Base directory to search from |
|
|
164
|
+
| `pattern` | string | ✅ | - | Glob pattern (e.g., `**/*.ts`, `src/**/*.js`) |
|
|
165
|
+
| `excludePatterns` | string[] | ❌ | `[]` | Patterns to exclude |
|
|
166
|
+
| `maxResults` | number | ❌ | - | Maximum matches to return (1-10,000) |
|
|
167
|
+
| `sortBy` | string | ❌ | `path` | Sort by: `name`, `size`, `modified`, `path` |
|
|
168
|
+
| `maxDepth` | number | ❌ | - | Maximum directory depth to search (1-100) |
|
|
169
|
+
|
|
170
|
+
**Returns:** List of matching files with path, type, size, and modified date.
|
|
171
|
+
|
|
172
|
+
**Example:**
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"path": "/project",
|
|
177
|
+
"pattern": "**/*.ts",
|
|
178
|
+
"excludePatterns": ["node_modules/**", "dist/**"]
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### `read_file`
|
|
185
|
+
|
|
186
|
+
Read the contents of a text file.
|
|
187
|
+
|
|
188
|
+
| Parameter | Type | Required | Default | Description |
|
|
189
|
+
| ----------- | ------ | -------- | ------- | ------------------------------------------------ |
|
|
190
|
+
| `path` | string | ✅ | - | File path to read |
|
|
191
|
+
| `encoding` | string | ❌ | `utf-8` | File encoding (`utf-8`, `ascii`, `base64`, etc.) |
|
|
192
|
+
| `maxSize` | number | ❌ | 10MB | Maximum file size in bytes |
|
|
193
|
+
| `lineStart` | number | ❌ | - | Start line (1-indexed) for reading a range |
|
|
194
|
+
| `lineEnd` | number | ❌ | - | End line (inclusive) for reading a range |
|
|
195
|
+
| `head` | number | ❌ | - | Read only first N lines |
|
|
196
|
+
| `tail` | number | ❌ | - | Read only last N lines |
|
|
197
|
+
|
|
198
|
+
> **Note:** Cannot specify both `head` and `tail` simultaneously. Use `lineStart`/`lineEnd` for range reading.
|
|
199
|
+
|
|
200
|
+
**Returns:** File contents as text.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### `read_multiple_files`
|
|
205
|
+
|
|
206
|
+
Read multiple files in parallel for efficient batch operations.
|
|
207
|
+
|
|
208
|
+
| Parameter | Type | Required | Default | Description |
|
|
209
|
+
| ---------- | -------- | -------- | ------- | ------------------------------------ |
|
|
210
|
+
| `paths` | string[] | ✅ | - | Array of file paths (max 100) |
|
|
211
|
+
| `encoding` | string | ❌ | `utf-8` | File encoding |
|
|
212
|
+
| `maxSize` | number | ❌ | 10MB | Maximum file size per file |
|
|
213
|
+
| `head` | number | ❌ | - | Read only first N lines of each file |
|
|
214
|
+
| `tail` | number | ❌ | - | Read only last N lines of each file |
|
|
215
|
+
|
|
216
|
+
**Returns:** Array of results with content or error for each file.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
### `get_file_info`
|
|
221
|
+
|
|
222
|
+
Get detailed metadata about a file or directory.
|
|
223
|
+
|
|
224
|
+
| Parameter | Type | Required | Default | Description |
|
|
225
|
+
| --------- | ------ | -------- | ------- | ------------------------- |
|
|
226
|
+
| `path` | string | ✅ | - | Path to file or directory |
|
|
227
|
+
|
|
228
|
+
**Returns:** Metadata including name, type, size, created/modified/accessed timestamps, permissions, MIME type, and symlink target (if applicable).
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
### `search_content`
|
|
233
|
+
|
|
234
|
+
Search for text content within files using regular expressions.
|
|
235
|
+
|
|
236
|
+
| Parameter | Type | Required | Default | Description |
|
|
237
|
+
| ----------------- | -------- | -------- | ------- | ------------------------------------------------ |
|
|
238
|
+
| `path` | string | ✅ | - | Base directory to search in |
|
|
239
|
+
| `pattern` | string | ✅ | - | Regex pattern to search for |
|
|
240
|
+
| `filePattern` | string | ❌ | `**/*` | Glob pattern to filter files |
|
|
241
|
+
| `excludePatterns` | string[] | ❌ | `[]` | Glob patterns to exclude |
|
|
242
|
+
| `caseSensitive` | boolean | ❌ | `false` | Case-sensitive search |
|
|
243
|
+
| `maxResults` | number | ❌ | `100` | Maximum number of results (1-10,000) |
|
|
244
|
+
| `maxFileSize` | number | ❌ | 1MB | Maximum file size to scan |
|
|
245
|
+
| `maxFilesScanned` | number | ❌ | - | Maximum files to scan before stopping |
|
|
246
|
+
| `timeoutMs` | number | ❌ | - | Timeout in milliseconds (100-3,600,000) |
|
|
247
|
+
| `skipBinary` | boolean | ❌ | `true` | Skip binary files |
|
|
248
|
+
| `contextLines` | number | ❌ | `0` | Lines of context before/after match (0-10) |
|
|
249
|
+
| `wholeWord` | boolean | ❌ | `false` | Match whole words only |
|
|
250
|
+
| `isLiteral` | boolean | ❌ | `false` | Treat pattern as literal string (escape special) |
|
|
251
|
+
|
|
252
|
+
**Returns:** Matching lines with file path, line number, content, and optional context.
|
|
253
|
+
|
|
254
|
+
**Example:**
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"path": "/project/src",
|
|
259
|
+
"pattern": "TODO|FIXME",
|
|
260
|
+
"filePattern": "**/*.ts",
|
|
261
|
+
"contextLines": 2
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### `analyze_directory`
|
|
268
|
+
|
|
269
|
+
Analyze a directory structure and return statistics.
|
|
270
|
+
|
|
271
|
+
| Parameter | Type | Required | Default | Description |
|
|
272
|
+
| ----------------- | -------- | -------- | ------- | -------------------------------------- |
|
|
273
|
+
| `path` | string | ✅ | - | Directory to analyze |
|
|
274
|
+
| `maxDepth` | number | ❌ | `10` | Maximum depth to analyze (0-100) |
|
|
275
|
+
| `topN` | number | ❌ | `10` | Number of top items to return (1-1000) |
|
|
276
|
+
| `excludePatterns` | string[] | ❌ | `[]` | Glob patterns to exclude |
|
|
277
|
+
| `includeHidden` | boolean | ❌ | `false` | Include hidden files and directories |
|
|
278
|
+
|
|
279
|
+
**Returns:** Statistics including total files/directories, total size, file type distribution, largest files, and recently modified files.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
### `directory_tree`
|
|
284
|
+
|
|
285
|
+
Get a JSON tree structure of a directory, optimized for AI parsing.
|
|
286
|
+
|
|
287
|
+
| Parameter | Type | Required | Default | Description |
|
|
288
|
+
| ----------------- | -------- | -------- | ------- | --------------------------------------- |
|
|
289
|
+
| `path` | string | ✅ | - | Directory path to build tree from |
|
|
290
|
+
| `maxDepth` | number | ❌ | `5` | Maximum depth to traverse (0-50) |
|
|
291
|
+
| `excludePatterns` | string[] | ❌ | `[]` | Glob patterns to exclude |
|
|
292
|
+
| `includeHidden` | boolean | ❌ | `false` | Include hidden files and directories |
|
|
293
|
+
| `includeSize` | boolean | ❌ | `false` | Include file sizes in the tree |
|
|
294
|
+
| `maxFiles` | number | ❌ | - | Maximum total files to include (1-100k) |
|
|
295
|
+
|
|
296
|
+
**Returns:** Hierarchical tree structure with file/directory nodes.
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
### `read_media_file`
|
|
301
|
+
|
|
302
|
+
Read a binary/media file and return it as base64-encoded data.
|
|
303
|
+
|
|
304
|
+
| Parameter | Type | Required | Default | Description |
|
|
305
|
+
| --------- | ------ | -------- | ------- | -------------------------------------- |
|
|
306
|
+
| `path` | string | ✅ | - | Path to the media file |
|
|
307
|
+
| `maxSize` | number | ❌ | 50MB | Maximum file size in bytes (max 500MB) |
|
|
308
|
+
|
|
309
|
+
**Supported formats:** Images (PNG, JPG, GIF, WebP, SVG, etc.), Audio (MP3, WAV, FLAC, etc.), Video (MP4, WebM, etc.), Fonts (TTF, WOFF, etc.), PDFs, and more.
|
|
310
|
+
|
|
311
|
+
**Returns:** Base64-encoded data with MIME type, size, and dimensions (for images).
|
|
312
|
+
|
|
313
|
+
## 🔌 Client Configuration
|
|
314
|
+
|
|
315
|
+
<details>
|
|
316
|
+
<summary><b>VS Code</b></summary>
|
|
317
|
+
|
|
318
|
+
Add to `.vscode/settings.json`:
|
|
319
|
+
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"mcp": {
|
|
323
|
+
"servers": {
|
|
324
|
+
"filesystem-context": {
|
|
325
|
+
"command": "npx",
|
|
326
|
+
"args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
</details>
|
|
334
|
+
|
|
335
|
+
<details>
|
|
336
|
+
<summary><b>Claude Desktop</b></summary>
|
|
337
|
+
|
|
338
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
339
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
340
|
+
|
|
341
|
+
```json
|
|
342
|
+
{
|
|
343
|
+
"mcpServers": {
|
|
344
|
+
"filesystem-context": {
|
|
345
|
+
"command": "npx",
|
|
346
|
+
"args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
</details>
|
|
353
|
+
|
|
354
|
+
<details>
|
|
355
|
+
<summary><b>Cursor</b></summary>
|
|
356
|
+
|
|
357
|
+
Add to Cursor's MCP configuration:
|
|
358
|
+
|
|
359
|
+
```json
|
|
360
|
+
{
|
|
361
|
+
"mcpServers": {
|
|
362
|
+
"filesystem-context": {
|
|
363
|
+
"command": "npx",
|
|
364
|
+
"args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
</details>
|
|
371
|
+
|
|
372
|
+
<details>
|
|
373
|
+
<summary><b>Windsurf</b></summary>
|
|
374
|
+
|
|
375
|
+
Add to Windsurf's MCP configuration:
|
|
376
|
+
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"mcpServers": {
|
|
380
|
+
"filesystem-context": {
|
|
381
|
+
"command": "npx",
|
|
382
|
+
"args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
</details>
|
|
389
|
+
|
|
390
|
+
## 🔒 Security
|
|
391
|
+
|
|
392
|
+
This server implements multiple layers of security:
|
|
393
|
+
|
|
394
|
+
| Protection | Description |
|
|
395
|
+
| ----------------------------- | ------------------------------------------------------------------------- |
|
|
396
|
+
| **Access Control** | Only explicitly allowed directories are accessible |
|
|
397
|
+
| **Path Validation** | All paths are validated before any filesystem operation |
|
|
398
|
+
| **Symlink Protection** | Symlinks that resolve outside allowed directories are blocked |
|
|
399
|
+
| **Path Traversal Prevention** | Attempts to escape via `../` are detected and blocked |
|
|
400
|
+
| **Read-Only Operations** | Server only performs read operations—no writes, deletes, or modifications |
|
|
401
|
+
| **Safe Regex** | Regular expressions are validated to prevent ReDoS attacks |
|
|
402
|
+
| **Size Limits** | Configurable limits prevent resource exhaustion |
|
|
403
|
+
|
|
404
|
+
### Security Model
|
|
405
|
+
|
|
406
|
+
```text
|
|
407
|
+
┌─────────────────────────────────────────────────────────┐
|
|
408
|
+
│ MCP Client │
|
|
409
|
+
└─────────────────────┬───────────────────────────────────┘
|
|
410
|
+
│
|
|
411
|
+
▼
|
|
412
|
+
┌─────────────────────────────────────────────────────────┐
|
|
413
|
+
│ Filesystem Context MCP Server │
|
|
414
|
+
│ ┌───────────────────────────────────────────────────┐ │
|
|
415
|
+
│ │ Path Validation Layer │ │
|
|
416
|
+
│ │ • Normalize paths │ │
|
|
417
|
+
│ │ • Check against allowed directories │ │
|
|
418
|
+
│ │ • Resolve and validate symlinks │ │
|
|
419
|
+
│ │ • Block traversal attempts │ │
|
|
420
|
+
│ └───────────────────────────────────────────────────┘ │
|
|
421
|
+
│ │ │
|
|
422
|
+
│ ▼ │
|
|
423
|
+
│ ┌───────────────────────────────────────────────────┐ │
|
|
424
|
+
│ │ Read-Only File Operations │ │
|
|
425
|
+
│ └───────────────────────────────────────────────────┘ │
|
|
426
|
+
└─────────────────────────────────────────────────────────┘
|
|
427
|
+
│
|
|
428
|
+
▼
|
|
429
|
+
┌─────────────────────────────────────────────────────────┐
|
|
430
|
+
│ Allowed Directories Only │
|
|
431
|
+
│ /home/user/project ✅ │
|
|
432
|
+
│ /home/user/docs ✅ │
|
|
433
|
+
│ /etc/passwd ❌ (blocked) │
|
|
434
|
+
│ ../../../etc ❌ (blocked) │
|
|
435
|
+
└─────────────────────────────────────────────────────────┘
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## 🛠️ Development
|
|
439
|
+
|
|
440
|
+
### Prerequisites
|
|
441
|
+
|
|
442
|
+
- Node.js >= 20.0.0
|
|
443
|
+
- npm
|
|
444
|
+
|
|
445
|
+
### Scripts
|
|
446
|
+
|
|
447
|
+
| Command | Description |
|
|
448
|
+
| ----------------------- | -------------------------------- |
|
|
449
|
+
| `npm run build` | Compile TypeScript to JavaScript |
|
|
450
|
+
| `npm run dev` | Watch mode with tsx |
|
|
451
|
+
| `npm run start` | Run compiled server |
|
|
452
|
+
| `npm run test` | Run tests with Vitest |
|
|
453
|
+
| `npm run test:watch` | Run tests in watch mode |
|
|
454
|
+
| `npm run test:coverage` | Run tests with coverage report |
|
|
455
|
+
| `npm run lint` | Run ESLint |
|
|
456
|
+
| `npm run format` | Format code with Prettier |
|
|
457
|
+
| `npm run type-check` | TypeScript type checking |
|
|
458
|
+
| `npm run inspector` | Test with MCP Inspector |
|
|
459
|
+
|
|
460
|
+
### Project Structure
|
|
461
|
+
|
|
462
|
+
```text
|
|
463
|
+
src/
|
|
464
|
+
├── index.ts # Entry point, CLI argument parsing
|
|
465
|
+
├── server.ts # MCP server setup, roots protocol handling
|
|
466
|
+
├── config/
|
|
467
|
+
│ └── types.ts # Shared TypeScript types
|
|
468
|
+
├── lib/
|
|
469
|
+
│ ├── constants.ts # Configuration constants and limits
|
|
470
|
+
│ ├── errors.ts # Error handling utilities
|
|
471
|
+
│ ├── file-operations.ts# Core filesystem operations
|
|
472
|
+
│ ├── formatters.ts # Output formatting utilities
|
|
473
|
+
│ ├── fs-helpers.ts # Low-level filesystem helpers
|
|
474
|
+
│ ├── path-utils.ts # Path manipulation utilities
|
|
475
|
+
│ └── path-validation.ts# Security: path validation layer
|
|
476
|
+
├── schemas/
|
|
477
|
+
│ ├── common.ts # Shared Zod schemas
|
|
478
|
+
│ ├── inputs.ts # Input validation schemas
|
|
479
|
+
│ ├── outputs.ts # Output validation schemas
|
|
480
|
+
│ └── index.ts # Schema exports
|
|
481
|
+
├── tools/
|
|
482
|
+
│ ├── analyze-directory.ts
|
|
483
|
+
│ ├── directory-tree.ts
|
|
484
|
+
│ ├── get-file-info.ts
|
|
485
|
+
│ ├── list-allowed-dirs.ts
|
|
486
|
+
│ ├── list-directory.ts
|
|
487
|
+
│ ├── read-file.ts
|
|
488
|
+
│ ├── read-media-file.ts
|
|
489
|
+
│ ├── read-multiple-files.ts
|
|
490
|
+
│ ├── search-content.ts
|
|
491
|
+
│ ├── search-files.ts
|
|
492
|
+
│ └── index.ts # Tool registration
|
|
493
|
+
└── __tests__/ # Test files
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### Testing with MCP Inspector
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
npm run inspector
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
This launches the MCP Inspector for interactive testing of all tools.
|
|
503
|
+
|
|
504
|
+
## ❓ Troubleshooting
|
|
505
|
+
|
|
506
|
+
| Issue | Solution |
|
|
507
|
+
| --------------------------- | ---------------------------------------------------------------------------------------- |
|
|
508
|
+
| "Access denied" error | Ensure the path is within an allowed directory. Use `list_allowed_directories` to check. |
|
|
509
|
+
| "Path does not exist" error | Verify the path exists. Use `list_directory` to explore available files. |
|
|
510
|
+
| "File too large" error | Use `head` or `tail` parameters for partial reading, or increase `maxSize`. |
|
|
511
|
+
| "Binary file" warning | Use `read_media_file` for binary files, or set `skipBinary=false` in content search. |
|
|
512
|
+
| No directories configured | Pass directories as CLI arguments or ensure client provides roots via MCP protocol. |
|
|
513
|
+
| Symlink blocked | Symlinks that resolve outside allowed directories are blocked for security. |
|
|
514
|
+
| Regex timeout | Simplify the regex pattern or use `isLiteral=true` for literal string search. |
|
|
515
|
+
|
|
516
|
+
## 🤝 Contributing
|
|
517
|
+
|
|
518
|
+
Contributions are welcome! Please follow these steps:
|
|
519
|
+
|
|
520
|
+
1. Fork the repository
|
|
521
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
522
|
+
3. Run tests and linting (`npm run lint && npm run test`)
|
|
523
|
+
4. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
524
|
+
5. Push to the branch (`git push origin feature/amazing-feature`)
|
|
525
|
+
6. Open a Pull Request
|
|
526
|
+
|
|
527
|
+
### Code Style
|
|
528
|
+
|
|
529
|
+
- Use TypeScript with strict mode
|
|
530
|
+
- Follow ESLint configuration
|
|
531
|
+
- Use Prettier for formatting
|
|
532
|
+
- Write tests for new features
|
package/package.json
CHANGED