Skip to main content
Glama
sergei-tofu-fedorov

Mongo MCP Server

check_connection

Verify MongoDB database connectivity and health status to ensure the connection is active and operational.

Instructions

Check if MongoDB connection is active and healthy

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'check_connection' tool. It checks the MongoDB connection status, performs a ping and retrieves server status with timeouts, and returns a text content response indicating connection health or errors.
    async checkConnection() { const timeout = (ms) => new Promise((_, reject) => setTimeout(() => reject(new Error('Operation timed out')), ms) ); try { if (!this.mongoClient || !this.db || !this.isConnected) { return { content: [ { type: "text", text: `MongoDB not available\nTarget URI: ${MONGODB_URI}\nTarget Database: ${DATABASE_NAME}\nStatus: Disconnected - MCP server is running without database connection`, }, ], }; } // Apply 10-second timeout to ping and serverStatus operations await Promise.race([ this.db.admin().ping(), timeout(10000) ]); const serverStatus = await Promise.race([ this.db.admin().serverStatus(), timeout(10000) ]); return { content: [ { type: "text", text: `MongoDB connection is healthy\nConnected to: ${MONGODB_URI}\nDatabase: ${DATABASE_NAME}\nServer version: ${serverStatus.version}\nUptime: ${serverStatus.uptime} seconds`, }, ], }; } catch (error) { this.isConnected = false; this.mongoClient = null; this.db = null; return { content: [ { type: "text", text: `MongoDB connection lost: ${error.message}\nTarget URI: ${MONGODB_URI}\nTarget Database: ${DATABASE_NAME}\nStatus: MCP server continues running without database connection`, }, ], }; } }
  • server.js:121-129 (registration)
    Registration of the 'check_connection' tool in the ListTools response, including its name, description, and empty input schema.
    { name: "check_connection", description: "Check if MongoDB connection is active and healthy", inputSchema: { type: "object", properties: {}, required: [], }, },
  • Input schema for the 'check_connection' tool, which requires no parameters (empty object).
    inputSchema: { type: "object", properties: {}, required: [], },
  • Dispatch case in the generic CallToolRequestHandler that routes 'check_connection' calls to the specific handler method.
    case "check_connection": return await this.checkConnection();
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sergei-tofu-fedorov/mongo_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server