Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@j0hanz/filesystem-context-mcp

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@j0hanz/filesystem-context-mcp

🔍 Read-only MCP server for secure filesystem exploration, searching, and analysis

latest
Source
npmnpm
Version
1.3.8
Version published
Maintainers
1
Created
Source

Filesystem Context MCP Server

Filesystem Context MCP Server Logo

A secure, read-only MCP server for filesystem scanning, searching, and analysis with comprehensive security validation.

npm version License Node.js TypeScript MCP SDK

One-Click Install

Install with NPX in VS CodeInstall with NPX in VS Code Insiders

Install in Cursor

Features

  • Directory listing with recursive support
  • Path search with glob patterns (files and directories)
  • Content search with regex and context lines
  • File reading with head/tail/line ranges
  • Batch reads and metadata lookups in parallel
  • Security: path validation, symlink escape protection, read-only operations

When to Use

TaskTool
Explore project structurelist_directory
Find files or directoriessearch_files
Search for code patterns/textsearch_content
Read source coderead_file
Batch read multiple filesread_multiple_files
Get file metadata (size, dates)get_file_info
Batch get file metadataget_multiple_file_info
Check available directorieslist_allowed_directories

Quick Start

Allow the current working directory explicitly:

npx -y @j0hanz/filesystem-context-mcp@latest --allow-cwd

Or pass explicit directories:

npx -y @j0hanz/filesystem-context-mcp@latest /path/to/project /path/to/docs

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.

VS Code (workspace folder)

Add to .vscode/mcp.json:

{
  "servers": {
    "filesystem-context": {
      "command": "npx",
      "args": [
        "-y",
        "@j0hanz/filesystem-context-mcp@latest",
        "${workspaceFolder}"
      ]
    }
  }
}

Installation

NPX (no install)

npx -y @j0hanz/filesystem-context-mcp@latest /path/to/dir1 /path/to/dir2

Global installation

npm install -g @j0hanz/filesystem-context-mcp
filesystem-context-mcp /path/to/your/project

From source

git clone https://github.com/j0hanz/filesystem-context-mcp-server.git
cd filesystem-context-mcp-server
npm install
npm run build
node dist/index.js /path/to/your/project

Directory Access and Resolution

Access is always restricted to explicitly allowed directories.

  • CLI directories are validated and added first (if provided).
  • --allow-cwd optionally adds the current working directory.
  • MCP Roots from the client are used next:
    • If CLI and/or --allow-cwd are 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 has no access and logs a warning.

Notes:

  • Windows drive-relative paths like C:path are rejected. Use C:\path or C:/path.
  • Reserved Windows device names (e.g., CON, NUL) are blocked.

Configuration

All configuration is optional. Values are integers unless noted. Sizes are in bytes, timeouts in milliseconds.

Environment Variables

VariableDefaultRangeDescription
UV_THREADPOOL_SIZE(unset)1-1024libuv threadpool size. If set, caps parallelism.
FILESYSTEM_CONTEXT_CONCURRENCYAuto (2x cores, cap 50)1-100Parallel file operations. Further capped by UV_THREADPOOL_SIZE
FILESYSTEM_CONTEXT_SEARCH_WORKERS0 (disabled)0-32Worker-thread offload for search_content (uses one worker per search)
FILESYSTEM_CONTEXT_GLOB_ENGINEauton/aGlob engine: auto, fast-glob, or node/node:fs
MAX_FILE_SIZE10MB1MB-100MBMax text file size (read_file, read_multiple_files)
MAX_SEARCH_SIZE1MB100KB-10MBMax file size for content search (search_content)
DEFAULT_DEPTH101-100Default max depth (list_directory, search_files)
DEFAULT_RESULTS10010-10000Default max results (search_files, search_content)
DEFAULT_LIST_MAX_ENTRIES10000100-100000Default max entries (list_directory)
DEFAULT_SEARCH_MAX_FILES20000100-100000Default max files scanned (search_files, search_content)
DEFAULT_SEARCH_TIMEOUT30000100-3600000Default operation timeout (list_directory, search_files, search_content)

Note: FILESYSTEM_CONTEXT_GLOB_ENGINE is a string. auto uses Node's glob when options allow, otherwise it falls back to fast-glob.

See CONFIGURATION.md for profiles and examples.

Tools

All tools return both human-readable text and structured JSON. Structured responses include ok, error (with code, message, path, suggestion), and effectiveOptions/summary fields where applicable.

list_allowed_directories

List all directories that this server can access.

ParameterTypeRequiredDefaultDescription
(none)----

Returns: Allowed directory paths plus access status (accessible/readable), count, and a configuration hint in structured output.

list_directory

List contents of a directory with optional recursion.

ParameterTypeRequiredDefaultDescription
pathstringYes-Directory path to list
recursivebooleanNofalseList subdirectories recursively
includeHiddenbooleanNofalseInclude hidden files and directories
excludePatternsstring[]No[]Glob patterns to exclude
patternstringNo-Glob pattern to include (relative, no ..)
maxDepthnumberNo10Maximum depth for recursive listing (0-100)
maxEntriesnumberNo10000Maximum entries to return (1-100000)
timeoutMsnumberNo30000Timeout in milliseconds
sortBystringNonameSort by: name, size, modified, type
includeSymlinkTargetsbooleanNofalseInclude symlink target paths (symlinks are not followed)

Returns: Entries with name, relativePath, type, extension, size, modified time, and symlink target. Structured output includes effectiveOptions and a summary (totals, maxDepthReached, truncated/stoppedReason, entriesScanned, entriesVisible, skippedInaccessible, symlinksNotFollowed).

search_files

Search for paths (files and directories) using glob patterns.

ParameterTypeRequiredDefaultDescription
pathstringYes-Base directory to search from
patternstringYes-Glob pattern (e.g., **/*.ts, src/**/*.js)
excludePatternsstring[]Nobuilt-in exclude listGlob patterns to exclude
maxResultsnumberNo100Maximum matches to return (1-10000)
sortBystringNopathSort by: name, size, modified, path
maxDepthnumberNo10Maximum directory depth to search (0-100)
maxFilesScannednumberNo20000Maximum files to scan before stopping
timeoutMsnumberNo30000Timeout in milliseconds
baseNameMatchbooleanNofalseMatch patterns without slashes against basenames
skipSymlinksbooleanNotrueMust remain true; symlink traversal is disabled for security
includeHiddenbooleanNofalseInclude hidden files and directories

Returns: Matching paths with relative path, type, size, and modified date. Structured output includes effectiveOptions and a summary (matched, filesScanned, truncated/stoppedReason, skippedInaccessible). Directories may appear as type other in structured output.

read_file

Read the contents of a text file.

ParameterTypeRequiredDefaultDescription
pathstringYes-File path to read
encodingstringNoutf-8File encoding (utf-8, utf8, ascii, base64, hex, latin1)
maxSizenumberNo10MBMaximum file size in bytes (capped by MAX_FILE_SIZE)
skipBinarybooleanNotrueReject likely-binary files
lineStartnumberNo-Start line (1-indexed) for range reading
lineEndnumberNo-End line (inclusive) for range reading
headnumberNo-Read only first N lines
tailnumberNo-Read only last N lines

Notes:

  • head, tail, and lineStart/lineEnd are mutually exclusive.
  • lineStart and lineEnd must be provided together.

Returns: File content plus structured metadata (readMode, linesRead, totalLines, hasMoreLines, truncated, effectiveOptions).

read_multiple_files

Read multiple files in parallel.

ParameterTypeRequiredDefaultDescription
pathsstring[]Yes-Array of file paths (max 100)
encodingstringNoutf-8File encoding
maxSizenumberNo10MBMaximum size per file in bytes (capped by MAX_FILE_SIZE)
maxTotalSizenumberNo100MBMaximum total size across all files (max 1GB)
headnumberNo-Read only first N lines of each file
tailnumberNo-Read only last N lines of each file
lineStartnumberNo-Start line (1-indexed) for each file
lineEndnumberNo-End line (inclusive) for each file

Notes:

  • lineStart and lineEnd must be provided together.
  • head, tail, and lineStart/lineEnd are mutually exclusive.
  • No binary detection is performed; use read_file with skipBinary=true for checks.

Returns: Per-file content or error, plus structured summary and effectiveOptions.

get_file_info

Get detailed metadata about a file or directory.

ParameterTypeRequiredDefaultDescription
pathstringYes-Path to file or directory

Returns: name, path, type, size, created/modified/accessed timestamps, permissions, isHidden, MIME type, and symlink target (if applicable).

get_multiple_file_info

Get metadata for multiple files/directories in parallel.

ParameterTypeRequiredDefaultDescription
pathsstring[]Yes-Array of paths to query (max 100)
includeMimeTypebooleanNotrueInclude MIME type detection

Returns: Array of file info with individual success/error status, plus summary (total, succeeded, failed, totalSize).

search_content

Search for text content within files using regular expressions.

ParameterTypeRequiredDefaultDescription
pathstringYes-Base directory to search in
patternstringYes-Regex pattern to search for
filePatternstringNo**/*Glob pattern to filter files
excludePatternsstring[]Nobuilt-in exclude listGlob patterns to exclude
caseSensitivebooleanNofalseCase-sensitive search
maxResultsnumberNo100Maximum number of results
maxFileSizenumberNo1MBMaximum file size to scan (default from MAX_SEARCH_SIZE)
maxFilesScannednumberNo20000Maximum files to scan before stopping
timeoutMsnumberNo30000Timeout in milliseconds
skipBinarybooleanNotrueSkip likely-binary files
includeHiddenbooleanNofalseInclude hidden files and directories
contextLinesnumberNo0Lines of context before/after match (0-10)
wholeWordbooleanNofalseMatch whole words only
isLiteralbooleanNofalseTreat pattern as literal string (escape regex chars)
baseNameMatchbooleanNofalseMatch file patterns without slashes against basenames
caseSensitiveFileMatchbooleanNotrueCase-sensitive filename matching

Returns: Matching lines with file path, line number, content, and optional context. Structured output includes effectiveOptions and a summary (filesScanned/filesMatched, totalMatches, truncated/stoppedReason, skippedTooLarge/skippedBinary/skippedInaccessible, linesSkippedDueToRegexTimeout). Matched line content is trimmed to 200 characters.

Built-in exclude list 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: [] to disable it.

Error Codes

CodeMeaning
E_ACCESS_DENIEDPath outside allowed roots
E_NOT_FOUNDPath does not exist
E_NOT_FILEExpected file, got directory
E_NOT_DIRECTORYExpected directory, got file
E_TOO_LARGEFile exceeds size limits
E_TIMEOUTOperation timed out
E_INVALID_PATTERNInvalid glob/regex pattern
E_INVALID_INPUTInvalid argument(s)
E_PERMISSION_DENIEDOS-level permission denied
E_SYMLINK_NOT_ALLOWEDSymlink escapes allowed roots
E_UNKNOWNUnexpected error

Client Configuration

VS Code

Add to .vscode/mcp.json (recommended) or .vscode/settings.json:

{
  "servers": {
    "filesystem-context": {
      "command": "npx",
      "args": [
        "-y",
        "@j0hanz/filesystem-context-mcp@latest",
        "${workspaceFolder}"
      ]
    }
  }
}
Claude Desktop

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "filesystem-context": {
      "command": "npx",
      "args": [
        "-y",
        "@j0hanz/filesystem-context-mcp@latest",
        "C:\\path\\to\\project"
      ]
    }
  }
}

If your client supports MCP Roots, you can omit the path. Otherwise, pass a path or --allow-cwd.

Cursor

Add to Cursor's MCP configuration:

{
  "mcpServers": {
    "filesystem-context": {
      "command": "npx",
      "args": [
        "-y",
        "@j0hanz/filesystem-context-mcp@latest",
        "${workspaceFolder}"
      ]
    }
  }
}
Codex

Add to ~/.codex/config.toml:

[mcp_servers.filesystem-context]
command = "npx"
args = ["-y", "@j0hanz/filesystem-context-mcp@latest", "/path/to/your/project"]

If your client supports MCP Roots, you can omit the path. Otherwise, pass a path or --allow-cwd.

Windsurf

Add to Windsurf's MCP configuration:

{
  "mcpServers": {
    "filesystem-context": {
      "command": "npx",
      "args": [
        "-y",
        "@j0hanz/filesystem-context-mcp@latest",
        "${workspaceFolder}"
      ]
    }
  }
}

Security

This server implements multiple layers of security:

ProtectionDescription
Access controlOnly explicitly allowed directories are accessible
Path validationAll paths are validated before any filesystem operation
Symlink protectionSymlinks that resolve outside allowed directories are blocked
Path traversal preventionAttempts to escape via .. are detected and blocked
Read-only operationsNo writes, deletes, or modifications
Safe regexRegex validation with RE2 prevents ReDoS
Size limitsConfigurable limits prevent resource exhaustion

Development

Prerequisites

  • Node.js >= 20.0.0
  • npm

Scripts

CommandDescription
npm run buildCompile TypeScript to JavaScript
npm run devWatch mode with tsx
npm run startRun compiled server
npm run testRun tests (node --test with tsx/esm)
npm run test:watchRun tests in watch mode (node --test --watch)
npm run test:coverageRun tests with coverage (node --test --experimental-test-coverage)
npm run test:nodeRun node-tests (isolated checks)
npm run lintRun ESLint
npm run formatFormat code with Prettier
npm run type-checkTypeScript type checking
npm run benchRun benchmarks
npm run inspectorTest with MCP Inspector

Project Structure

src/
  index.ts                 # CLI entry point
  server.ts                # MCP server wiring and roots handling
  instructions.md          # Tool usage instructions (bundled in dist)
  config/                  # Shared types and formatting helpers
  lib/                     # Core logic and filesystem operations
  schemas/                 # Zod input/output schemas
  tools/                   # MCP tool registration
  __tests__/               # node:test + tsx tests
node-tests/                # Isolated Node.js checks

Troubleshooting

IssueSolution
"Access denied" errorEnsure the path is within an allowed directory. Use list_allowed_directories to check.
"Path does not exist"Verify the path exists. Use list_directory to explore available files.
"File too large"Use head/tail or increase maxSize.
"Binary file" warningSet skipBinary=false in read_file to read as text.
No directories availablePass explicit paths, use --allow-cwd, or ensure the client provides MCP Roots.
Symlink blockedSymlinks that resolve outside allowed directories are blocked.
Invalid regex/patternSimplify the regex or set isLiteral=true for exact matches.

Contributing

Contributions are welcome! Please follow these steps:

  • Fork the repository
  • Create a feature branch (git checkout -b feature/amazing-feature)
  • Run tests and linting (npm run lint && 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

Keywords

mcp

FAQs

Package last updated on 06 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts