local-explorer-mcp
Making Local File System Search Smarter for AI Agents
An MCP (Model Context Protocol) server for intelligent local file system exploration using native Unix/Linux commands (inspired by octocode-mcp).
โจ This project used its own prompts to generate AGENTS.md and ARCHITECTURE.md
๐ง Ongoing Research Project - Please share your feedback and suggestions via GitHub Issues
๐ฏ Built-in AI Prompts
Two powerful prompts to auto-generate comprehensive documentation:
๐ generate_architecture_markdown - Create ARCHITECTURE.md
Auto-generates complete architecture documentation by exploring your codebase:
- Identifies project type, language, and scale
- Maps entry points, core components, and system boundaries
- Discovers architectural patterns and key abstractions
Perfect for: New contributors, architecture reviews, understanding complex codebases
๐ค generate_agents_markdown - Create AGENTS.md
Auto-generates AI-friendly guidance for coding assistants:
- Discovers and merges existing agent configs (CLAUDE.md, .cursorrules, etc.)
- Maps file permissions (edit, ask first, never touch)
- Extracts setup commands, testing workflows, and style guidelines
- Documents code style, commit format, and PR requirements
Perfect for: AI-assisted development, team onboarding, consistent coding practices
๐ก Why Use This?
Smart local codebase research - faster and more efficient than traditional file reading:
- Research Your Code - Understand complex codebases, find functions/classes, trace implementations
- Investigate Dependencies - Debug issues in node_modules, explore third-party code, detect bugs
- Smart Workspace Search - Pattern-based discovery, time-based filtering, metadata search
- Token Efficient - Automatic pagination, minification, and smart chunking
- Native Performance - Leverages ripgrep, find, ls for blazing-fast searches
- Security First - Multi-layer validation prevents path traversal and command injection
- Agent Optimized - Purpose-built workflows with decision trees for AI assistants
Table of Contents
- Built-in AI Prompts
- Why Use This
- Installation
- Tools Overview
- Usage Examples
- Security Features
- Performance Tips
- Development
- Troubleshooting
๐ฆ Installation
Prerequisites
- Node.js >= 18.0.0
- ripgrep (required for
local_ripgreptool):- โ Already available in Claude Code and Cursor
- macOS:
brew install ripgrep - Ubuntu/Debian:
apt-get install ripgrep - Windows:
choco install ripgrep - Installation guide
Quick Install
Claude Codeclaude mcp add local-explorer-mcp npx local-explorer-mcp@latest
Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"local-explorer-mcp": {
"command": "npx",
"args": ["local-explorer-mcp@latest"],
"env": {
"WORKSPACE_ROOT": "/path/to/your/project"
}
}
}
}
Cursor
Click to install:
Or manually edit your Cursor MCP settings and add:
{
"mcpServers": {
"local-explorer-mcp": {
"command": "npx",
"args": ["local-explorer-mcp@latest"],
"env": {
"WORKSPACE_ROOT": "${workspaceFolder}"
}
}
}
}
Environment Variables
- WORKSPACE_ROOT (required): Project root directory. Defaults to current working directory.
- DEBUG (optional): Set to "true" for detailed logging
- CACHE_TTL (optional): Cache duration in seconds (default: 900)
- MEMORY_LIMIT (optional): Max memory in MB (default: 100)
๐ How It Works
Once installed, AI assistants can automatically:
- Explore directories - View project structure, find entry points
- Search code patterns - Find functions, classes, or any text
- Filter by metadata - Locate files by name, size, or modification time
- Read efficiently - Extract specific sections without loading entire files
๐ ๏ธ Tools Overview
4 Unix-powered tools for efficient file system research:
| Tool | Purpose | Unix Command | Best For |
|---|---|---|---|
local_view_structure |
Directory exploration | ls / fs.readdir |
Project structure, finding entry points |
local_ripgrep |
Pattern search | ripgrep |
Finding functions, classes, TODOs |
local_find_files |
File discovery | find |
Metadata filtering (name, size, time) |
local_fetch_content |
Content reading | fs.readFile |
Efficient file reading with pagination |
All tools support bulk operations and smart pagination.
1. local_view_structure - Directory Exploration
Explore directory structure with sorting and filtering options.
Key Features:
- Tree or list view
- Sort by name, size, time, or extension
- Filter by file patterns
- Control depth (1-5 levels)
- Include/exclude hidden files
Use Cases:
- Understand project organization
- Find large or recently modified files
- Identify entry points and key directories
Workflow: Start with depth=1 for overview โ drill down into specific directories โ sort by size/time as needed
2. local_ripgrep - Pattern Search
Fast code search using ripgrep. Find functions, classes, or patterns across your codebase in milliseconds.
Key Features:
- Discovery mode (files only) or detailed mode (matches with context)
- Regex and fixed-string search
- Smart case, case-insensitive, or whole-word matching
- Filter by file type or patterns
- Exclude directories (node_modules, etc.)
- Pagination for large results
Use Cases:
- Find function/class definitions and usages
- Locate TODO comments or error messages
- Understand code patterns across projects
- Quick file discovery
Workflow: Discovery mode (filesOnly=true) โ detailed search with context โ read full file if needed
3. local_find_files - Advanced File Discovery
Find files by name, size, modification time, or permissions.
Key Features:
- Name matching (case-sensitive/insensitive, regex, multiple patterns)
- Time filters (modifiedWithin, modifiedBefore, accessedWithin)
- Size filters (sizeGreater, sizeLess)
- File attributes (type, permissions, executable, empty)
- Exclude directories
- Control depth and result limits
Use Cases:
- Find config files (
*.config.js,.env) - Locate large files
- Track recent modifications
- Discover executable scripts
- Combine multiple criteria
Examples:
- Recent TypeScript:
name="*.ts",modifiedWithin="7d" - Large files:
sizeGreater="1M" - Executables:
executable=true,type="f"
4. local_fetch_content - Smart Content Reading
Read files efficiently with automatic optimization and pagination.
Key Features:
- Full file or pattern-based extraction (matchString)
- Automatic minification (removes comments/whitespace)
- Pagination for large files
- Context control (lines around matches)
Use Cases:
- Read config files
- Extract specific functions/classes
- Follow up on search results
- Handle large files with pagination
Reading Modes:
fullContent=true- Entire file (small files)matchString="functionName"- Extract specific sections (most efficient)matchStringContextLines=20- Control surrounding context
Integration: Use with ripgrep โ find patterns โ extract with matchString
๐ก Usage Examples
Common Workflows
Understanding a New Codebase:
- View structure (sortBy size) โ Find entry points โ Search patterns โ Read key files
Finding and Fixing Bugs:
- Search error message โ Find recent files โ Extract function/class
Code Refactoring:
- Find all usages (filesOnly) โ Get detailed matches โ Read affected sections
Performance Analysis:
- Find large files โ Check recent modifications โ Search TODO/FIXME comments
๐ Security Features
Multi-layer security with command whitelisting, path validation, and resource limits.
Core Protections
Command Whitelisting: Only rg, find, ls allowed
Path Protection:
- Workspace-restricted operations
- Path traversal prevention
- Symlink validation
- Absolute path resolution
Sensitive File Filtering (automatic):
- Secrets:
.env,*.pem,*.key,credentials.json - Dependencies:
node_modules/,.yarn/ - Build artifacts:
dist/,build/,*.min.js - VCS:
.git/,.svn/ - IDE:
.vscode/,.idea/
Resource Limits:
- Timeout: 30s (configurable)
- Output: 10MB max (configurable)
- Memory: 100MB (configurable)
- Auto-pagination for token limits
Injection Prevention:
- Direct command execution (no shell)
- Argument validation and escaping
- No command chaining
โก Performance Tips
Token Optimization:
- Start with discovery (filesOnly mode)
- Use pattern matching over full files
- Enable minification for code files
- Process bulk operations in parallel
- Use automatic pagination
Caching: 15-min TTL, LRU eviction, automatic
Memory Management: 100MB default, per-operation tracking, auto-cleanup
๐ Troubleshooting
ripgrep not found:
# Install ripgrep
brew install ripgrep # macOS
apt-get install ripgrep # Ubuntu/Debian
choco install ripgrep # Windows
Permission denied: Check WORKSPACE_ROOT permissions with ls -la
Path outside workspace: Verify WORKSPACE_ROOT is set correctly, avoid symlinks outside workspace
Server not starting:
- Check Node.js >= 18.0.0
- Clear cache:
npm cache clean --force - Check MCP config syntax
- View logs: Claude Desktop โ Help โ Show Logs
Token limit exceeded: Use filesOnly=true, pagination, matchString instead of fullContent
Slow performance: Use specific patterns, limit scope, exclude large dirs, use depth=1
Debug Mode: Set DEBUG="true" in env vars for detailed logging
Get Help: GitHub Issues
๐ License
MIT License - see LICENSE.md for details.
๐ Acknowledgments
- Inspired by octocode-mcp research methodologies
- Built on Model Context Protocol by Anthropic
- Powered by ripgrep
npm: local-explorer-mcp