NestJS MongoDB

Provides a NestJS-based MCP server for MongoDB with CRUD, aggregation, and dual transport options.
  • typescript

0

GitHub Stars

typescript

Language

6 months ago

First Indexed

3 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs

You run a NestJS-based MCP server that enables AI assistants to interact with MongoDB databases through standardized MCP tools, resources, and prompts. It supports local STDIO transport for desktop integrations and HTTP/SSE for remote access, with strong type safety, structured logging, and Docker-ready development workflows.

How to use

Connect to the MCP server using your preferred MCP client (for example, Claude Desktop in STDIO mode or an HTTP/SSE client for remote access). Use the available MongoDB tools to query, insert, update, delete, count, and aggregate data across your MongoDB collections. You can also list collections and leverage prompts that help you build complex queries in natural language. When you ask Claude to perform an operation, the server translates your request into MongoDB operations handled by the dedicated use cases.

Practical workflows you can perform include querying documents with filters and projections, inserting single or multiple documents, updating many documents that match a filter, deleting documents, counting documents in a collection, and running aggregation pipelines. If you use STDIO, Claude will exchange messages over standard input/output; if you use HTTP/SSE, you’ll interact through a REST-like endpoint with server-sent events for real-time responses.

How to install

Prerequisites: ensure you have Node.js 20 or newer and MongoDB 7.0 or newer installed, plus npm or yarn for package management.

  1. Clone the repository and navigate into the project directory.

  2. Install dependencies.

  3. Create the environment file by copying the example and editing the values.

  4. Configure essential environment variables in .env.

Configuration and operation notes

The server supports two transport modes: STDIO for local use with Claude Desktop and HTTP/SSE for remote access. You configure the transport with environment variables and start the server accordingly.

Key environment variables you will set include the MongoDB connection details and the MCP transport mode.

{
  "mcpServers": {
    "nestjs_mongodb": {
      "type": "stdio",
      "command": "node",
      "args": ["dist/main.js"],
      "cwd": "/absolute/path/to/nestjs-mcp-server",
      "env": {
        "MONGODB_URI": "mongodb://localhost:27017",
        "MONGODB_DATABASE": "your_database",
        "MCP_TRANSPORT": "STDIO",
        "LOG_LEVEL": "info"
      }
    }
  }
}

Security considerations

Enable read-only mode if you want to restrict write operations by setting the appropriate environment flag. Use environment variables for sensitive configuration and ensure all inputs are validated. In STDIO mode, logs are directed to stderr to avoid interfering with JSON-RPC messaging.

API endpoints and usage modes

In HTTP/SSE mode, the MCP endpoint is available at http://localhost:3000/api/mcp. Health checks are exposed at GET /health, and the MCP interaction is handled through POST /api/mcp and SSE at GET /api/mcp.

Testing and development workflows

Run unit tests, integration tests, and end-to-end tests with the available npm scripts. Generate test coverage to verify behavior across CRUD operations and aggregations.

Available tools

mongodb-find

Query documents with filters, projection, sorting, and limits

mongodb-insert

Insert a single document into a collection

mongodb-insert-many

Insert multiple documents into a collection

mongodb-update-many

Update documents matching a filter in bulk

mongodb-delete-many

Delete documents matching a filter

mongodb-count

Count documents in a collection

mongodb-aggregate

Execute aggregation pipelines against a collection

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational