UNPKG

smh-mongo-mcp-server

Version:

A Model Context Protocol server for MongoDB connections

33 lines (32 loc) 834 B
const handlePingRequest = async (options) => { const { client, db } = options; try { if (!client) { throw new Error("MongoDB connection is not available"); } const pong = await db.command({ ping: 1 }); if (pong.ok !== 1) { throw new Error(`MongoDB ping failed: ${pong.errmsg}`); } return { content: [ { type: "text", text: "MongoDB is alive! Pong!" } ] }; } catch (error) { return { content: [ { type: "text", text: `MongoDB ping failed: ${error?.message}` } ], isError: true }; } }; export { handlePingRequest };