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();
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it implies a read-only, non-destructive operation (checking connection status), it fails to specify what 'active and healthy' entails (e.g., latency thresholds, authentication status), the response format, or any side effects like logging. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any fluff or redundancy. It is front-loaded with the core action and resource, making it easy to parse and understand immediately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (no parameters, no output schema, no annotations), the description is minimally adequate. It states what the tool does but lacks details on behavioral traits, response format, or usage context. For a diagnostic tool, more information on what constitutes 'healthy' would enhance completeness, but the current description meets the basic requirement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, and schema description coverage is 100%, meaning there are no parameters to document. The description appropriately does not mention parameters, aligning with the schema. A baseline of 4 is applied since no parameter information is needed, though it doesn't add value beyond the schema's indication of no parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Check if MongoDB connection is active and healthy.' It specifies the verb ('check') and the resource ('MongoDB connection'), making the intent unambiguous. However, with no sibling tools mentioned, there's no opportunity to distinguish from alternatives, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives or in what context it should be invoked. It lacks any mention of prerequisites, timing, or scenarios where this check is appropriate, leaving the agent without operational context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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