Skip to content

Commit 9dffa57

Browse files
committed
docs: review & rewrite documentation
1 parent b8170cf commit 9dffa57

12 files changed

Lines changed: 1286 additions & 293 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ wheels/
1414
.coverage.*
1515
coverage.xml
1616
htmlcov/
17+
18+
# Largefile data directories
19+
.largefile/

README.md

Lines changed: 214 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,221 @@
11
# Largefile MCP Server
22

3-
MCP server for working with large text files that exceed LLM context limits.
3+
MCP server that helps your AI assistant work with large files that exceed context limits.
44

5-
This server enables LLMs to navigate, search, and edit files of any size without loading the entire content into memory. It provides targeted access to specific lines, patterns, and sections while maintaining file integrity. Perfect for working with large codebases, generated files, logs, and datasets that would otherwise be inaccessible to AI tools.
5+
[![CI](https://img.shields.io/github/actions/workflow/status/peteretelej/largefile/ci.yml?branch=main&logo=github)](https://github.com/peteretelej/largefile/actions/workflows/ci.yml) [![PyPI version](https://img.shields.io/pypi/v/largefile.svg)](https://pypi.org/project/largefile/) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
66

7-
## Goal
7+
This MCP server enables AI assistants to navigate, search, and edit files of any size without loading entire content into memory. It provides targeted access to specific lines, patterns, and sections while maintaining file integrity using research-backed search/replace editing instead of error-prone line-based operations. Perfect for working with large codebases, generated files, logs, and datasets that would otherwise be inaccessible due to context window limitations.
88

9-
Enable LLMs to perform precise operations on files of any size through intelligent navigation, targeted search, and atomic editing, eliminating the context barrier that prevents AI tools from working with production codebases or very large documents.
9+
## MCP Tools
1010

11-
## Planned Features
11+
The server provides 4 core tools that work together for progressive file exploration:
1212

13-
- **Smart Navigation**: Jump to specific lines, functions, or patterns instantly
14-
- **Intelligent Search**: Pattern-based search across files without context limits
15-
- **Precision Editing**: Atomic edit operations that preserve file integrity
16-
- **Context Extraction**: Extract minimal relevant context for LLM consumption
17-
- **Atomic Calculations**: Perform file-wide calculations without full loading
13+
- **`get_overview`** - Get file structure with Tree-sitter semantic analysis, line counts, and suggested search patterns
14+
- **`search_content`** - Find patterns with fuzzy matching, context lines, and semantic information
15+
- **`read_content`** - Read targeted content by line number or pattern with semantic chunking (complete functions/classes)
16+
- **`edit_content`** - Primary editing via search/replace blocks with automatic backups and preview mode
17+
18+
## Quick Start
19+
20+
**Prerequisite:** Install [uv](https://docs.astral.sh/uv/getting-started/installation/) (an extremely fast Python package manager) which provides the `uvx` command.
21+
22+
Add to your MCP configuration:
23+
24+
```json
25+
{
26+
"mcpServers": {
27+
"largefile": {
28+
"command": "uvx",
29+
"args": ["--from", "largefile", "largefile-mcp"]
30+
}
31+
}
32+
}
33+
```
34+
35+
## Usage Examples
36+
37+
### Analyzing Large Code Files
38+
39+
**AI Question:** _"Can you analyze this large Django models file and tell me about the class structure and any potential issues? It's a large file so use largefile."_
40+
41+
**AI Assistant workflow:**
42+
43+
1. Get file overview to understand structure
44+
2. Search for classes and their methods
45+
3. Look for code issues like TODOs or long functions
46+
47+
```python
48+
# AI gets file structure
49+
overview = get_overview("/path/to/django-models.py")
50+
# Returns: 2,847 lines, 15 classes, semantic outline with Tree-sitter
51+
52+
# AI searches for all class definitions
53+
classes = search_content("/path/to/django-models.py", "class ", max_results=20)
54+
# Returns: Model classes with line numbers and context
55+
56+
# AI examines specific class implementation
57+
model_code = read_content("/path/to/django-models.py", "class User", mode="semantic")
58+
# Returns: Complete class definition with all methods
59+
```
60+
61+
### Working with Documentation
62+
63+
**AI Question:** _"Find all the installation methods mentioned in this README file and update the pip install to use uv instead."_
64+
65+
**AI Assistant workflow:**
66+
67+
1. Search for installation patterns
68+
2. Read the installation section
69+
3. Replace pip commands with uv equivalents
70+
71+
```python
72+
# AI finds installation instructions
73+
install_sections = search_content("/path/to/readme.md", "install", fuzzy=True, context_lines=3)
74+
75+
# AI reads the installation section
76+
install_content = read_content("/path/to/readme.md", "## Installation", mode="semantic")
77+
78+
# AI replaces pip with uv
79+
edit_result = edit_content(
80+
"/path/to/readme.md",
81+
search_text="pip install anthropic",
82+
replace_text="uv add anthropic",
83+
preview=True
84+
)
85+
```
86+
87+
### Debugging Large Log Files
88+
89+
**AI Question:** _"Check this production log file for any critical errors in the last few thousand lines and show me the context around them. Use largefile mcp."_
90+
91+
**AI Assistant workflow:**
92+
93+
1. Get log file overview
94+
2. Search for error patterns
95+
3. Read context around critical issues
96+
97+
```python
98+
# AI gets log file overview
99+
overview = get_overview("/path/to/production.log")
100+
# Returns: 150,000 lines, 2.1GB file size
101+
102+
# AI searches for critical errors
103+
errors = search_content("/path/to/production.log", "CRITICAL|ERROR", fuzzy=True, max_results=10)
104+
105+
# AI examines context around each error
106+
for error in errors:
107+
context = read_content("/path/to/production.log", error.line_number, mode="lines")
108+
# Shows surrounding log entries for debugging
109+
```
110+
111+
### Refactoring Code
112+
113+
**AI Question:** _"I need to rename the function `process_data` to `transform_data` throughout this large codebase file. Can you help me do this safely?"_
114+
115+
**AI Assistant workflow:**
116+
117+
1. Find all occurrences of the function
118+
2. Preview changes to ensure accuracy
119+
3. Apply changes with automatic backup
120+
121+
```python
122+
# AI finds all usages
123+
usages = search_content("/path/to/codebase.py", "process_data", fuzzy=False, max_results=50)
124+
125+
# AI previews the changes
126+
preview = edit_content(
127+
"/path/to/codebase.py",
128+
search_text="process_data",
129+
replace_text="transform_data",
130+
preview=True
131+
)
132+
133+
# AI applies changes after confirmation
134+
result = edit_content(
135+
"/path/to/codebase.py",
136+
search_text="process_data",
137+
replace_text="transform_data",
138+
preview=False
139+
)
140+
# Creates automatic backup before changes
141+
```
142+
143+
### Exploring API Documentation
144+
145+
**AI Question:** _"What are all the available methods in this large API documentation file and can you show me examples of authentication?"_
146+
147+
**AI Assistant workflow:**
148+
149+
1. Get document structure overview
150+
2. Search for method definitions and auth patterns
151+
3. Extract relevant code examples
152+
153+
```python
154+
# AI analyzes document structure
155+
overview = get_overview("/path/to/api-docs.md")
156+
# Returns: Section outline, headings, suggested search patterns
157+
158+
# AI finds API methods
159+
methods = search_content("/path/to/api-docs.md", "###", max_results=30)
160+
# Returns: All method headings with context
161+
162+
# AI searches for authentication examples
163+
auth_examples = search_content("/path/to/api-docs.md", "auth", fuzzy=True, context_lines=5)
164+
165+
# AI reads complete authentication section
166+
auth_section = read_content("/path/to/api-docs.md", "## Authentication", mode="semantic")
167+
```
168+
169+
## File Size Handling
170+
171+
- **Small files (<50MB)**: Memory loading with Tree-sitter AST caching
172+
- **Medium files (50-500MB)**: Memory-mapped access
173+
- **Large files (>500MB)**: Streaming processing
174+
- **Long lines (>1000 chars)**: Automatic truncation for display
175+
176+
## Supported Languages
177+
178+
Tree-sitter semantic analysis for:
179+
180+
- Python (.py)
181+
- JavaScript/JSX (.js, .jsx)
182+
- TypeScript/TSX (.ts, .tsx)
183+
- Rust (.rs)
184+
- Go (.go)
185+
186+
Files without Tree-sitter support use text-based analysis with graceful degradation.
187+
188+
## Configuration
189+
190+
Configure via environment variables:
191+
192+
```bash
193+
# File processing thresholds
194+
LARGEFILE_MEMORY_THRESHOLD_MB=50 # Memory loading limit
195+
LARGEFILE_MMAP_THRESHOLD_MB=500 # Memory mapping limit
196+
197+
# Search settings
198+
LARGEFILE_FUZZY_THRESHOLD=0.8 # Fuzzy match sensitivity
199+
LARGEFILE_MAX_SEARCH_RESULTS=20 # Result limit
200+
LARGEFILE_CONTEXT_LINES=2 # Context window
201+
202+
# Performance
203+
LARGEFILE_ENABLE_TREE_SITTER=true # Semantic features
204+
LARGEFILE_BACKUP_DIR=".largefile_backups" # Backup location
205+
```
206+
207+
## Key Features
208+
209+
- **Search/replace primary**: Eliminates LLM line number errors
210+
- **Fuzzy matching**: Handles whitespace and formatting variations
211+
- **Atomic operations**: File integrity with automatic backups
212+
- **Semantic awareness**: Tree-sitter integration for code structure
213+
- **Memory efficient**: Handles files of any size without context limits
214+
- **Error recovery**: Graceful degradation with clear error messages
215+
216+
## Documentation
217+
218+
- [API Reference](docs/api-reference.md) - Detailed tool documentation
219+
- [Configuration Guide](docs/configuration.md) - Environment variables and tuning
220+
- [Examples](docs/examples.md) - Real-world usage examples and workflows
221+
- [Design Document](docs/design.md) - Architecture and implementation details

docs/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Documentation
2+
3+
Technical documentation for the Largefile MCP Server.
4+
5+
## Core Documentation
6+
7+
- **[API Reference](api-reference.md)** - Detailed tool signatures, parameters, and response formats
8+
- **[Configuration Guide](configuration.md)** - Environment variables and performance tuning
9+
- **[Examples](examples.md)** - Real-world usage examples and AI assistant workflows
10+
11+
## Technical Details
12+
13+
- **[Design Document](design.md)** - Architecture, implementation details, and research-backed decisions
14+
- **[Examples](examples.md)** - Real-world usage examples and integration scenarios
15+
16+
## Development
17+
18+
- **[Implementation Plan](plans/implementation.md)** - Development phases and completion checklist
19+
- **[Open Source Plan](plans/opensource.md)** - Preparation tasks for public release
20+
21+
## Research and Integration
22+
23+
- **[Third-party Integrations](3rd-party/)** - Documentation on Tree-sitter, MCP SDK, and research materials
24+
25+
## Quick Navigation
26+
27+
**Getting Started**: Read the [main README](../README.md) first, then refer to [Examples](examples.md) for AI assistant workflows.
28+
29+
**Configuration**: See [Configuration Guide](configuration.md) for environment variables and performance settings.
30+
31+
**Integration**: Check [API Reference](api-reference.md) for detailed tool documentation and [Examples](examples.md) for AI assistant workflows.
32+
33+
**Development**: Review [Design Document](design.md) for architecture details and [Implementation Plan](plans/implementation.md) for development status.

0 commit comments

Comments
 (0)