@morphllm/morphsdk
v0.2.62
Published
TypeScript SDK and CLI for Morph Fast Apply integration
Downloads
10,592
Readme
Morph SDK
Production-ready tools for AI coding agents: Repo Storage with automatic code indexing, semantic search, and Fast Apply (10,500 tokens/s).
Install
npm install @morphllm/morphsdkGet your API key: morphllm.com/dashboard/api-keys
export MORPH_API_KEY="sk-your-key-here"Features
- 🔍 Semantic Search - State of the Art Code Search (AST aware chunking, morph-v4-embedding + morph-v4-rerank)
- 📦 Repo Storage - Agent native git with automatic code indexing, agent metadata, and chat history
- ⚡ Fast Apply - 98% 1st pass accuracy, AI-powered code editing at 10,500 tokens/s
- 🤖 Agent Tools - Ready-to-use tools for Anthropic, OpenAI, and Vercel AI SDK
Quick Start
Repo Storage + Semantic Search
import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
// Initialize repo
await morph.git.init({ repoId: 'my-project', dir: './my-project' });
// Commit with agent metadata
await morph.git.add({ dir: './my-project', filepath: '.' });
await morph.git.commit({
dir: './my-project',
message: 'Add authentication'
});
// Push (triggers automatic code embedding, 3-8s)
await morph.git.push({ dir: './my-project' });
// Search your code with natural language
const results = await morph.codebaseSearch.search({
query: "Where is the OAuth login implemented?",
repoId: 'my-project',
targetDirectories: [] // or ['src/auth'] to narrow search
});
console.log(results.results[0].content);Fast Apply
import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
// AI-powered file editing
await morph.fastApply.execute({
target_filepath: 'src/app.ts',
instructions: 'Add error handling',
code_edit: 'try { ... } catch (e) { ... }'
});Repo Storage
Git built for AI agents with automatic code indexing and semantic search.
Git Operations
// Initialize
await morph.git.init({ repoId: 'my-project', dir: './my-project' });
// Clone
await morph.git.clone({ repoId: 'my-project', dir: './local-copy' });
// Stage and commit
await morph.git.add({ dir: './my-project', filepath: '.' });
await morph.git.commit({
dir: './my-project',
message: 'Add feature'
});
// Push (triggers code embedding in background)
await morph.git.push({ dir: './my-project' });
// Status and history
const files = await morph.git.statusMatrix({ dir: './my-project' });
const commits = await morph.git.log({ dir: './my-project', depth: 10 });
// Branch operations
await morph.git.branch({ dir: './my-project', name: 'feature' });
const branches = await morph.git.listBranches({ dir: './my-project' });
await morph.git.checkout({ dir: './my-project', ref: 'main' });Agent Metadata
Store chat history and browser recordings with commits:
// Commit with metadata
const sha = await morph.git.commit({
dir: './my-project',
message: 'Implement user auth',
chatHistory: [
{ role: 'user', content: 'Add OAuth' },
{ role: 'assistant', content: 'Adding Google OAuth' }
],
recordingId: 'rec_abc123'
});
// Retrieve metadata later
const metadata = await morph.git.getCommitMetadata({
dir: './my-project',
commitSha: sha
});
console.log(metadata?.chatHistory);
console.log(metadata?.recordingId);State of the Art Code Semantic Search
When you push, Morph automatically embeds your code for semantic search. Each commit is indexed separately:
// Search latest code on 'main'
await morph.codebaseSearch.search({
query: "auth logic",
repoId: 'my-project'
});
// Advanced: Search specific branch
await morph.codebaseSearch.search({
query: "auth logic",
repoId: 'my-project',
branch: 'develop'
});
// Advanced: Search exact commit
await morph.codebaseSearch.search({
query: "auth logic",
repoId: 'my-project',
commitHash: 'abc123...'
});Semantic Search
Two-stage retrieval: embedding similarity (morph-v4-embedding) + reranking (morph-v4-rerank).
As Agent Tool
import { createCodebaseSearchTool } from '@morphllm/morphsdk/tools/anthropic';
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const tool = createCodebaseSearchTool({ repoId: 'my-project' });
const response = await client.messages.create({
model: "claude-sonnet-4-5-20250929",
tools: [tool],
messages: [{ role: "user", content: "Find authentication code" }]
});Direct Search
const results = await morph.codebaseSearch.search({
query: "How does authentication work?",
repoId: 'my-project',
targetDirectories: ["src/auth"], // or [] for all
limit: 10
});
results.results.forEach(r => {
console.log(`${r.filepath} (${(r.rerankScore * 100).toFixed(1)}% relevant)`);
console.log(r.content);
});How It Works
- Embedding Search: Query embedded with morph-v4-embedding, vector search retrieves top 50 candidates (~50ms)
- Reranking: Candidates scored with morph-v4-rerank for precision (~150ms)
- Results: Top 10 most relevant code chunks (~1230ms total)
Fast Apply
AI-powered code editing at 10,500 tokens/s. See tools/fastapply/README.md for details.
Agent Tools
Ready-to-use tools for popular AI frameworks:
- Anthropic SDK -
@morphllm/morphsdk/tools/anthropic - OpenAI SDK -
@morphllm/morphsdk/tools/openai - Vercel AI SDK -
@morphllm/morphsdk/tools/vercel
Available tools:
createCodebaseSearchTool- Semantic code searchcreateFastApplyTool- AI-powered code editingcreateBrowserTool- Browser automationcreateWarpGrepTool- Fast grep with AI parsing
Documentation
Full docs: docs.morphllm.com
Key Pages:
- Repo Storage - Git operations and agent metadata
- Semantic Search - Code search with natural language
- Fast Apply - AI-powered code editing
