Skip to main content
Glama
kawaljain

nodejs-mcp-mongodb

by kawaljain

nodejs-mcp-mongodb

Simple MCP (Model Context Protocol) server built with Node.js, TypeScript, the official MCP SDK, and MongoDB.

Features

This server provides three MCP tools:

  1. get_business_summary

    • Returns:

      • total users

      • active users

      • paid users

      • pending payments

      • new users (last 7 days)

  2. get_new_users

    • Input:

      • days (number)

    • Returns users created during the given period.

  3. get_pending_payments

    • Returns all customers with pending payments.

Related MCP server: jobs-mcp-server

Transport

This server currently runs over stdio — the standard transport for local MCP servers. The client (e.g. Claude Desktop, Claude Code) launches this server as a subprocess and communicates over stdin/stdout. This is the right choice for a server that runs locally against your own database.

Note: The legacy HTTP+SSE transport is deprecated in the MCP spec in favor of Streamable HTTP. This repo doesn't implement a remote transport yet — stdio only, by design, for local use. Streamable HTTP support (for hosting this as a remote/shared server) is a possible future addition.

Project Structure

  • src/index.ts - MCP server and tool handlers

  • src/config/env.ts - environment loading

  • src/db/mongo.ts - MongoDB connection helper

  • src/services/users.ts - MongoDB queries for tool responses

  • seed/seed.ts - sample MongoDB seed script

  • .env.example - required environment variables

Setup

  1. Install dependencies:

npm install
  1. Create your env file:

cp .env.example .env
  1. Update .env values:

MONGODB_URI=mongodb://localhost:27017
MONGODB_DB_NAME=mcp_business

Works with a local MongoDB (including Docker) or MongoDB Atlas — just use the appropriate connection string (mongodb://... for local, mongodb+srv://... for Atlas). 4. Seed sample data:

npm run seed
  1. Build the server:

npm run build

This compiles to dist/src/index.js (note: nested under dist/src/, not directly in dist/). 6. Run the MCP server over stdio:

npm start

Development

Run directly with TypeScript:

npm run dev

Connecting to Claude Desktop (macOS)

  1. Build the project first (npm install && npm run build) and note the absolute path to dist/src/index.js.

  2. Find your Node binary path: which node (if you use nvm, this will be a versioned path like ~/.nvm/versions/node/vX.X.X/bin/node).

  3. Open Claude Desktop's config file:

    ~/Library/Application Support/Claude/claude_desktop_config.json
  4. Add a mcpServers entry (merge with any existing config — don't overwrite the whole file):

    {
      "mcpServers": {
        "mongodb-business": {
          "command": "/absolute/path/to/node",
          "args": ["/absolute/path/to/nodejs-mcp-mongodb/dist/src/index.js"],
          "env": {
            "MONGODB_URI": "mongodb://localhost:27017",
            "MONGODB_DB_NAME": "mcp_business"
          }
        }
      }
    }

    Use an absolute path to your Node binary, not just "node" — GUI apps on macOS don't always inherit your shell's PATH.

  5. Fully quit Claude Desktop (Cmd+Q) and reopen it — the config is only read on startup.

  6. Check the tools/connectors panel in the chat box for mongodb-business with its 3 tools listed.

Troubleshooting

  • "Server disconnected" / MODULE_NOT_FOUND: Double-check the build output path is dist/src/index.js, not dist/index.js.

  • Tool calls fail with a generic internal error: Check the MCP log at ~/Library/Logs/Claude/mcp-server-<name>.log on macOS. If the log doesn't show a clear cause, test the server directly by piping a JSON-RPC request into it via stdin to see the raw error.

  • Works when run manually but not from Claude Desktop: Usually an environment variable mismatch — confirm the env block in claude_desktop_config.json exactly matches your working .env file (the subprocess Claude Desktop spawns does not inherit your shell's environment).

  • Using MongoDB Atlas: make sure your current IP is allowlisted under Atlas → Network Access, and that any special characters in your password are URL-encoded in the connection string.

  • First tool call fails, and every retry after fails identically: this indicates a failed initial DB connection getting cached — restart the MCP server process (fully quit and reopen the client) to clear it.

Known Limitations

  • No remote transport (stdio only) — not yet suitable for multi-client/hosted use.

  • No automated tests yet.

  • Query results from get_new_users / get_pending_payments are not paginated or capped — fine for demo-scale data, but should be limited before pointing this at a large production collection.

Available Tools

3 tools
get_business_summaryA

Get business summary metrics: total users, active users, paid users, pending payments, and new users in the last 7 days

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.2/5.0
Behavior3/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. It indicates a read-only operation via 'Get' and lists the returned metrics, but does not disclose data freshness, response format, or any prerequisites. Given the simplicity of the tool, this is adequate but lacks richer behavioral context.

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, clearly structured sentence. It leads with the action and resource, then lists the metrics in a scannable format, making it both concise and front-loaded with no wasted words.

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

Completeness4/5

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

Given the tool's low complexity (no parameters, no output schema), the description sufficiently covers the main purpose and included metrics. It could be slightly more explicit about the expected response structure or how the metrics are calculated, but for a simple summary getter, it is nearly complete.

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?

There are zero parameters, so the baseline is 4. The description adds value by specifying which metrics are included in the summary, which is beyond the empty input schema and helps set expectations for the return value.

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

Purpose5/5

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

The description clearly states the tool's function: 'Get business summary metrics' and lists specific metrics (total users, active users, paid users, pending payments, new users in the last 7 days). This is a specific verb+resource+scope, and it distinguishes from siblings get_new_users and get_pending_payments by being the aggregate summary tool.

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

Usage Guidelines4/5

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

The description provides clear context by enumerating the metrics included, implying that this is the comprehensive summary tool while the siblings focus on individual metrics. However, it does not explicitly state when to choose this over the siblings (e.g., 'if you need all metrics, use this; for just one metric, use the specific tool'), so it stops short of explicit exclusions.

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

get_new_usersA

Get users created within the last N days

ParametersJSON Schema
NameRequiredDescriptionDefault
daysYesNumber of days to look back

TDQS

A3.6/5.0
Behavior2/5

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

With no annotations, the description carries the full burden for behavioral disclosure. It implies a read operation via 'Get' but does not explicitly state safety (read-only), required permissions, pagination, limits, or return shape. This leaves the agent without key context for invoking the tool safely.

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 immediately states the action and scope. There is no redundant text or unnecessary detail.

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

Completeness4/5

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

For a simple tool with one parameter and no output schema, the description captures the essential purpose ('get users') and the key filter (time window). It could mention return format or pagination, but the simplicity of the operation makes the current description minimally sufficient.

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

Parameters3/5

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

Schema description coverage is 100% for the only parameter ('days' with explanation). The tool description's 'N days' aligns with the schema but adds no additional meaning beyond what is already documented, so the baseline of 3 applies.

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

Purpose5/5

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

The description uses a specific verb ('Get') with a clear resource ('users') and a defining scope ('created within the last N days'). This distinguishes it from sibling tools like get_business_summary and get_pending_payments, which focus on different resources or metrics.

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

Usage Guidelines3/5

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

The description implies when to use the tool (when needing users added within a timeframe) but provides no explicit guidance on when not to use it or how it compares to alternatives. No references to sibling tools or exclusions are present.

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

get_pending_paymentsA

Get all customers with pending payments

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A3.8/5.0
Behavior2/5

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

No annotations are provided, so the description must convey behavioral details. It only says 'Get all customers,' which is a read operation, but it does not disclose any additional traits such as data freshness, potential size limits, sorting, or if it only returns active customers. The description is minimal and leaves the agent uncertain about return format or side effects.

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 concise sentence that fully states the tool's purpose. There is no wasted wording, and the structure is clear and front-loaded.

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

Completeness4/5

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

Given that there are no parameters, no output schema, and the tool is a simple read operation, the description is mostly complete. However, it does not specify what fields are returned for each customer or any filtering criteria like 'outstanding balance > 0' beyond the 'pending payments' phrasing, leaving a small gap.

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 accepts no parameters, so the description adds no parameter details. Since there are no parameters, the baseline is 4, and the description does not need to explain parameter meaning.

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

Purpose5/5

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

The description clearly states the tool's function: it retrieves a list of customers with pending payments. The verb 'Get' combined with the specific resource ('customers with pending payments') distinguishes it from siblings like get_business_summary and get_new_users, which target different data.

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

Usage Guidelines3/5

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

The description implies usage when needing a list of customers with pending payments, but it does not explicitly mention when to avoid using it or which alternative to prefer. Sibling tools like get_new_users suggest a similar query pattern, so some ambiguity remains about when this tool is the best choice.

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. Dates show when Glama detected each change.

  1. 3 tool updatesv1.0.0
    • First observedget_business_summary
    • First observedget_new_users
    • First observedget_pending_payments

TDQS

A3.9/5.0
Disambiguation4/5

get_business_summary provides aggregate metrics, while get_new_users and get_pending_payments return detailed lists. There is conceptual overlap since new users and pending payments are part of the summary, but the granularity difference helps distinguish them.

Naming Consistency5/5

All three tools follow a consistent 'get_<noun>' pattern in snake_case, making the API naming predictable and uniform.

Tool Count5/5

With three tools, the server is tightly scoped to business analytics. This is an appropriate size for a focused read-only reporting API.

Completeness3/5

The summary tool covers five metrics, but dedicated detail tools exist only for new users and pending payments. Missing detail tools for active users, paid users, and total users create an imbalance, though the core summary is present.

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    MCP server that exposes a MongoDB healthcare jobs collection, enabling listing, searching, creating, updating, deleting jobs and getting summary counts.
    -
  • F
    license
    A
    quality
    D
    maintenance
    MCP server for the WhatsMyBudget Analytics API, providing tools to query budget periods, categories, accounts, and summaries.
    26
    -

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/kawaljain/nodejs-mcp-mongodb'

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