Give Claude Code semantic search superpowers and persistent memory across sessions.
| Without K2 | With K2 |
|---|---|
grep "auth" finds exact matches |
Finds "authentication", "login", "session", "JWT" |
| Re-reads files every session | Index once, search forever |
| Pattern matching only | Semantic understanding of code |
| No cross-session memory | Remembers what you discussed last week |
cd mcp-server-k2
npm install
npm run buildSign up at knowledge2.ai and create an API key.
Add to your ~/.claude/mcp_servers.json:
{
"mcpServers": {
"k2": {
"command": "node",
"args": ["/path/to/mcp-server-k2/dist/index.js"],
"env": {
"K2_API_KEY": "your-api-key",
"K2_PROJECT_ID": "your-project-id",
"K2_CORPUS_ID": "your-corpus-id"
}
}
}
}In Claude Code:
Create a K2 corpus called "my-project" and index all TypeScript files
Claude will use the k2_create_corpus, k2_index_files_batch, and k2_build_indexes tools.
Search K2 for "error handling patterns"
| Tool | Description |
|---|---|
k2_search |
Semantic search across indexed code |
k2_index_file |
Index a single file |
k2_index_files_batch |
Index multiple files at once |
k2_status |
Check corpus status and stats |
k2_list_corpora |
List available corpora |
k2_create_corpus |
Create a new corpus |
k2_build_indexes |
Build/rebuild search indexes |
| Variable | Required | Description |
|---|---|---|
K2_API_KEY |
Yes | Your K2 API key |
K2_PROJECT_ID |
No | Default project ID |
K2_CORPUS_ID |
No | Default corpus ID |
K2_API_HOST |
No | API host (default: https://api.knowledge2.ai) |
User: Index this codebase into K2
Claude: I'll create a corpus and index your code.
[Uses k2_create_corpus to create "my-project"]
[Uses Glob to find all source files]
[Uses k2_index_files_batch to upload them]
[Uses k2_build_indexes to build search indexes]
Done! Indexed 347 files into corpus "my-project".
User: How do we handle database connection errors?
Claude: Let me search for that.
[Uses k2_search with query "database connection error handling"]
Found 8 relevant results:
[1] src/db/pool.ts (score: 0.892)
Connection retry logic with exponential backoff...
[2] src/services/user.ts (score: 0.847)
Catches connection errors and falls back to cache...
# Session 1
User: Explain the auth system
Claude: [explains auth, K2 indexes the conversation context]
# Session 2 (days later)
User: What did we discuss about auth?
Claude: [Uses k2_search to find previous context]
Last week we discussed the JWT-based auth system...
# Traditional grep
grep -r "error" src/ # 2,847 results, mostly noise
# K2 semantic search
k2_search "production error handling strategies" # 12 highly relevant results- 0:00 - Show grep failing to find "retry logic" (code uses "backoff")
- 0:15 - K2 search finds it instantly
- 0:30 - Index 10,000 file monorepo in seconds
- 0:45 - Cross-session memory demo
- 1:00 - "Claude Code + K2 = photographic memory"
K2 can run locally for privacy-sensitive codebases:
docker-compose up -d # Start local K2 instance
export K2_API_HOST=http://localhost:8000PRs welcome! See the main K2 repository for development setup.
MIT