FS Context MCP Server
A secure, read-only MCP server for filesystem scanning, searching, and analysis with comprehensive security validation.
One-Click Install
Features
Directory listing (immediate contents)
File search with glob patterns
Content search with regex and context lines
File reading with head previews (first N lines)
Batch reads and metadata lookups in parallel
Security: path validation, symlink escape protection, read-only operations
When to Use
Task | Tool |
Explore project structure |
|
Find files |
|
Search for code patterns/text |
|
Read source code |
|
Batch read multiple files |
|
Get file metadata (size, dates) |
|
Batch get file metadata |
|
Check available directories |
|
Quick Start
NPX (recommended)
Allow the current working directory explicitly:
Or pass explicit directories:
If your MCP client supports the Roots protocol, you can omit directory arguments and let the client provide allowed directories. Otherwise, pass explicit directories or use --allow-cwd (if neither is provided, the server defaults to the current working directory).
VS Code (workspace folder)
Add to .vscode/mcp.json:
Installation
NPX (no install)
Global installation
From source
Directory Access and Resolution
Access is always restricted to explicitly allowed directories.
CLI directories are validated and added first (if provided).
--allow-cwdoptionally adds the current working directory.MCP Roots from the client are used next:
If CLI and/or
--allow-cwdare provided, only roots inside those baseline directories are accepted.If no baseline is provided, roots become the allowed directories.
If nothing is configured and the client provides no roots, the server defaults to the current working directory and logs a warning.
Notes:
Windows drive-relative paths like
C:pathare rejected. UseC:\pathorC:/path.Reserved Windows device names (e.g.,
CON,NUL) are blocked.
Configuration
All configuration is optional. Sizes in bytes, timeouts in milliseconds.
Environment Variables
Variable | Default | Description |
| 10MB | Max file size for read operations (range: 1MB-100MB) |
| 1MB | Max file size for content search (range: 100KB-10MB) |
| 30000 | Timeout for search/list operations (range: 100-3600000ms) |
| min(cpu cores, 8) | Search worker threads (range: 1-16) |
See CONFIGURATION.md for examples and CLI usage.
Tools
All tools return both human-readable text and structured JSON. Structured
responses include ok, optional error (with code, message, path,
suggestion), plus the tool-specific fields documented below.
roots
List all directories that this server can access.
Parameter | Type | Required | Default | Description |
(none) | - | - | - | - |
Returns: Allowed directory paths. Structured output includes ok and
directories.
ls
List the immediate contents of a directory (non-recursive). Omit path to use
the first allowed root. If pattern is provided, listing is recursive up to
maxDepth.
Parameter | Type | Required | Default | Description |
| string | No |
| Directory path to list (omit to use first root) |
| boolean | No |
| Include hidden files and directories |
| string[] | No |
| Glob patterns to exclude |
| string | No | - | Glob pattern to include (relative, no |
| number | No |
| Maximum depth when using pattern (0-100) |
| number | No |
| Maximum entries to return (1-100000) |
| number | No |
| Timeout in milliseconds |
| string | No |
| Sort by: |
| boolean | No |
| Include symlink target paths (symlinks are not followed) |
Returns: Entries with name, relativePath, type, size, and modified time.
Structured output includes ok, path, entries, and totalEntries.
find
Search for files using glob patterns. Omit path to search from the first
allowed root. find does not apply a built-in exclude list; scope your pattern
to avoid dependency/build directories (e.g., src/**/*.ts).
Parameter | Type | Required | Default | Description |
| string | No |
| Base directory to search from (omit to use first root) |
| string | Yes | - | Glob pattern (e.g., |
| number | No |
| Maximum matches to return (1-10000) |
Returns: Matching paths (relative) with size and modified date. Structured
output includes ok, results, totalMatches, and truncated.
read
Read the contents of a text file.
Parameter | Type | Required | Default | Description |
| string | Yes | - | File path to read |
| number | No | - | Read only first N lines |
Notes:
Reads are UTF-8 text only; binary files are rejected.
Full reads are capped by
MAX_FILE_SIZE(default 10MB). Whenheadis set, output stops at the line limit or size budget, whichever comes first.
Returns: File content plus structured metadata (ok, path, content,
truncated, totalLines).
read_many
Read multiple files in parallel.
Parameter | Type | Required | Default | Description |
| string[] | Yes | - | Array of file paths (max 100) |
| number | No | - | Read only first N lines of each file |
Notes:
Reads files as UTF-8 text; binary files are not filtered. Max size per file is capped by
MAX_FILE_SIZE(default 10MB).Total read budget across all files is capped at 100MB.
No binary detection is performed; use
readfor single-file safety checks.
Returns: Per-file content or error, plus structured summary (total,
succeeded, failed).
stat
Get detailed metadata about a file or directory.
Parameter | Type | Required | Default | Description |
| string | Yes | - | Path to file or directory |
Returns: name, path, type, size, timestamps (created/modified/accessed), permissions, hidden status, MIME type (for files), and symlink target (if applicable).
stat_many
Get metadata for multiple files/directories in parallel.
Parameter | Type | Required | Default | Description |
| string[] | Yes | - | Array of paths to query (max 100) |
Returns: Array of file info with individual success/error status, plus summary (total, succeeded, failed).
grep
Search for text content within files using regular expressions. Omit path to
search from the first allowed root.
Parameter | Type | Required | Default | Description |
| string | No |
| Base directory to search in (omit to use first root) |
| string | Yes | - | Regex pattern to search for |
| string | No |
| Glob pattern to filter files |
| string[] | No | built-in exclude list | Glob patterns to exclude (overrides built-in list) |
| boolean | No |
| Case-sensitive search |
| number | No |
| Maximum number of results |
| number | No | 1MB | Maximum file size to scan (default from |
| number | No |
| Maximum files to scan before stopping |
| number | No |
| Timeout in milliseconds |
| boolean | No |
| Skip likely-binary files |
| boolean | No |
| Include hidden files and directories |
| boolean | No |
| Include ignored dirs (node_modules, dist) and disable built-in excludes |
| number | No |
| Lines of context before/after match (0-10) |
| boolean | No |
| Match whole words only |
| boolean | No |
| Treat pattern as literal string (escape regex chars) |
| boolean | No |
| Match file patterns without slashes against basenames |
| boolean | No |
| Case-sensitive filename matching |
Returns: Matching lines with file path, line number, content, and optional
context. Structured output includes ok, matches, totalMatches, and
truncated.
Matched line content is trimmed to 200 characters.
Built-in exclude list (used by grep when excludePatterns is not provided and
includeIgnored is false) includes common dependency/build/output directories
and files: node_modules, dist, build, coverage, .git, .vscode,
.idea, .DS_Store, .next, .nuxt, .output, .svelte-kit, .cache,
.yarn, jspm_packages, bower_components, out, tmp, .temp,
npm-debug.log, yarn-debug.log, yarn-error.log, Thumbs.db. Pass
excludePatterns: [] or includeIgnored: true to disable it.
Error Codes
Code | Meaning |
| Path outside allowed roots |
| Path does not exist |
| Expected file, got directory |
| Expected directory, got file |
| File exceeds size limits |
| Operation timed out |
| Invalid glob/regex pattern |
| Invalid argument(s) |
| OS-level permission denied |
| Symlink escapes allowed roots |
| Unexpected error |
Client Configuration
Add to .vscode/mcp.json (recommended) or .vscode/settings.json:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
If your client supports MCP Roots, you can omit the path. Otherwise, pass a path or --allow-cwd.
Add to Cursor's MCP configuration:
Add to ~/.codex/config.toml:
If your client supports MCP Roots, you can omit the path. Otherwise, pass a path or --allow-cwd.
Add to Windsurf's MCP configuration:
Security
This server implements multiple layers of security:
Protection | Description |
Access control | Only explicitly allowed directories are accessible |
Path validation | All paths are validated before any filesystem operation |
Symlink protection | Symlinks that resolve outside allowed directories are blocked |
Path traversal prevention | Attempts to escape via |
Read-only operations | No writes, deletes, or modifications |
Safe regex | Regex validation with RE2 prevents ReDoS |
Size limits | Configurable limits prevent resource exhaustion |
Development
Prerequisites
Node.js >= 20.0.0
npm
Scripts
Command | Description |
| Compile TypeScript to JavaScript |
| Watch mode with tsx |
| Run compiled server |
| Run tests (node --test with tsx/esm) |
| Run tests in watch mode (node --test --watch) |
| Run tests with coverage (node --test --experimental-test-coverage) |
| Run node-tests (isolated checks) |
| Run ESLint |
| Format code with Prettier |
| TypeScript type checking |
| Test with MCP Inspector |
Project Structure
Troubleshooting
Issue | Solution |
"Access denied" error | Ensure the path is within an allowed directory. Use |
"Path does not exist" | Verify the path exists. Use |
"File too large" | Use |
"Binary file" warning |
|
No directories available | Pass explicit paths, use |
Symlink blocked | Symlinks that resolve outside allowed directories are blocked. |
Invalid regex/pattern | Simplify the regex or set |
Contributing
Contributions are welcome! Please follow these steps:
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Run format, lint, type-check, build, and tests (
npm run format && npm run lint && npm run type-check && npm run build && npm run test)Commit your changes (
git commit -m 'Add amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
Code Style
Use TypeScript with strict mode
Follow ESLint configuration
Use Prettier for formatting
Write tests for new features