@j0hanz/filesystem-context-mcp 1.0.0 → 1.0.2

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.
Files changed (79) hide show
  1. package/README.md +426 -224
  2. package/dist/__tests__/lib/errors.test.js +36 -1
  3. package/dist/__tests__/lib/errors.test.js.map +1 -1
  4. package/dist/__tests__/lib/file-operations.test.js +1 -1
  5. package/dist/__tests__/lib/file-operations.test.js.map +1 -1
  6. package/dist/__tests__/lib/formatters.test.d.ts +2 -0
  7. package/dist/__tests__/lib/formatters.test.d.ts.map +1 -0
  8. package/dist/__tests__/lib/formatters.test.js +251 -0
  9. package/dist/__tests__/lib/formatters.test.js.map +1 -0
  10. package/dist/__tests__/lib/image-parsing.test.d.ts +2 -0
  11. package/dist/__tests__/lib/image-parsing.test.d.ts.map +1 -0
  12. package/dist/__tests__/lib/image-parsing.test.js +265 -0
  13. package/dist/__tests__/lib/image-parsing.test.js.map +1 -0
  14. package/dist/__tests__/schemas/validators.test.d.ts +2 -0
  15. package/dist/__tests__/schemas/validators.test.d.ts.map +1 -0
  16. package/dist/__tests__/schemas/validators.test.js +142 -0
  17. package/dist/__tests__/schemas/validators.test.js.map +1 -0
  18. package/dist/config/types.d.ts +29 -3
  19. package/dist/config/types.d.ts.map +1 -1
  20. package/dist/config/types.js.map +1 -1
  21. package/dist/index.js +5 -12
  22. package/dist/index.js.map +1 -1
  23. package/dist/lib/constants.d.ts +8 -0
  24. package/dist/lib/constants.d.ts.map +1 -1
  25. package/dist/lib/constants.js +10 -0
  26. package/dist/lib/constants.js.map +1 -1
  27. package/dist/lib/errors.d.ts +2 -6
  28. package/dist/lib/errors.d.ts.map +1 -1
  29. package/dist/lib/errors.js +59 -58
  30. package/dist/lib/errors.js.map +1 -1
  31. package/dist/lib/file-operations.d.ts +0 -12
  32. package/dist/lib/file-operations.d.ts.map +1 -1
  33. package/dist/lib/file-operations.js +70 -207
  34. package/dist/lib/file-operations.js.map +1 -1
  35. package/dist/lib/fs-helpers.d.ts.map +1 -1
  36. package/dist/lib/fs-helpers.js +50 -11
  37. package/dist/lib/fs-helpers.js.map +1 -1
  38. package/dist/lib/image-parsing.d.ts +8 -0
  39. package/dist/lib/image-parsing.d.ts.map +1 -0
  40. package/dist/lib/image-parsing.js +119 -0
  41. package/dist/lib/image-parsing.js.map +1 -0
  42. package/dist/lib/path-validation.d.ts.map +1 -1
  43. package/dist/lib/path-validation.js +1 -4
  44. package/dist/lib/path-validation.js.map +1 -1
  45. package/dist/schemas/index.d.ts +1 -0
  46. package/dist/schemas/index.d.ts.map +1 -1
  47. package/dist/schemas/index.js +2 -0
  48. package/dist/schemas/index.js.map +1 -1
  49. package/dist/schemas/inputs.d.ts.map +1 -1
  50. package/dist/schemas/inputs.js +9 -4
  51. package/dist/schemas/inputs.js.map +1 -1
  52. package/dist/schemas/outputs.d.ts +12 -9
  53. package/dist/schemas/outputs.d.ts.map +1 -1
  54. package/dist/schemas/outputs.js +10 -3
  55. package/dist/schemas/outputs.js.map +1 -1
  56. package/dist/schemas/validators.d.ts +12 -0
  57. package/dist/schemas/validators.d.ts.map +1 -0
  58. package/dist/schemas/validators.js +35 -0
  59. package/dist/schemas/validators.js.map +1 -0
  60. package/dist/server.d.ts +3 -2
  61. package/dist/server.d.ts.map +1 -1
  62. package/dist/server.js +26 -15
  63. package/dist/server.js.map +1 -1
  64. package/dist/tools/analyze-directory.js +1 -1
  65. package/dist/tools/analyze-directory.js.map +1 -1
  66. package/dist/tools/directory-tree.js +1 -1
  67. package/dist/tools/directory-tree.js.map +1 -1
  68. package/dist/tools/list-directory.js +1 -1
  69. package/dist/tools/list-directory.js.map +1 -1
  70. package/dist/tools/read-file.d.ts.map +1 -1
  71. package/dist/tools/read-file.js +3 -0
  72. package/dist/tools/read-file.js.map +1 -1
  73. package/dist/tools/read-multiple-files.d.ts.map +1 -1
  74. package/dist/tools/read-multiple-files.js +3 -0
  75. package/dist/tools/read-multiple-files.js.map +1 -1
  76. package/dist/tools/search-content.d.ts.map +1 -1
  77. package/dist/tools/search-content.js +4 -3
  78. package/dist/tools/search-content.js.map +1 -1
  79. package/package.json +1 -1
package/README.md CHANGED
@@ -1,369 +1,571 @@
1
1
  # Filesystem Context MCP Server
2
2
 
3
- A secure Model Context Protocol (MCP) server for filesystem scanning, searching, and analysis. Built with TypeScript and the official MCP SDK.
3
+ A secure, read-only MCP server for filesystem scanning, searching, and analysis with comprehensive security validation.
4
4
 
5
- ## Security Features
5
+ [![npm version](https://img.shields.io/npm/v/@j0hanz/filesystem-context-mcp.svg)](https://www.npmjs.com/package/@j0hanz/filesystem-context-mcp)
6
+ [![License](https://img.shields.io/npm/l/@j0hanz/filesystem-context-mcp)](LICENSE)
7
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue)](https://www.typescriptlang.org/)
9
+ [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-1.12.0-purple)](https://modelcontextprotocol.io)
6
10
 
7
- - **Path Validation**: All file operations are restricted to explicitly allowed directories
8
- - **Symlink Attack Prevention**: Symlinks are resolved before validation to prevent escaping allowed directories
9
- - **Path Traversal Protection**: Attempts to access paths outside allowed directories are blocked
10
- - **Read-Only Operations**: All tools are marked with `readOnlyHint` annotation
11
+ ## One-Click Install
11
12
 
12
- ## Features
13
+ [![Install with NPX in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=filesystem-context&inputs=%5B%5D&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Ffilesystem-context-mcp%40latest%22%2C%22%24%7BworkspaceFolder%7D%22%5D%7D)[![Install with NPX in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=filesystem-context&inputs=%5B%5D&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Ffilesystem-context-mcp%40latest%22%2C%22%24%7BworkspaceFolder%7D%22%5D%7D&quality=insiders)
13
14
 
14
- This server provides the following tools for filesystem operations:
15
+ [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/install-mcp?name=filesystem-context&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBqMGhhbnovZmlsZXN5c3RlbS1jb250ZXh0LW1jcEBsYXRlc3QiLCIke3dvcmtzcGFjZUZvbGRlcn0iXX0=)
15
16
 
16
- | Tool | Description |
17
- | -------------------------- | ------------------------------------------------------------ |
18
- | `list_allowed_directories` | List directories this server is allowed to access |
19
- | `list_directory` | List files and directories with optional recursive traversal |
20
- | `search_files` | Search for files using glob patterns |
21
- | `read_file` | Read file contents with optional line range |
22
- | `read_multiple_files` | Read multiple files in parallel efficiently |
23
- | `get_file_info` | Get detailed file/directory metadata |
24
- | `search_content` | Search for text within files using regex patterns |
25
- | `analyze_directory` | Analyze directory structure and get statistics |
26
- | `directory_tree` | Get JSON tree structure of a directory |
27
- | `read_media_file` | Read binary/media files as base64-encoded data |
17
+ ## Features
28
18
 
29
- ## Installation
19
+ | Feature | Description |
20
+ | -------------------------- | ---------------------------------------------------------------------- |
21
+ | 📂 **Directory Listing** | List and explore directory contents with recursive support |
22
+ | 🔍 **File Search** | Find files using glob patterns like `**/*.ts` |
23
+ | 📝 **Content Search** | Search text within files using regex with context lines |
24
+ | 📊 **Directory Analysis** | Get statistics, file types, largest files, and recently modified files |
25
+ | 🌳 **Directory Tree** | JSON tree structure optimized for AI parsing |
26
+ | 📄 **File Reading** | Read single or multiple files with head/tail and line range support |
27
+ | 🖼️ **Media File Support** | Read binary files (images, audio, video) as base64 |
28
+ | 🔒 **Security First** | Path validation, symlink escape protection, and access control |
29
+ | ⚡ **Parallel Operations** | Efficient batch file reading with configurable concurrency |
30
30
 
31
- ```bash
32
- # Clone the repository
33
- git clone <repository-url>
34
- cd filesystem-context-mcp
31
+ ## 🎯 When to Use
35
32
 
36
- # Install dependencies
37
- npm install
33
+ | Task | Tool |
34
+ | -------------------------------- | -------------------------- |
35
+ | Explore project structure | `list_directory` |
36
+ | Find specific file types | `search_files` |
37
+ | Search for code patterns/text | `search_content` |
38
+ | Understand codebase statistics | `analyze_directory` |
39
+ | Get AI-friendly project overview | `directory_tree` |
40
+ | Read source code | `read_file` |
41
+ | Batch read multiple files | `read_multiple_files` |
42
+ | Get file metadata (size, dates) | `get_file_info` |
43
+ | Read images or binary files | `read_media_file` |
44
+ | Check available directories | `list_allowed_directories` |
38
45
 
39
- # Build the project
40
- npm run build
41
- ```
46
+ ## 🚀 Quick Start
42
47
 
43
- ## Usage
44
-
45
- ### Running the Server
46
-
47
- **Important**: You must specify at least one allowed directory when starting the server:
48
+ ### NPX (Recommended - Zero Config)
48
49
 
49
50
  ```bash
50
- # Production mode - specify allowed directories
51
- node dist/index.js /path/to/allowed/dir1 /path/to/allowed/dir2
52
-
53
- # Development mode with tsx
54
- npx tsx src/index.ts /path/to/allowed/dir
55
-
56
- # Windows example
57
- node dist/index.js C:\Users\Projects C:\Users\Documents
51
+ # Works in current directory automatically!
52
+ npx -y @j0hanz/filesystem-context-mcp@latest
58
53
  ```
59
54
 
60
- ### Testing with MCP Inspector
55
+ Or specify directories explicitly:
61
56
 
62
57
  ```bash
63
- npm run inspector
58
+ npx -y @j0hanz/filesystem-context-mcp@latest /path/to/your/project
64
59
  ```
65
60
 
66
- Then connect to the server via stdio, providing allowed directories as arguments.
67
-
68
- ### Configuration with MCP Clients
61
+ ### VS Code (with workspace folder)
69
62
 
70
- #### Claude Desktop
71
-
72
- Add to your Claude Desktop config (`%APPDATA%\Claude\claude_desktop_config.json` on Windows):
63
+ Add to your VS Code settings (`.vscode/mcp.json`):
73
64
 
74
65
  ```json
75
66
  {
76
- "mcpServers": {
67
+ "servers": {
77
68
  "filesystem-context": {
78
- "command": "node",
69
+ "command": "npx",
79
70
  "args": [
80
- "C:\\path\\to\\filesystem-context-mcp\\dist\\index.js",
81
- "C:\\Users\\Projects",
82
- "C:\\Users\\Documents"
71
+ "-y",
72
+ "@j0hanz/filesystem-context-mcp@latest",
73
+ "${workspaceFolder}"
83
74
  ]
84
75
  }
85
76
  }
86
77
  }
87
78
  ```
88
79
 
89
- #### VS Code with Copilot
80
+ > **Tip:** `${workspaceFolder}` automatically uses your current VS Code workspace. You can also omit it and the server will use its current working directory.
81
+
82
+ ### Claude Desktop
90
83
 
91
- Add to your VS Code settings or `.vscode/mcp.json`:
84
+ Add to your Claude Desktop configuration (`claude_desktop_config.json`):
92
85
 
93
86
  ```json
94
87
  {
95
- "mcp": {
96
- "servers": {
97
- "filesystem-context": {
98
- "command": "node",
99
- "args": ["${workspaceFolder}/dist/index.js", "${workspaceFolder}"]
100
- }
88
+ "mcpServers": {
89
+ "filesystem-context": {
90
+ "command": "npx",
91
+ "args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
101
92
  }
102
93
  }
103
94
  }
104
95
  ```
105
96
 
106
- ## Tool Documentation
97
+ > **Note:** Claude Desktop will use the current working directory automatically. No path arguments needed!
107
98
 
108
- All tools return both a human-readable `content` text block and a machine-friendly `structuredContent` payload (with `outputSchema` declared in the server).
99
+ ## 📦 Installation
109
100
 
110
- ### list_directory
101
+ ### NPX (No Installation)
111
102
 
112
- List all files and directories in a given path.
103
+ ```bash
104
+ npx -y @j0hanz/filesystem-context-mcp@latest /path/to/dir1 /path/to/dir2
105
+ ```
113
106
 
114
- **Parameters:**
107
+ ### Global Installation
115
108
 
116
- - `path` (string, required): The directory path to list
117
- - `recursive` (boolean, default: false): Whether to list recursively
118
- - `includeHidden` (boolean, default: false): Include hidden files (dotfiles)
119
- - `maxDepth` (number, default: 10): Maximum depth for recursive listing
120
- - `maxEntries` (number, optional): Maximum number of entries to return (prevents huge responses)
109
+ ```bash
110
+ npm install -g @j0hanz/filesystem-context-mcp
111
+ filesystem-context-mcp /path/to/your/project
112
+ ```
121
113
 
122
- **Example:**
114
+ ### From Source
123
115
 
124
- ```json
125
- {
126
- "path": "C:\\Users\\Projects",
127
- "recursive": true,
128
- "maxDepth": 2
129
- }
116
+ ```bash
117
+ git clone https://github.com/j0hanz/filesystem-context-mcp-server.git
118
+ cd filesystem-context-mcp-server
119
+ npm install
120
+ npm run build
121
+ node dist/index.js /path/to/your/project
130
122
  ```
131
123
 
132
- ### search_files
124
+ ## ⚙️ Configuration
133
125
 
134
- Search for files and directories matching a glob pattern.
126
+ ### Directory Resolution (Priority Order)
135
127
 
136
- **Parameters:**
128
+ The server determines which directories to access in this order:
137
129
 
138
- - `path` (string, required): Base directory to search from
139
- - `pattern` (string, required): Glob pattern to match (e.g. `**/*.ts`)
140
- - `excludePatterns` (string[], optional): Glob patterns to exclude
141
- - `maxResults` (number, optional): Maximum number of matches to return (prevents huge responses)
130
+ 1. **CLI Arguments** - Explicitly passed paths take highest priority
131
+ 2. **MCP Roots Protocol** - Directories provided by the MCP client
132
+ 3. **Current Working Directory** - Automatic fallback for plug-and-play experience
142
133
 
143
- **Example:**
134
+ This means you can run the server with zero configuration and it will work!
144
135
 
145
- ```json
146
- {
147
- "path": "./src",
148
- "pattern": "**/*.ts",
149
- "excludePatterns": ["**/*.test.ts"]
150
- }
136
+ ### Command Line Arguments
137
+
138
+ Optionally specify one or more directory paths as arguments:
139
+
140
+ ```bash
141
+ filesystem-context-mcp /home/user/project /home/user/docs
151
142
  ```
152
143
 
153
- ### read_file
144
+ ### MCP Roots Protocol
145
+
146
+ If no CLI arguments are provided, the server will use the MCP Roots protocol to receive allowed directories from the client (if supported).
147
+
148
+ ### Zero-Config Mode
149
+
150
+ If neither CLI arguments nor MCP Roots provide directories, the server automatically uses the current working directory. This makes it truly plug-and-play!
151
+
152
+ ### Environment Variables
153
+
154
+ | Variable | Description |
155
+ | ---------- | --------------------------------------------- |
156
+ | `NODE_ENV` | Set to `production` for optimized performance |
157
+
158
+ ## 🔧 Tools
159
+
160
+ ### `list_allowed_directories`
154
161
 
155
- Read the contents of a file (optionally a line range).
162
+ List all directories that this server is allowed to access.
163
+
164
+ | Parameter | Type | Required | Default | Description |
165
+ | --------- | ---- | -------- | ------- | ---------------------- |
166
+ | _(none)_ | - | - | - | No parameters required |
167
+
168
+ **Returns:** Array of allowed directory paths.
169
+
170
+ ---
171
+
172
+ ### `list_directory`
173
+
174
+ List contents of a directory with optional recursive listing.
175
+
176
+ | Parameter | Type | Required | Default | Description |
177
+ | ----------------------- | ------- | -------- | ------- | ------------------------------------------- |
178
+ | `path` | string | ✅ | - | Directory path to list |
179
+ | `recursive` | boolean | ❌ | `false` | List recursively |
180
+ | `includeHidden` | boolean | ❌ | `false` | Include hidden files |
181
+ | `maxDepth` | number | ❌ | `10` | Maximum depth for recursive listing (0-100) |
182
+ | `maxEntries` | number | ❌ | - | Maximum entries to return (1-100,000) |
183
+ | `sortBy` | string | ❌ | `name` | Sort by: `name`, `size`, `modified`, `type` |
184
+ | `includeSymlinkTargets` | boolean | ❌ | `false` | Include symlink target paths |
156
185
 
157
- **Parameters:**
186
+ **Returns:** List of entries with name, type, size, and modified date.
158
187
 
159
- - `path` (string, required): Path to the file
160
- - `encoding` (string, default: "utf-8"): File encoding
161
- - `maxSize` (number, default: 10485760): Maximum file size in bytes (default 10MB)
162
- - `lineStart` (number, optional): Start line (1-based)
163
- - `lineEnd` (number, optional): End line (inclusive)
188
+ ---
189
+
190
+ ### `search_files`
191
+
192
+ Search for files using glob patterns.
193
+
194
+ | Parameter | Type | Required | Default | Description |
195
+ | ----------------- | -------- | -------- | ------- | --------------------------------------------- |
196
+ | `path` | string | ✅ | - | Base directory to search from |
197
+ | `pattern` | string | ✅ | - | Glob pattern (e.g., `**/*.ts`, `src/**/*.js`) |
198
+ | `excludePatterns` | string[] | ❌ | `[]` | Patterns to exclude |
199
+ | `maxResults` | number | ❌ | - | Maximum matches to return (1-10,000) |
200
+ | `sortBy` | string | ❌ | `path` | Sort by: `name`, `size`, `modified`, `path` |
201
+ | `maxDepth` | number | ❌ | - | Maximum directory depth to search (1-100) |
202
+
203
+ **Returns:** List of matching files with path, type, size, and modified date.
164
204
 
165
205
  **Example:**
166
206
 
167
207
  ```json
168
208
  {
169
- "path": "./src/index.ts",
170
- "lineStart": 1,
171
- "lineEnd": 50
209
+ "path": "/project",
210
+ "pattern": "**/*.ts",
211
+ "excludePatterns": ["node_modules/**", "dist/**"]
172
212
  }
173
213
  ```
174
214
 
175
- ### get_file_info
215
+ ---
216
+
217
+ ### `read_file`
218
+
219
+ Read the contents of a text file.
176
220
 
177
- Get detailed information about a file or directory.
221
+ | Parameter | Type | Required | Default | Description |
222
+ | ----------- | ------ | -------- | ------- | ------------------------------------------------ |
223
+ | `path` | string | ✅ | - | File path to read |
224
+ | `encoding` | string | ❌ | `utf-8` | File encoding (`utf-8`, `ascii`, `base64`, etc.) |
225
+ | `maxSize` | number | ❌ | 10MB | Maximum file size in bytes |
226
+ | `lineStart` | number | ❌ | - | Start line (1-indexed) for reading a range |
227
+ | `lineEnd` | number | ❌ | - | End line (inclusive) for reading a range |
228
+ | `head` | number | ❌ | - | Read only first N lines |
229
+ | `tail` | number | ❌ | - | Read only last N lines |
178
230
 
179
- **Parameters:**
231
+ > **Note:** Cannot specify both `head` and `tail` simultaneously. Use `lineStart`/`lineEnd` for range reading.
180
232
 
181
- - `path` (string, required): Path to the file or directory
233
+ **Returns:** File contents as text.
182
234
 
183
- **Returns:** File metadata including size, timestamps, permissions, and type.
235
+ ---
184
236
 
185
- ### search_content
237
+ ### `read_multiple_files`
186
238
 
187
- Search for text content within files using a regular expression.
239
+ Read multiple files in parallel for efficient batch operations.
188
240
 
189
- **Parameters:**
241
+ | Parameter | Type | Required | Default | Description |
242
+ | ---------- | -------- | -------- | ------- | ------------------------------------ |
243
+ | `paths` | string[] | ✅ | - | Array of file paths (max 100) |
244
+ | `encoding` | string | ❌ | `utf-8` | File encoding |
245
+ | `maxSize` | number | ❌ | 10MB | Maximum file size per file |
246
+ | `head` | number | ❌ | - | Read only first N lines of each file |
247
+ | `tail` | number | ❌ | - | Read only last N lines of each file |
190
248
 
191
- - `path` (string, required): Base directory to search in
192
- - `pattern` (string, required): Regular expression pattern
193
- - `filePattern` (string, default: "\*_/_"): Glob pattern to filter files
194
- - `excludePatterns` (string[], optional): Glob patterns to exclude (e.g. `node_modules/**`)
195
- - `caseSensitive` (boolean, default: false): Case-sensitive search
196
- - `maxResults` (number, default: 100): Maximum number of matches to return
197
- - `maxFileSize` (number, optional): Maximum file size in bytes to scan (default 1MB)
198
- - `maxFilesScanned` (number, optional): Maximum number of files to scan before stopping
199
- - `timeoutMs` (number, optional): Timeout in milliseconds for the search operation
200
- - `skipBinary` (boolean, default: true): Skip likely-binary files
249
+ **Returns:** Array of results with content or error for each file.
250
+
251
+ ---
252
+
253
+ ### `get_file_info`
254
+
255
+ Get detailed metadata about a file or directory.
256
+
257
+ | Parameter | Type | Required | Default | Description |
258
+ | --------- | ------ | -------- | ------- | ------------------------- |
259
+ | `path` | string | ✅ | - | Path to file or directory |
260
+
261
+ **Returns:** Metadata including name, type, size, created/modified/accessed timestamps, permissions, MIME type, and symlink target (if applicable).
262
+
263
+ ---
264
+
265
+ ### `search_content`
266
+
267
+ Search for text content within files using regular expressions.
268
+
269
+ | Parameter | Type | Required | Default | Description |
270
+ | ----------------- | -------- | -------- | ------- | ------------------------------------------------ |
271
+ | `path` | string | ✅ | - | Base directory to search in |
272
+ | `pattern` | string | ✅ | - | Regex pattern to search for |
273
+ | `filePattern` | string | ❌ | `**/*` | Glob pattern to filter files |
274
+ | `excludePatterns` | string[] | ❌ | `[]` | Glob patterns to exclude |
275
+ | `caseSensitive` | boolean | ❌ | `false` | Case-sensitive search |
276
+ | `maxResults` | number | ❌ | `100` | Maximum number of results (1-10,000) |
277
+ | `maxFileSize` | number | ❌ | 1MB | Maximum file size to scan |
278
+ | `maxFilesScanned` | number | ❌ | - | Maximum files to scan before stopping |
279
+ | `timeoutMs` | number | ❌ | - | Timeout in milliseconds (100-3,600,000) |
280
+ | `skipBinary` | boolean | ❌ | `true` | Skip binary files |
281
+ | `contextLines` | number | ❌ | `0` | Lines of context before/after match (0-10) |
282
+ | `wholeWord` | boolean | ❌ | `false` | Match whole words only |
283
+ | `isLiteral` | boolean | ❌ | `false` | Treat pattern as literal string (escape special) |
284
+
285
+ **Returns:** Matching lines with file path, line number, content, and optional context.
201
286
 
202
287
  **Example:**
203
288
 
204
289
  ```json
205
290
  {
206
- "path": "./src",
207
- "pattern": "TODO:",
291
+ "path": "/project/src",
292
+ "pattern": "TODO|FIXME",
208
293
  "filePattern": "**/*.ts",
209
- "maxResults": 50
294
+ "contextLines": 2
210
295
  }
211
296
  ```
212
297
 
213
- ### analyze_directory
298
+ ---
214
299
 
215
- Analyze a directory structure and compute summary statistics.
300
+ ### `analyze_directory`
216
301
 
217
- **Parameters:**
302
+ Analyze a directory structure and return statistics.
218
303
 
219
- - `path` (string, required): Directory path to analyze
220
- - `maxDepth` (number, default: 10): Maximum depth to traverse
221
- - `topN` (number, default: 10): Number of “top” items to return (largest/recent)
304
+ | Parameter | Type | Required | Default | Description |
305
+ | ----------------- | -------- | -------- | ------- | -------------------------------------- |
306
+ | `path` | string | ✅ | - | Directory to analyze |
307
+ | `maxDepth` | number | ❌ | `10` | Maximum depth to analyze (0-100) |
308
+ | `topN` | number | ❌ | `10` | Number of top items to return (1-1000) |
309
+ | `excludePatterns` | string[] | ❌ | `[]` | Glob patterns to exclude |
310
+ | `includeHidden` | boolean | ❌ | `false` | Include hidden files and directories |
222
311
 
223
- **Returns:** Statistics including file counts by extension, total size, largest files, and recently modified files.
312
+ **Returns:** Statistics including total files/directories, total size, file type distribution, largest files, and recently modified files.
224
313
 
225
- ### list_allowed_directories
314
+ ---
226
315
 
227
- List all directories that this server is allowed to access.
316
+ ### `directory_tree`
228
317
 
229
- **Parameters:** None
318
+ Get a JSON tree structure of a directory, optimized for AI parsing.
230
319
 
231
- **Returns:** Array of allowed directory paths. Use this to understand the scope of available file operations.
320
+ | Parameter | Type | Required | Default | Description |
321
+ | ----------------- | -------- | -------- | ------- | --------------------------------------- |
322
+ | `path` | string | ✅ | - | Directory path to build tree from |
323
+ | `maxDepth` | number | ❌ | `5` | Maximum depth to traverse (0-50) |
324
+ | `excludePatterns` | string[] | ❌ | `[]` | Glob patterns to exclude |
325
+ | `includeHidden` | boolean | ❌ | `false` | Include hidden files and directories |
326
+ | `includeSize` | boolean | ❌ | `false` | Include file sizes in the tree |
327
+ | `maxFiles` | number | ❌ | - | Maximum total files to include (1-100k) |
232
328
 
233
- ### read_multiple_files
329
+ **Returns:** Hierarchical tree structure with file/directory nodes.
234
330
 
235
- Read the contents of multiple files in parallel. More efficient than reading files one by one.
331
+ ---
236
332
 
237
- **Parameters:**
333
+ ### `read_media_file`
238
334
 
239
- - `paths` (string[], required): Array of file paths to read
240
- - `encoding` (string, default: "utf-8"): File encoding
241
- - `maxSize` (number, default: 10485760): Maximum file size in bytes per file (default 10MB)
335
+ Read a binary/media file and return it as base64-encoded data.
242
336
 
243
- **Example:**
337
+ | Parameter | Type | Required | Default | Description |
338
+ | --------- | ------ | -------- | ------- | -------------------------------------- |
339
+ | `path` | string | ✅ | - | Path to the media file |
340
+ | `maxSize` | number | ❌ | 50MB | Maximum file size in bytes (max 500MB) |
341
+
342
+ **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.
343
+
344
+ **Returns:** Base64-encoded data with MIME type, size, and dimensions (for images).
345
+
346
+ ## 🔌 Client Configuration
347
+
348
+ <details>
349
+ <summary><b>VS Code</b></summary>
350
+
351
+ Add to `.vscode/mcp.json` (recommended) or `.vscode/settings.json`:
244
352
 
245
353
  ```json
246
354
  {
247
- "paths": ["./src/index.ts", "./src/server.ts", "./package.json"],
248
- "encoding": "utf-8"
355
+ "servers": {
356
+ "filesystem-context": {
357
+ "command": "npx",
358
+ "args": [
359
+ "-y",
360
+ "@j0hanz/filesystem-context-mcp@latest",
361
+ "${workspaceFolder}"
362
+ ]
363
+ }
364
+ }
249
365
  }
250
366
  ```
251
367
 
252
- **Returns:** Array of results, each containing the file path and either its content or an error message. Individual file errors do not fail the entire operation.
253
-
254
- ### directory_tree
368
+ > **Note:** `${workspaceFolder}` is expanded by VS Code to the current workspace path.
255
369
 
256
- Get a JSON tree structure of a directory. More efficient for AI parsing than flat file lists.
370
+ </details>
257
371
 
258
- **Parameters:**
372
+ <details>
373
+ <summary><b>Claude Desktop</b></summary>
259
374
 
260
- - `path` (string, required): Directory path to build tree from
261
- - `maxDepth` (number, default: 5): Maximum depth to traverse
262
- - `excludePatterns` (string[], optional): Glob patterns to exclude (e.g., `node_modules`, `*.log`)
263
- - `includeHidden` (boolean, default: false): Include hidden files and directories
264
- - `includeSize` (boolean, default: false): Include file sizes in the tree
265
-
266
- **Example:**
375
+ **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
376
+ **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
267
377
 
268
378
  ```json
269
379
  {
270
- "path": "./src",
271
- "maxDepth": 3,
272
- "excludePatterns": ["__tests__"],
273
- "includeSize": true
380
+ "mcpServers": {
381
+ "filesystem-context": {
382
+ "command": "npx",
383
+ "args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
384
+ }
385
+ }
274
386
  }
275
387
  ```
276
388
 
277
- **Returns:** Nested tree structure with files and directories, useful for understanding project structure.
389
+ </details>
390
+
391
+ <details>
392
+ <summary><b>Cursor</b></summary>
278
393
 
279
- ### read_media_file
394
+ Add to Cursor's MCP configuration:
280
395
 
281
- Read a binary/media file (image, audio, video, etc.) and return it as base64-encoded data.
396
+ ```json
397
+ {
398
+ "mcpServers": {
399
+ "filesystem-context": {
400
+ "command": "npx",
401
+ "args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
402
+ }
403
+ }
404
+ }
405
+ ```
282
406
 
283
- **Parameters:**
407
+ </details>
284
408
 
285
- - `path` (string, required): Path to the media file
286
- - `maxSize` (number, default: 52428800): Maximum file size in bytes (default 50MB)
409
+ <details>
410
+ <summary><b>Windsurf</b></summary>
287
411
 
288
- **Example:**
412
+ Add to Windsurf's MCP configuration:
289
413
 
290
414
  ```json
291
415
  {
292
- "path": "./assets/logo.png"
416
+ "mcpServers": {
417
+ "filesystem-context": {
418
+ "command": "npx",
419
+ "args": ["-y", "@j0hanz/filesystem-context-mcp@latest"]
420
+ }
421
+ }
293
422
  }
294
423
  ```
295
424
 
296
- **Returns:** Object containing the file path, MIME type, size in bytes, and base64-encoded data.
425
+ </details>
297
426
 
298
- ## Development
427
+ ## 🔒 Security
299
428
 
300
- ```bash
301
- # Run in development mode with hot reload
302
- npm run dev
429
+ This server implements multiple layers of security:
303
430
 
304
- # Type checking
305
- npm run type-check
431
+ | Protection | Description |
432
+ | ----------------------------- | ------------------------------------------------------------------------- |
433
+ | **Access Control** | Only explicitly allowed directories are accessible |
434
+ | **Path Validation** | All paths are validated before any filesystem operation |
435
+ | **Symlink Protection** | Symlinks that resolve outside allowed directories are blocked |
436
+ | **Path Traversal Prevention** | Attempts to escape via `../` are detected and blocked |
437
+ | **Read-Only Operations** | Server only performs read operations—no writes, deletes, or modifications |
438
+ | **Safe Regex** | Regular expressions are validated to prevent ReDoS attacks |
439
+ | **Size Limits** | Configurable limits prevent resource exhaustion |
306
440
 
307
- # Linting
308
- npm run lint
441
+ ### Security Model
309
442
 
310
- # Build for production
311
- npm run build
443
+ ```text
444
+ ┌─────────────────────────────────────────────────────────┐
445
+ │ MCP Client │
446
+ └─────────────────────┬───────────────────────────────────┘
447
+
448
+
449
+ ┌─────────────────────────────────────────────────────────┐
450
+ │ Filesystem Context MCP Server │
451
+ │ ┌───────────────────────────────────────────────────┐ │
452
+ │ │ Path Validation Layer │ │
453
+ │ │ • Normalize paths │ │
454
+ │ │ • Check against allowed directories │ │
455
+ │ │ • Resolve and validate symlinks │ │
456
+ │ │ • Block traversal attempts │ │
457
+ │ └───────────────────────────────────────────────────┘ │
458
+ │ │ │
459
+ │ ▼ │
460
+ │ ┌───────────────────────────────────────────────────┐ │
461
+ │ │ Read-Only File Operations │ │
462
+ │ └───────────────────────────────────────────────────┘ │
463
+ └─────────────────────────────────────────────────────────┘
464
+
465
+
466
+ ┌─────────────────────────────────────────────────────────┐
467
+ │ Allowed Directories Only │
468
+ │ /home/user/project ✅ │
469
+ │ /home/user/docs ✅ │
470
+ │ /etc/passwd ❌ (blocked) │
471
+ │ ../../../etc ❌ (blocked) │
472
+ └─────────────────────────────────────────────────────────┘
312
473
  ```
313
474
 
314
- ## Architecture
475
+ ## 🛠️ Development
315
476
 
316
- ```text
317
- filesystem-context-mcp/
318
- ├── src/
319
- │ ├── index.ts # Main server entry point
320
- │ └── lib/
321
- │ ├── types.ts # TypeScript interfaces
322
- │ ├── path-utils.ts # Path normalization utilities
323
- │ ├── path-validation.ts # Security validation
324
- │ ├── file-operations.ts # Core file operations
325
- │ └── formatters.ts # Output formatting
326
- ├── dist/ # Compiled JavaScript output
327
- ├── package.json # Project configuration
328
- ├── tsconfig.json # TypeScript configuration
329
- └── README.md # This file
330
- ```
477
+ ### Prerequisites
478
+
479
+ - Node.js >= 20.0.0
480
+ - npm
331
481
 
332
- The server uses:
482
+ ### Scripts
333
483
 
334
- - **Transport**: StdioServerTransport for local MCP client integration
335
- - **Schema Validation**: Zod for input/output validation
336
- - **Glob Matching**: `fast-glob` for file pattern matching and `minimatch` for pattern testing
337
- - **Security**: Path validation against allowed directories with symlink resolution
484
+ | Command | Description |
485
+ | ----------------------- | -------------------------------- |
486
+ | `npm run build` | Compile TypeScript to JavaScript |
487
+ | `npm run dev` | Watch mode with tsx |
488
+ | `npm run start` | Run compiled server |
489
+ | `npm run test` | Run tests with Vitest |
490
+ | `npm run test:watch` | Run tests in watch mode |
491
+ | `npm run test:coverage` | Run tests with coverage report |
492
+ | `npm run lint` | Run ESLint |
493
+ | `npm run format` | Format code with Prettier |
494
+ | `npm run type-check` | TypeScript type checking |
495
+ | `npm run inspector` | Test with MCP Inspector |
338
496
 
339
- ## Security Considerations
497
+ ### Project Structure
340
498
 
341
- - **Required Configuration**: You must specify allowed directories via command line arguments
342
- - **Path Validation**: All paths are validated against allowed directories before any operation
343
- - **Symlink Protection**: Symlinks are resolved to their real paths before validation
344
- - **Read-Only**: The server only performs read operations (no file modifications)
345
- - **Annotations**: All tools are marked with `readOnlyHint: true` for MCP client awareness
499
+ ```text
500
+ src/
501
+ ├── index.ts # Entry point, CLI argument parsing
502
+ ├── server.ts # MCP server setup, roots protocol handling
503
+ ├── config/
504
+ │ └── types.ts # Shared TypeScript types
505
+ ├── lib/
506
+ │ ├── constants.ts # Configuration constants and limits
507
+ │ ├── errors.ts # Error handling utilities
508
+ │ ├── file-operations.ts# Core filesystem operations
509
+ │ ├── formatters.ts # Output formatting utilities
510
+ │ ├── fs-helpers.ts # Low-level filesystem helpers
511
+ │ ├── image-parsing.ts # Image dimension parsing
512
+ │ ├── path-utils.ts # Path manipulation utilities
513
+ │ └── path-validation.ts# Security: path validation layer
514
+ ├── schemas/
515
+ │ ├── common.ts # Shared Zod schemas
516
+ │ ├── inputs.ts # Input validation schemas
517
+ │ ├── outputs.ts # Output validation schemas
518
+ │ ├── validators.ts # Custom validation functions
519
+ │ └── index.ts # Schema exports
520
+ ├── tools/
521
+ │ ├── analyze-directory.ts
522
+ │ ├── directory-tree.ts
523
+ │ ├── get-file-info.ts
524
+ │ ├── list-allowed-dirs.ts
525
+ │ ├── list-directory.ts
526
+ │ ├── read-file.ts
527
+ │ ├── read-media-file.ts
528
+ │ ├── read-multiple-files.ts
529
+ │ ├── search-content.ts
530
+ │ ├── search-files.ts
531
+ │ └── index.ts # Tool registration
532
+ └── __tests__/ # Test files
533
+ ```
534
+
535
+ ### Testing with MCP Inspector
346
536
 
347
- ## Troubleshooting
537
+ ```bash
538
+ npm run inspector
539
+ ```
348
540
 
349
- ### Server not starting
541
+ This launches the MCP Inspector for interactive testing of all tools.
350
542
 
351
- 1. Ensure Node.js >= 20.0.0 is installed
352
- 2. Run `npm install` to install dependencies
353
- 3. Run `npm run build` to compile TypeScript
543
+ ## Troubleshooting
354
544
 
355
- ### Connection issues with MCP clients
545
+ | Issue | Solution |
546
+ | --------------------------- | ---------------------------------------------------------------------------------------- |
547
+ | "Access denied" error | Ensure the path is within an allowed directory. Use `list_allowed_directories` to check. |
548
+ | "Path does not exist" error | Verify the path exists. Use `list_directory` to explore available files. |
549
+ | "File too large" error | Use `head` or `tail` parameters for partial reading, or increase `maxSize`. |
550
+ | "Binary file" warning | Use `read_media_file` for binary files, or set `skipBinary=false` in content search. |
551
+ | Unexpected directory access | Server defaults to CWD if no args/roots provided. Pass explicit paths to restrict. |
552
+ | Symlink blocked | Symlinks that resolve outside allowed directories are blocked for security. |
553
+ | Regex timeout | Simplify the regex pattern or use `isLiteral=true` for literal string search. |
356
554
 
357
- 1. Check the path in your client configuration is correct
358
- 2. Ensure the server is built (`npm run build`)
359
- 3. Test with MCP Inspector first: `npx @modelcontextprotocol/inspector`
555
+ ## 🤝 Contributing
360
556
 
361
- ### File access errors
557
+ Contributions are welcome! Please follow these steps:
362
558
 
363
- 1. Verify the server process has read permissions
364
- 2. Check that file paths are absolute or relative to the working directory
365
- 3. Some files (binary, locked) may be skipped during search operations
559
+ 1. Fork the repository
560
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
561
+ 3. Run tests and linting (`npm run lint && npm run test`)
562
+ 4. Commit your changes (`git commit -m 'Add amazing feature'`)
563
+ 5. Push to the branch (`git push origin feature/amazing-feature`)
564
+ 6. Open a Pull Request
366
565
 
367
- ## License
566
+ ### Code Style
368
567
 
369
- MIT
568
+ - Use TypeScript with strict mode
569
+ - Follow ESLint configuration
570
+ - Use Prettier for formatting
571
+ - Write tests for new features