Skip to content

Commit 761ac6c

Browse files
committed
docs: add URL support examples and update feature descriptions
1 parent c295555 commit 761ac6c

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

CLAUDE.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ This is an MCP (Model Context Protocol) server that provides precise code extrac
6262
- **Data Models** (`models.py`) - Rich symbol representations with hierarchical relationships
6363
- **Language Support** (`languages.py`) - Detection and mapping for 30+ programming languages
6464
- **Tree-sitter Queries** (`queries/`) - Language-specific syntax parsing patterns
65-
- **File Reading** (`file_reader.py`) - Unified file reading with VCS support
65+
- **File Reading** (`file_reader.py`) - Unified file reading with VCS and URL support
66+
- **URL Fetching** (`url_fetcher.py`) - HTTP fetching with caching and error handling
6667
- **VCS Support** (`vcs/`) - Pluggable version control system abstraction
6768
- **Entry Points** (`__main__.py`) - Module execution support
6869

@@ -125,17 +126,42 @@ The server exposes 5 tools to AI assistants:
125126

126127
**Best Practice**: Always use `get_symbols` first for code exploration, then use specific extraction tools for detailed analysis.
127128

129+
### URL Support
130+
131+
All 5 MCP tools support URLs for fetching remote code:
132+
133+
**Examples:**
134+
```python
135+
# GitHub raw URLs
136+
get_symbols("https://raw.githubusercontent.com/user/repo/main/src/main.py")
137+
get_function("https://raw.githubusercontent.com/user/repo/main/src/api.py", "handle_request")
138+
139+
# GitLab raw URLs
140+
get_class("https://gitlab.com/user/project/-/raw/main/src/models.py", "User")
141+
get_lines("https://gitlab.com/user/project/-/raw/main/config.py", 10, 20)
142+
143+
# Direct file URLs
144+
get_signature("https://example.com/code/utils.py", "helper_function")
145+
```
146+
147+
**Features:**
148+
- Automatic content-type validation (text/* only)
149+
- File size limits (1MB default, configurable)
150+
- TTL caching for performance (5min default)
151+
- Robust error handling for network issues
152+
- Support for GitHub, GitLab, and direct file URLs
153+
128154
### Git Revision Support
129155

130-
All 5 MCP tools now support an optional `git_revision` parameter for extracting code from any git revision:
156+
All 5 MCP tools also support an optional `git_revision` parameter for extracting code from any git revision:
131157

132158
**Examples:**
133159
```python
134160
# Extract from filesystem (default, backward compatible)
135161
get_symbols("src/main.py")
136162
get_function("src/main.py", "process_data")
137163

138-
# Extract from git revisions
164+
# Extract from git revisions (NOT compatible with URLs)
139165
get_symbols("src/main.py", "HEAD~1") # Previous commit
140166
get_function("src/main.py", "process_data", "feature-branch") # Branch
141167
get_class("src/models.py", "User", "v1.0.0") # Tagged version
@@ -156,4 +182,5 @@ get_signature("src/api.py", "handle_request", "HEAD^2") # Merge parent
156182
- File must be in a git repository
157183
- Git command must be available in PATH
158184
- Revision must exist in the repository
159-
- File must exist at the specified revision
185+
- File must exist at the specified revision
186+
- **Note**: `git_revision` parameter is NOT supported when using URLs

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ MCP Server Code Extractor solves these problems by providing structured, tree-si
1818
- **🌍 30+ Languages**: Supports Python, JavaScript, TypeScript, Go, Rust, Java, C/C++, and many more
1919
- **📍 Line Numbers**: Every extraction includes precise line number information
2020
- **🔍 Code Discovery**: List all functions and classes in a file before extracting
21-
- **⚡ Fast & Lightweight**: Single-file implementation with minimal dependencies
21+
- **🌐 URL Support**: Fetch and extract code from GitHub, GitLab, and direct file URLs
22+
- **🔄 Git Integration**: Extract code from any git revision, branch, or tag
23+
- **⚡ Fast & Lightweight**: Efficient caching and minimal dependencies
2224
- **🤖 AI-Optimized**: Designed specifically for use with AI coding assistants
2325

2426
## Installation
@@ -141,7 +143,7 @@ Returns:
141143

142144
## Usage Examples
143145

144-
### Example 1: Exploring a Python File
146+
### Example 1: Exploring Local Files
145147

146148
```python
147149
# First, see what's in the file
@@ -157,19 +159,35 @@ sig = get_signature("src/main.py", "process_data")
157159
# Returns: "def process_data(input_file: str, output_dir: Path) -> Dict[str, Any]:"
158160
```
159161

160-
### Example 2: Working with Classes
162+
### Example 2: Working with URLs
161163

162164
```python
163-
# Extract an entire class
165+
# Explore a GitHub file
166+
symbols = get_symbols("https://raw.githubusercontent.com/user/repo/main/src/api.py")
167+
168+
# Extract function from GitLab
169+
result = get_function("https://gitlab.com/user/project/-/raw/main/utils.py", "helper_func")
170+
171+
# Get lines from any URL
172+
lines = get_lines("https://example.com/code/script.py", 10, 25)
173+
```
174+
175+
### Example 3: Working with Classes
176+
177+
```python
178+
# Extract an entire class (local file)
164179
result = get_class("models/user.py", "User")
165180
# Returns: Complete User class with all methods
166181

182+
# Extract class from URL
183+
result = get_class("https://raw.githubusercontent.com/user/repo/main/models.py", "DatabaseModel")
184+
167185
# Get specific lines (e.g., just the __init__ method)
168186
lines = get_lines("models/user.py", 10, 25)
169187
# Returns: Lines 10-25 of the file
170188
```
171189

172-
### Example 3: Multi-Language Support
190+
### Example 4: Multi-Language Support
173191

174192
```javascript
175193
// Works with JavaScript/TypeScript

0 commit comments

Comments
 (0)