loading…
Search for a command to run...
loading…
An MCP server that provides a flexible lens into directory structures and files, enabling LLM clients to efficiently navigate and understand codebases with mini
An MCP server that provides a flexible lens into directory structures and files, enabling LLM clients to efficiently navigate and understand codebases with minimal noise. It offers secure, gitignore-aware file access with tools like directory listing, file reading, and grep-like search.
PyPI version Python 3.12+ License: MIT
An MCP (Model Context Protocol) server that provides a flexible "lens" into your directory structure and files, enabling LLM clients to efficiently navigate and understand codebases with minimal noise.
mcp-file-lens is a Python-based MCP server designed to give LLMs targeted access to file systems. Rather than reading entire file contents indiscriminately, it provides surgical tools to inspect exactly what's needed, preserving context window and improving comprehension.
This server is designed to work alongside other MCP servers like Language Protocol Servers (LPS), providing complementary file navigation capabilities while the LPS handles language-specific operations like symbol resolution, type checking, and refactoring.
--allowed-dirlist_dir): Navigate directory structures efficiently with optional recursive moderead_file): Read complete file contents with optional line numbersread_file_grep): Find lines containing specific strings with context (like grep -A/-B/-C)read_files_grep): Recursively search across all files in a directory treeread_file_range): Extract a specific line range from filespip install mcp-file-lens
Note: The package name uses hyphens (
mcp-file-lens) for PyPI installation, but the Python module name uses underscores (mcp_file_lens) for imports.
# Clone the repository
git clone https://github.com/solatis/mcp-file-lens.git
cd mcp-file-lens
# Install in development mode
pip install -e ".[dev]"
# Start the server with a specific allowed directory
python -m mcp_file_lens --allowed-dir ./my_project
# Or with an absolute path
python -m mcp_file_lens --allowed-dir /absolute/path/to/project
# Enable debug logging
python -m mcp_file_lens --allowed-dir ./my_project --debug
# Disable gitignore filtering (not recommended)
python -m mcp_file_lens --allowed-dir ./my_project --disable-gitignore
Security Note: The --allowed-dir argument is REQUIRED and restricts file access to only the specified directory tree. This prevents the LLM from accessing files outside your project.
Add to your MCP client configuration:
{
"servers": {
"mcp-file-lens": {
"command": "python",
"args": ["-m", "mcp_file_lens", "--allowed-dir", "./my_project"],
"env": {}
}
}
}
For development or troubleshooting, enable debug mode:
{
"servers": {
"mcp-file-lens": {
"command": "python",
"args": ["-m", "mcp_file_lens", "--allowed-dir", "./my_project", "--debug"],
"env": {}
}
}
}
mcp-file-lens is designed to complement other MCP servers. For example, when used alongside a Language Protocol Server:
{
"servers": {
"mcp-file-lens": {
"command": "python",
"args": ["-m", "mcp_file_lens", "--allowed-dir", "./my_project"],
"env": {}
},
"typescript-lps": {
"command": "typescript-language-server",
"args": ["--stdio"],
"env": {}
}
}
}
This allows LLMs to:
mcp-file-lens for efficient file navigation and content inspectionlist_dir(path: str = ".", recursive: bool = False)Lists the contents of a directory in ls -la format. Automatically filters out gitignored files and binary files.
Parameters:
path: Directory path to list (default: current directory)recursive: If True, recursively list all files (default: False)Returns: Plain text directory listing with file sizes and names (filtered by gitignore and excluding binary files)
Filtering: Respects .gitignore patterns and excludes binary files for cleaner output.
Example Output:
2494 pyproject.toml
6420 README.md
src/
read_file(path: str, lineno: bool = True)Reads the complete contents of a file in cat -n format. Automatically skips binary files and handles UTF-8 encoding issues gracefully.
Parameters:
path: File path to readlineno: Include line numbers in output (default: True)Returns: Plain text file content with optional line numbers
Example Output:
1 #!/usr/bin/env python3
2 """Main module"""
3
4 import sys
read_file_grep(path: str, search_string: str, before: int = 0, after: int = 0, context: int | None = None, lineno: bool = True)Searches for lines containing a string with optional context in grep -n format.
Parameters:
path: File path to searchsearch_string: String to search forbefore: Lines to include before each match (like grep -B)after: Lines to include after each match (like grep -A)context: Sets both before and after (like grep -C)lineno: Include line numbers in output (default: True)Returns: Plain text grep-style output with matching lines and context
Example Output:
15:def install_audit_hook() -> None:
16: """Install an audit hook to monitor file operations."""
17: def audit_hook(event: str, args: Tuple) -> None:
--
25: if _allowed_dir is not None:
26: sys.addaudithook(audit_hook)
read_files_grep(path: str = ".", search_string: str = "", before: int = 0, after: int = 0, context: int | None = None, lineno: bool = True, filename: bool = True)Recursively searches for patterns across all files in a directory tree. Automatically filters out binary files and gitignored files for cleaner results.
Parameters:
path: Directory to search recursively (default: current directory)search_string: String to search forbefore: Lines to include before each match (like grep -B)after: Lines to include after each match (like grep -A)context: Sets both before and after (like grep -C)lineno: Include line numbers in output (default: True)filename: Include filename prefix in output (default: True)Returns: Plain text grep -r style output with matches from all files
Example Output:
src/server.py:15:def install_audit_hook() -> None:
src/server.py:16: """Install an audit hook to monitor file operations."""
--
tests/test_server.py:42:def test_install_audit_hook():
tests/test_server.py:43: """Test audit hook installation."""
read_file_range(path: str, start_line: int, end_line: int, lineno: bool = True)Reads a specific line range from a file.
Parameters:
path: File path to readstart_line: Start line number (1-indexed, inclusive)end_line: End line number (1-indexed, inclusive)lineno: Include line numbers in output (default: True)Example:
# Read lines 10-20
read_file_range("/path/to/file.py", 10, 20)
Returns: Plain text with selected lines from the specified range
Example Output:
10:import logging
11:from pathlib import Path
12:from typing import Any
--
50:def validate_path(path: str) -> Tuple[bool, str]:
51: """Validate if path is allowed."""
# Clone and install in development mode
git clone https://github.com/solatis/mcp-file-lens.git
cd mcp-file-lens
pip install -e ".[dev]"
# Run tests
pytest
# Code quality checks
ruff check . # Linting
black --check . # Format checking
mypy src/ # Type checking
# Auto-fix formatting
black . # Format code
ruff check --fix . # Fix linting issues
mcp-file-lens/
├── src/
│ └── mcp_file_lens/
│ ├── __init__.py
│ ├── __main__.py
│ └── server.py
├── tests/
│ └── test_server.py
├── pyproject.toml
└── README.md
--allowed-dir PATH: REQUIRED - Restricts file access to the specified directory tree. Can be relative or absolute path.--enable-gitignore: Enable gitignore filtering (default behavior). Files matching patterns in .gitignore will be excluded from listings and searches.--disable-gitignore: Disable gitignore filtering. All files will be accessible regardless of .gitignore patterns.--debug: Enable debug logging. Shows detailed information about file operations, errors, and security checks.Gitignore Support:
--disable-gitignoreBinary File Detection:
Error Handling:
The --allowed-dir argument implements targeted security through a filesystem adapter:
../ and other directory traversal attemptsThis ensures that the LLM can only access files within your designated project directory, protecting your system files and other sensitive data, while allowing normal Python operations to function unimpeded.
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Run in your terminal:
claude mcp add mcp-file-lens -- npx Security
Low riskAutomated heuristic from public metadata — not a security guarantee.