mongodocs-mcp
Version:
Lightning-fast semantic search for MongoDB documentation via Model Context Protocol. 10,000+ documents, <500ms search.
107 lines ⢠5.2 kB
JavaScript
import { MongoClient } from 'mongodb';
import dotenv from 'dotenv';
import colors from 'colors';
// Load environment variables
dotenv.config();
async function checkStatus() {
console.log(colors.cyan('\nš MONGODB MCP STATUS CHECK'));
console.log(colors.cyan('='.repeat(50)));
try {
// Connect to MongoDB
console.log(colors.yellow('\nš Connecting to MongoDB...'));
const client = new MongoClient(process.env.MONGODB_URI);
await client.connect();
const cluster = process.env.MONGODB_URI.split('@')[1]?.split('/')[0] || 'Unknown';
console.log(colors.green(`ā
Connected to: ${cluster}`));
// Check database and collections
const dbName = process.env.MONGODB_DATABASE || 'mongodb_semantic_docs';
const collectionName = process.env.MONGODB_COLLECTION || 'documents';
console.log(colors.yellow(`\nš Checking database: ${dbName}`));
const db = client.db(dbName);
const collections = await db.listCollections().toArray();
if (collections.length === 0) {
console.log(colors.red('ā Database is empty!'));
console.log(colors.yellow('š” Run: mongodocs-index to populate the database'));
await client.close();
return;
}
console.log(colors.green(`ā
Found ${collections.length} collections:`));
let totalDocuments = 0;
let hasEmbeddings = false;
for (const collection of collections) {
const coll = db.collection(collection.name);
const count = await coll.countDocuments();
totalDocuments += count;
const icon = collection.name === collectionName ? 'šÆ' : 'š';
const status = collection.name === collectionName ? ' (ACTIVE)' : '';
console.log(colors.white(` ${icon} ${collection.name}: ${count} documents${status}`));
if (count > 0 && collection.name === collectionName) {
const sample = await coll.findOne();
if (sample?.embedding) {
hasEmbeddings = true;
console.log(colors.green(` ā
Has embeddings (${sample.embedding.length} dimensions)`));
}
else {
console.log(colors.red(` ā No embeddings found`));
}
}
}
// Check vector search index
console.log(colors.yellow('\nš Checking vector search index...'));
try {
const collection = db.collection(collectionName);
const indexes = await collection.listSearchIndexes().toArray();
const vectorIndex = indexes.find((i) => i.name === 'semantic_search');
if (vectorIndex) {
const indexStatus = vectorIndex.status || 'UNKNOWN';
const status = indexStatus === 'READY' ? colors.green('READY') : colors.yellow(indexStatus);
console.log(colors.white(` š Vector index: ${status}`));
}
else {
console.log(colors.red(' ā No vector search index found'));
console.log(colors.yellow(' š” Create index in MongoDB Atlas for vector search'));
}
}
catch (error) {
console.log(colors.red(' ā Cannot check vector index (may not be supported)'));
}
// Environment check
console.log(colors.yellow('\nāļø Environment Configuration:'));
console.log(colors.white(` š Database: ${dbName}`));
console.log(colors.white(` š Collection: ${collectionName}`));
console.log(colors.white(` š Voyage API: ${process.env.VOYAGE_API_KEY ? 'ā
Set' : 'ā Missing'}`));
// Overall status
console.log(colors.cyan('\nšÆ OVERALL STATUS:'));
if (totalDocuments === 0) {
console.log(colors.red('ā NOT READY - No documents indexed'));
console.log(colors.yellow(' Run: mongodocs-index'));
}
else if (!hasEmbeddings) {
console.log(colors.red('ā NOT READY - Documents exist but no embeddings'));
console.log(colors.yellow(' Run: mongodocs-index to generate embeddings'));
}
else {
console.log(colors.green('ā
READY FOR MCP!'));
console.log(colors.white(` š ${totalDocuments} documents with embeddings`));
console.log(colors.white(' š Run: mongodocs-mcp to start server'));
}
await client.close();
}
catch (error) {
console.log(colors.red('\nā Status check failed:'));
console.log(colors.red(` ${error instanceof Error ? error.message : 'Unknown error'}`));
if (error instanceof Error && error.message.includes('authentication')) {
console.log(colors.yellow('\nš” Check your MONGODB_URI credentials'));
}
process.exit(1);
}
}
// Run if executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
checkStatus().catch(error => {
console.error(colors.red('ā Fatal error:'), error);
process.exit(1);
});
}
//# sourceMappingURL=status.js.map