Skip to main content
Glama
sergei-tofu-fedorov

Mongo MCP Server

MongoDB MCP Server

A Model Context Protocol (MCP) server that provides MongoDB database access for Claude Code. This server allows you to query MongoDB databases directly from Claude with configurable connection parameters.

Features

  • Master User Management: Find users by platform ID, email, account ID, or user ID

  • Invoice Management: Search and retrieve invoices by account ID or invoice ID

  • Connection Health: Check MongoDB connection status and health

  • Flexible Configuration: Support for command-line arguments, environment variables, and config files

  • Error Handling: Graceful fallback when database is unavailable

Installation

cd your-project-directory
mcp add https://github.com/sergei-tofu-fedorov/mongo_mcp.git

Then edit the generated .mcp.json to add your connection parameters:

{
  "mcpServers": {
    "mongo_mcp": {
      "command": "npx",
      "args": [
        "mongo-mcp-server",
        "--uri", "mongodb://your-host:27017",
        "--db", "your-database-name"
      ]
    }
  }
}

Option 2: Install from npm (coming soon)

npm install -g mongo-mcp-server

Option 3: Install from GitHub

npm install -g git+https://github.com/sergei-tofu-fedorov/mongo_mcp.git

Option 4: Clone and install locally

git clone https://github.com/sergei-tofu-fedorov/mongo_mcp.git
cd mongo_mcp
npm install
npm link  # Make it available globally

Usage

Add the server to your .mcp.json file in any project directory:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "mongo-mcp-server",
        "--mongo-uri", "mongodb://your-host:27017",
        "--database", "your-database-name"
      ]
    }
  }
}

Or with environment variables:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["mongo-mcp-server"],
      "env": {
        "MONGODB_URI": "mongodb://your-host:27017",
        "MONGODB_DATABASE": "your-database-name"
      }
    }
  }
}

Method 2: Install locally in project

  1. Clone this repo into your project or install as dependency

  2. Create a settings.json file in the project root:

{
  "mongodb": {
    "uri": "mongodb://your-host:27017",
    "database": "your-database-name"
  }
}
  1. Add to your .mcp.json:

{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": ["./path/to/mongo_mcp/server.js"]
    }
  }
}

Configuration Priority

The server accepts configuration in the following priority order:

  1. Command-line arguments (highest priority)

    # Full format
    mongo-mcp-server --mongo-uri mongodb://localhost:27017 --database mydb
    
    # Short format
    mongo-mcp-server --uri mongodb://localhost:27017 --db mydb
    
    # Single URI format (with database in path)
    mongo-mcp-server mongodb://localhost:27017/mydb
  2. Environment variables

    export MONGODB_URI="mongodb://localhost:27017"
    export MONGODB_DATABASE="mydb"
    mongo-mcp-server
  3. settings.json file

    {
      "mongodb": {
        "uri": "mongodb://localhost:27017",
        "database": "mydb"
      }
    }
  4. Default values (lowest priority)

    • URI: mongodb://localhost:27017

    • Database: mcpserver

Available Tools

Connection Management

  • check_connection: Check if MongoDB connection is active and healthy

Master User Tools

  • find-master-user-by-platform-id: Find master user by platform ID (case-insensitive search)

    • Parameters: platformId (string), limit (number, default: 10)

  • find-master-user-by-email: Find master user by email (case-insensitive search)

    • Parameters: email (string), limit (number, default: 10)

  • find-master-user-by-id: Find a specific master user by their ID

    • Parameters: id (string)

  • find-master-user-by-account-id: Find master user by account ID (case-insensitive search)

    • Parameters: accountId (string), limit (number, default: 10)

Invoice Tools

  • find-invoices-by-account-id: Find invoices by account ID (case-insensitive search)

    • Parameters: accountId (string), limit (number, default: 10)

  • find-invoice-by-id: Find a specific invoice by its ID

    • Parameters: id (string)

Quick Start with mcp add

  1. Navigate to any directory where you want to use MongoDB tools:

    cd C:\AI\mongo_test
  2. Add the MongoDB MCP server:

    mcp add https://github.com/sergei-tofu-fedorov/mongo_mcp.git
  3. Edit the generated .mcp.json file to add your MongoDB connection:

    {
      "mcpServers": {
        "mongo_mcp": {
          "command": "npx",
          "args": [
            "mongo-mcp-server",
            "mongodb://your-host:27017/your-database"
          ]
        }
      }
    }
  4. Start Claude Code:

    claude-code
  5. Use MongoDB tools directly in Claude:

    find master user by email john@example.com
    find invoices by account 2djcl2neh9-0f9f3bd0e
    check mongodb connection status

Example Usage in Claude Code

Once configured, you can use these tools directly in Claude Code:

find master user by email john@example.com
find invoices by account 2djcl2neh9-0f9f3bd0e
check mongodb connection status

Development

Requirements

  • Node.js >= 18.0.0

  • MongoDB instance (local or remote)

Running in Development

git clone https://github.com/sergei-tofu-fedorov/mongo_mcp.git
cd mongo_mcp
npm install
npm run dev  # Runs with --watch for auto-reload

Testing with Different Configurations

# Test with command line args
node server.js --mongo-uri mongodb://localhost:27017 --database testdb

# Test with environment variables
MONGODB_URI=mongodb://localhost:27017 MONGODB_DATABASE=testdb node server.js

# Test with settings.json (create the file first)
node server.js

Troubleshooting

Connection Issues

  • Verify MongoDB is running and accessible

  • Check firewall settings and network connectivity

  • Ensure the URI format is correct: mongodb://host:port or mongodb+srv://cluster.example.com

  • Validate database name and permissions

Permission Issues

  • Ensure the MongoDB user has read permissions on the target database

  • Check that the user can access the required collections

MCP Server Issues

  • Verify Claude Code can find the server executable

  • Check the .mcp.json configuration syntax

  • Look for error messages in Claude Code's output

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Available Tools

1 tool
check_connectionB

Check if MongoDB connection is active and healthy

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

B3.2/5.0
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.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev1.0.0
    • First observedcheck_connection

TDQS

B3.2/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap in purpose. The tool 'check_connection' has a single, clear function, making it impossible for an agent to confuse it with any other tool.

Naming Consistency5/5

The single tool name follows a consistent verb_noun pattern ('check_connection'), and with only one tool, there is no inconsistency in naming conventions. The naming is straightforward and predictable.

Tool Count2/5

A single tool is too few for a MongoDB server, which typically requires CRUD operations, querying, indexing, and other database management tasks. This minimal set severely limits the server's utility and scope, indicating a significant mismatch with the expected domain coverage.

Completeness1/5

The tool set is severely incomplete for a MongoDB server. It lacks essential operations like insert, find, update, delete, or any other database interactions, leaving major gaps that will cause agent failures in performing typical database tasks. The single tool only handles connection checking, which is insufficient for the stated purpose.

Related MCP Connectors