mcp-mongo-server
Version:
A Model Context Protocol server for MongoDB connections
21 lines (20 loc) • 669 B
JavaScript
export async function handlePingRequest({ request, client, db, isReadOnlyMode, }) {
try {
// Check MongoDB connection
if (!client) {
throw new Error("MongoDB connection is not available");
}
// Ping MongoDB to verify connection
const pong = await db.command({ ping: 1 });
if (pong.ok !== 1) {
throw new Error(`MongoDB ping failed: ${pong.errmsg}`);
}
return {};
}
catch (error) {
if (error instanceof Error) {
throw new Error(`MongoDB ping failed: ${error.message}`);
}
throw new Error("MongoDB ping failed: Unknown error");
}
}