Skip to content

gemini2026/mcp-server-k2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K2 MCP Server for Claude Code

Give Claude Code semantic search superpowers and persistent memory across sessions.

Why?

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

Quick Start

1. Install

cd mcp-server-k2
npm install
npm run build

2. Get K2 API Key

Sign up at knowledge2.ai and create an API key.

3. Configure Claude Code

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"
      }
    }
  }
}

4. Index Your Codebase

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.

5. Search!

Search K2 for "error handling patterns"

Available Tools

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

Environment Variables

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)

Example Workflow

Initial Setup

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".

Semantic Search

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...

Cross-Session Memory

# 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...

Viral Demo Script

"Semantic vs Grep" Challenge

# Traditional grep
grep -r "error" src/  # 2,847 results, mostly noise

# K2 semantic search
k2_search "production error handling strategies"  # 12 highly relevant results

Video Demo Outline

  1. 0:00 - Show grep failing to find "retry logic" (code uses "backoff")
  2. 0:15 - K2 search finds it instantly
  3. 0:30 - Index 10,000 file monorepo in seconds
  4. 0:45 - Cross-session memory demo
  5. 1:00 - "Claude Code + K2 = photographic memory"

Self-Hosted Option

K2 can run locally for privacy-sensitive codebases:

docker-compose up -d  # Start local K2 instance
export K2_API_HOST=http://localhost:8000

Contributing

PRs welcome! See the main K2 repository for development setup.

License

MIT

About

K2 MCP Server for Claude Code - semantic code search and persistent memory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors