MCP server for semantic code search powered by MongoDB Atlas Vector Search and Voyage AI embeddings
npm install code-context-mcp


An MCP (Model Context Protocol) server that provides semantic code search capabilities to AI assistants using MongoDB Atlas Vector Search and Voyage AI embeddings.
- Semantic Code Search: Find relevant code based on meaning, not just keywords
- MongoDB Atlas Vector Search: Unified platform for vectors and data
- Voyage AI Embeddings: State-of-the-art code embeddings (MongoDB exclusive)
- Native Hybrid Search: Combine vector and text search with MongoDB's $rankFusion
- Real-time Sync: Automatic updates with MongoDB Change Streams
- Multi-language Support: TypeScript, JavaScript, Python, Java, Go, Rust, C++
1. MongoDB Atlas Account (Free tier available)
- Sign up at: https://www.mongodb.com/cloud/atlas/register
- Create a cluster and get your connection string
2. Voyage AI API Key (200M tokens free)
- Sign up at: https://dash.voyageai.com/
- Get your API key
``bashInstall globally
npm install -g code-context-mcp
$3
Add to your Claude Desktop configuration:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json`json
{
"mcpServers": {
"code-context": {
"command": "npx",
"args": ["code-context-mcp"],
"env": {
"MONGODB_URI": "mongodb+srv://username:password@cluster.mongodb.net/",
"VOYAGE_API_KEY": "va_xxx"
}
}
}
}
`$3
#### Cursor
Add to
~/.cursor/mcp.json:`json
{
"mcpServers": {
"code-context": {
"command": "npx",
"args": ["code-context-mcp"],
"env": {
"MONGODB_URI": "mongodb+srv://...",
"VOYAGE_API_KEY": "va_xxx"
}
}
}
}
`#### Windsurf
Add to your Windsurf configuration:
`json
{
"mcpServers": {
"code-context": {
"command": "npx",
"args": ["code-context-mcp"],
"env": {
"MONGODB_URI": "mongodb+srv://...",
"VOYAGE_API_KEY": "va_xxx"
}
}
}
}
`🛠️ Available Tools
The MCP server provides the following tools to AI assistants:
$3
Index a codebase for semantic search.`typescript
{
"path": "/path/to/project",
"name": "my-project"
}
`$3
Search for code semantically.`typescript
{
"projectPath": "/path/to/project",
"query": "authentication middleware",
"limit": 10,
"threshold": 0.7
}
`$3
Retrieve specific file content.`typescript
{
"projectPath": "/path/to/project",
"relativePath": "src/auth.ts",
"startLine": 10,
"endLine": 50
}
`$3
List all indexed projects.$3
Clear the index for a project.`typescript
{
"projectPath": "/path/to/project"
}
`$3
Get statistics about an indexed project.`typescript
{
"projectPath": "/path/to/project"
}
`⚙️ Configuration
$3
| Variable | Description | Required | Default |
|----------|-------------|----------|---------|
|
MONGODB_URI | MongoDB Atlas connection string | ✅ | - |
| VOYAGE_API_KEY | Voyage AI API key | ✅ | - |
| MONGODB_DATABASE | Database name | ❌ | code_context |
| MONGODB_COLLECTION | Collection name | ❌ | embeddings |
| VOYAGE_MODEL | Voyage AI model | ❌ | voyage-3.5 |
| BATCH_SIZE | Embedding batch size | ❌ | 10 |
| MAX_FILE_SIZE | Max file size (MB) | ❌ | 10 |$3
| Model | Best For | Performance |
|-------|----------|-------------|
|
voyage-context-3 | RAG systems, long documents | +14.24% vs OpenAI |
| voyage-3-large | Highest accuracy | +9.74% vs OpenAI |
| voyage-3.5 | General purpose (default) | +8.26% vs OpenAI |
| voyage-3.5-lite | High throughput | +6.34% vs OpenAI |
| voyage-code-3 | Source code | Best for code |🏗️ MongoDB Atlas Setup
$3
In MongoDB Atlas:
1. Navigate to your cluster
2. Click "Search" → "Create Search Index"
3. Choose "Atlas Vector Search"
4. Use this configuration:
`json
{
"fields": [{
"type": "vector",
"path": "embedding",
"numDimensions": 1024,
"similarity": "cosine"
}]
}
`$3
For MongoDB 8.0+, create both vector and text indexes:
`json
{
"mappings": {
"fields": {
"embedding": {
"type": "knnVector",
"dimensions": 1024,
"similarity": "cosine"
},
"content": {
"type": "string",
"analyzer": "lucene.standard"
}
}
}
}
`📊 Performance
Based on 2025 benchmarks:
- Storage: 83% less than competitors with int8 quantization
- Accuracy: Up to 14.24% better retrieval than OpenAI
- Speed: Native hybrid search 30% faster
- Cost: 96% storage reduction with binary quantization
🔍 Example Usage in Claude
Once configured, you can use natural language commands:
`
"Index my TypeScript project at /Users/me/my-project""Search for authentication middleware in my-project"
"Show me the implementation of the UserService class"
"Find all database connection code"
"What files handle error logging?"
`🐛 Troubleshooting
$3
1. MongoDB Connection Failed
- Verify your connection string
- Check IP whitelist in Atlas
- Ensure cluster is running
2. Voyage AI Authentication Failed
- Verify API key is correct
- Check API key has credits
3. MCP Not Responding
- Check logs in stderr
- Verify environment variables
- Restart AI assistant
$3
Set
DEBUG=true in environment variables for verbose logging:`json
{
"env": {
"DEBUG": "true",
"MONGODB_URI": "...",
"VOYAGE_API_KEY": "..."
}
}
``Contributions are welcome! Please see our Contributing Guide.
MIT License - see LICENSE for details.
- GitHub Repository
- MongoDB Atlas
- Voyage AI
- Model Context Protocol
---
Built with 💚 by MongoDB and Voyage AI