Loading...
Loading...
Integration guide for Morph's WarpGrep (fast agentic code search) and Fast Apply (10,500 tok/s code editing). Use when building coding agents that need fast, accurate code search or need to apply AI-generated edits to code efficiently. Particularly useful for large codebases, deep logic queries, bug tracing, and code path analysis.
npx skill4agent add letta-ai/skills morph-warpgrepexport MORPH_API_KEY="your-api-key"bun add @morphllm/morphsdk
# or
npm install @morphllm/morphsdkripgrep# macOS
brew install ripgrep
# Ubuntu/Debian
sudo apt install ripgrep
# Verify installation
rg --version# Clone a test repo (or use any existing codebase)
git clone https://github.com/letta-ai/letta-code.git test-repo
# Install SDK
cd test-repo
bun add @morphllm/morphsdk
# Run test script
export MORPH_API_KEY="your-key"
bun ../scripts/test-warpgrep.ts .======================================================================
MORPH WARPGREP TEST
======================================================================
Repo: .
SDK: @morphllm/morphsdk
======================================================================
| Query | Result | Time | Files |
|------------------------------------|--------|--------|-------|
| Find the main entry point | ✅ | 5.2s | 2 |
| Find authentication logic | ✅ | 4.1s | 4 |
| Find where configuration is handled | ✅ | 3.8s | 3 |
| Find error handling patterns | ✅ | 4.5s | 5 |
======================================================================
Results: 4 passed, 0 failed
======================================================================greprgimport { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
const result = await morph.warpGrep.execute({
query: 'Find authentication middleware',
repoRoot: '.'
});
if (result.success) {
for (const ctx of result.contexts) {
console.log(`File: ${ctx.file}`);
console.log(ctx.content);
}
} else {
console.error('Search failed');
}interface WarpGrepResult {
success: boolean;
contexts: Array<{
file: string; // File path relative to repo root
content: string; // File content with relevant code
}>;
summary?: string; // Human-readable summary
}import { MorphClient } from '@morphllm/morphsdk';
import Anthropic from '@anthropic-ai/sdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
const anthropic = new Anthropic();
// Define WarpGrep as a tool
const tools = [{
name: 'warpgrep_search',
description: 'Search codebase for relevant code. Use for finding implementations, tracing bugs, or understanding code flow.',
input_schema: {
type: 'object',
properties: {
query: { type: 'string', description: 'What to search for' }
},
required: ['query']
}
}];
// Handle tool calls
async function handleToolCall(name: string, input: { query: string }) {
if (name === 'warpgrep_search') {
const result = await morph.warpGrep.execute({
query: input.query,
repoRoot: process.cwd()
});
if (result.success) {
return result.contexts.map(c => `## ${c.file}\n${c.content}`).join('\n\n');
}
return 'No results found';
}
}import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
const result = await morph.fastApply.apply({
originalCode: `function divide(a, b) {
return a / b;
}`,
editSnippet: `function divide(a, b) {
if (b === 0) throw new Error("Division by zero");
return a / b;
}`
});
console.log(result.mergedCode);const response = await fetch('https://api.morphllm.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.MORPH_API_KEY}`
},
body: JSON.stringify({
model: 'morph-v3-fast', // or 'morph-v3-large' for complex edits
messages: [{
role: 'user',
content: `<instruction>Add error handling</instruction>
<code>function divide(a, b) { return a / b; }</code>
<update>function divide(a, b) {
if (b === 0) throw new Error("Division by zero");
return a / b;
}</update>`
}],
temperature: 0
})
});
const data = await response.json();
const mergedCode = data.choices[0].message.content;| Query | Result | Time | Files Found |
|---|---|---|---|
| "Find authentication logic" | ✅ | 4.2s | |
| "Find the main CLI entry point" | ✅ | 5.8s | |
| "Find where models are configured" | ✅ | 3.1s | |
| "Find how memory blocks work" | ✅ | 3.9s | |
| "Find the settings manager" | ✅ | 2.9s | |
┌─────────────────────────────────────────────────────────────┐
│ Turn 1: Analyze query, map repo structure, initial search │
├─────────────────────────────────────────────────────────────┤
│ Turn 2-3: Refine search, read specific files │
├─────────────────────────────────────────────────────────────┤
│ Turn 4: Return all relevant code locations │
└─────────────────────────────────────────────────────────────┘| Tool | Description | Implementation |
|---|---|---|
| Regex search across files | Uses ripgrep ( |
| Read file contents | Local filesystem |
| Show directory structure | Local filesystem |
┌──────────────────────────────────────────────────────────────┐
│ Your Code / Agent │
└──────────────────────────┬───────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────┐
│ @morphllm/morphsdk │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 1. Build repo structure │ │
│ │ 2. Send query to Morph API │ │
│ │ 3. Execute local tools (grep, read, list_dir) │ │
│ │ 4. Multi-turn refinement │ │
│ │ 5. Return relevant code contexts │ │
│ └─────────────────────────────────────────────────────────┘ │
└──────────────────────────┬───────────────────────────────────┘
│
┌──────────────┴──────────────┐
▼ ▼
┌───────────────────────┐ ┌───────────────────────┐
│ Morph API │ │ Local Filesystem │
│ (morph-warp-grep-v1) │ │ (ripgrep, fs) │
└───────────────────────┘ └───────────────────────┘| Metric | Without WarpGrep | With WarpGrep | Improvement |
|---|---|---|---|
| Input Tokens | 14K | 9K | 39% fewer |
| Agent Turns | 35.0 | 26.0 | 26% fewer |
| Tasks Solved | 74.4% | 81.9% | 10% more |
import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
// 1. Search for relevant code
const result = await morph.warpGrep.execute({
query: 'Where is the payment processing logic?',
repoRoot: '.'
});
// 2. Use found contexts to inform next steps
if (result.success) {
const relevantFiles = result.contexts.map(c => c.file);
console.log('Found relevant files:', relevantFiles);
// Now read/edit these specific files
}import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
// 1. Find the code to modify
const search = await morph.warpGrep.execute({
query: 'Find the user validation function',
repoRoot: '.'
});
if (search.success && search.contexts.length > 0) {
const targetFile = search.contexts[0];
// 2. Apply an edit
const result = await morph.fastApply.apply({
originalCode: targetFile.content,
editSnippet: '// Add your modified version here'
});
console.log(result.mergedCode);
}# Install MCP server
claude mcp add morph --scope user -e MORPH_API_KEY=YOUR_API_KEY --npx -y @morphllm/morphmcpwarpgrep_codebase_search# Install ripgrep
brew install ripgrep # macOS
sudo apt install ripgrep # Ubuntu/Debian
# Verify
rg --version# Verify API key works
curl -X POST https://api.morphllm.com/v1/chat/completions \
-H "Authorization: Bearer $MORPH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"morph-v3-fast","messages":[{"role":"user","content":"test"}]}'bun add @morphllm/morphsdk@latest
# or
npm install @morphllm/morphsdk@latest