code-context-mcp
Version:
MCP server for semantic code search powered by MongoDB Atlas Vector Search and Voyage AI embeddings
139 lines (125 loc) • 6 kB
JavaScript
import { envManager } from "@mongodb/claude-context-core";
/**
* Get the optimal Voyage AI model based on use case
*/
export function getOptimalVoyageModel() {
const model = envManager.get('VOYAGE_MODEL');
// Validate model selection
if (model === 'voyage-code-3' || model === 'voyage-3.5' || model === 'voyage-finance-2') {
return model;
}
// Default to voyage-code-3 for code repositories
return 'voyage-code-3';
}
export function createMcpConfig() {
// Debug: Print MongoDB and Voyage configuration
console.log(`[DEBUG] 🔍 MongoDB + Voyage AI Configuration:`);
console.log(`[DEBUG] MONGODB_URI: ${envManager.get('MONGODB_URI') ? '✅ SET' : '❌ NOT SET'}`);
console.log(`[DEBUG] MONGODB_DATABASE: ${envManager.get('MONGODB_DATABASE') || 'claude_context (default)'}`);
console.log(`[DEBUG] MONGODB_COLLECTION: ${envManager.get('MONGODB_COLLECTION') || 'code_embeddings (default)'}`);
console.log(`[DEBUG] VOYAGE_API_KEY: ${envManager.get('VOYAGE_API_KEY') ? '✅ SET' : '❌ NOT SET'}`);
console.log(`[DEBUG] VOYAGE_MODEL: ${envManager.get('VOYAGE_MODEL') || 'voyage-code-3 (default)'}`);
const config = {
name: envManager.get('MCP_SERVER_NAME') || "MongoDB + Voyage AI Context Server",
version: envManager.get('MCP_SERVER_VERSION') || "1.0.0",
// MongoDB Atlas Configuration
mongodbUri: envManager.get('MONGODB_URI') || '',
mongodbDatabase: envManager.get('MONGODB_DATABASE') || 'claude_context',
mongodbCollection: envManager.get('MONGODB_COLLECTION') || 'code_embeddings',
// Voyage AI Configuration (MongoDB Exclusive)
voyageApiKey: envManager.get('VOYAGE_API_KEY') || '',
voyageModel: getOptimalVoyageModel(),
// Performance settings
batchSize: parseInt(envManager.get('BATCH_SIZE') || '10'),
maxConcurrency: parseInt(envManager.get('MAX_CONCURRENCY') || '5'),
incrementalSync: envManager.get('INCREMENTAL_SYNC') !== 'false'
};
// Validate required configuration
if (!config.mongodbUri) {
throw new Error('❌ MONGODB_URI environment variable is required. Please set your MongoDB Atlas connection string.');
}
if (!config.voyageApiKey) {
throw new Error('❌ VOYAGE_API_KEY environment variable is required. Please set your Voyage AI API key.');
}
return config;
}
export function logConfigurationSummary(config) {
// Log configuration summary before starting server
console.log(`[MCP] 🚀 Starting MongoDB + Voyage AI Context Server`);
console.log(`[MCP] Configuration Summary:`);
console.log(`[MCP] Server: ${config.name} v${config.version}`);
console.log(`[MCP] `);
console.log(`[MCP] 🍃 MongoDB Atlas:`);
console.log(`[MCP] Database: ${config.mongodbDatabase}`);
console.log(`[MCP] Collection: ${config.mongodbCollection}`);
console.log(`[MCP] Connection: ✅ Configured`);
console.log(`[MCP] `);
console.log(`[MCP] 🚢 Voyage AI (MongoDB Exclusive):`);
console.log(`[MCP] Model: ${config.voyageModel}`);
console.log(`[MCP] API Key: ✅ Configured`);
console.log(`[MCP] `);
console.log(`[MCP] ⚡ Performance:`);
console.log(`[MCP] Batch Size: ${config.batchSize}`);
console.log(`[MCP] Max Concurrency: ${config.maxConcurrency}`);
console.log(`[MCP] Incremental Sync: ${config.incrementalSync ? '✅' : '❌'}`);
console.log(`[MCP] `);
console.log(`[MCP] 🔧 Initializing server components...`);
}
export function showHelpMessage() {
console.log(`
MongoDB + Voyage AI Context MCP Server
Powered by MongoDB Atlas Vector Search and Voyage AI Embeddings
Usage: npx @mongodb/claude-context-mcp@latest [options]
Options:
--help, -h Show this help message
Required Environment Variables:
MONGODB_URI MongoDB Atlas connection string (required)
Format: mongodb+srv://username:password@cluster.mongodb.net/
VOYAGE_API_KEY Voyage AI API key (required)
Get from: https://dash.voyageai.com/
Optional Environment Variables:
MONGODB_DATABASE Database name (default: claude_context)
MONGODB_COLLECTION Collection name (default: code_embeddings)
VOYAGE_MODEL Voyage AI model selection:
- voyage-code-3 (default, best for code)
- voyage-3.5 (general purpose)
- voyage-finance-2 (financial code)
Performance Tuning:
BATCH_SIZE Embedding batch size (default: 10)
MAX_CONCURRENCY Parallel operations (default: 5)
INCREMENTAL_SYNC Enable incremental sync (default: true)
Server Configuration:
MCP_SERVER_NAME Server name
MCP_SERVER_VERSION Server version
Examples:
# Start with MongoDB Atlas and Voyage AI
MONGODB_URI="mongodb+srv://user:pass@cluster.mongodb.net/" \\
VOYAGE_API_KEY="va_xxx" \\
npx @mongodb/claude-context-mcp@latest
# Use voyage-3.5 model for mixed content
MONGODB_URI="mongodb+srv://..." \\
VOYAGE_API_KEY="va_xxx" \\
VOYAGE_MODEL="voyage-3.5" \\
npx @mongodb/claude-context-mcp@latest
# Optimize for large codebases
MONGODB_URI="mongodb+srv://..." \\
VOYAGE_API_KEY="va_xxx" \\
BATCH_SIZE="20" \\
MAX_CONCURRENCY="10" \\
npx @mongodb/claude-context-mcp@latest
MongoDB Atlas Setup:
1. Sign up at: https://www.mongodb.com/cloud/atlas/register
2. Create a free M0 cluster
3. Get your connection string from: Database > Connect > Drivers
4. Create Atlas Vector Search index via the UI
Voyage AI Setup:
1. Sign up at: https://dash.voyageai.com/
2. Get your API key from the dashboard
3. Choose the appropriate model for your use case
For more information:
MongoDB Atlas: https://docs.atlas.mongodb.com/
Voyage AI: https://docs.voyageai.com/
GitHub: https://github.com/mongodb/claude-context
`);
}
//# sourceMappingURL=config.js.map