MCP server for MongoDB: connect an AI agent to MongoDB and Atlas Connect Claude, Codex or any MCP client to MongoDB or Atlas with DeepORG. The agent writes one query language for every database; the engine translates it into MongoDB aggregation pipelines, joins collections with $lookup, and enforces access rules. Declared relationships, embedded documents, cursors and subscriptions. guides guides guides/mongodb-mcp-server guides/mongodb-mcp-server.md

GuidesMongoDB

An AI agent for MongoDB that writes queries, not pipelines.

On MongoDB the agent writes the same queries it writes for Postgres. The engine turns each one into an aggregation pipeline: $match for filters, $lookup for relationships, $project for the fields asked for. One query language covers your documents and your SQL databases.

The short version

What you get on MongoDB.

  • Pipelines written by the engine. Filters, ordering, limits, relationships and embedded arrays compile into one aggregation pipeline. The model never builds a pipeline by hand.
  • Joins across collections. A nested selection becomes a $lookup with its own pipeline. An array of ids joins with $in.
  • One language across databases. A question that spans MongoDB and Postgres is written once; the engine runs each part on its own database.
  • Rules from the caller. Row filters from the signed-in person’s role are added to the $match stage.

Connect

Connection, database and relationships.

Shell
curl -fsSL https://deeporg.io/install.sh | bash
YAML
# config/dev.yml
sources:
  - name: docs
    kind: database
    type: mongodb
    default: true
    # mongodb+srv://user:pass@cluster.example.net
    connection_string: ${MONGODB_URI}
    dbname: app                         # required: the database to read
    read_only: true   # start read-only

Name the database in dbname; the one in the URI is not used. MongoDB has no foreign keys, so tell the engine how collections relate:

YAML
tables:
  - name: orders
    columns:
      - name: customer_id
        foreign_key: customers.id

The agent then follows orders → customer as it would on any SQL database. Fields are addressed as id; the engine maps them to _id.

Shell
deeporg serve

Your AI client

Add it to Claude Code or Codex.

Shell
claude mcp add deeporg -- deeporg mcp --path /absolute/path/to/config
codex mcp add deeporg -- deeporg mcp --path /absolute/path/to/config

Your client’s model does the reasoning. With a server already running, deeporg mcp add claude http://localhost:8080 registers it over HTTP.

What runs

A nested query becomes $lookup.

GraphQL
query {
  orders(where: { status: { eq: "open" } }, order_by: { id: desc }, limit: 10) {
    id
    total
    customer { id name }
  }
}

The engine sends MongoDB one pipeline: a $match on status plus the role’s filter, a $sort and $limit, and a $lookup into customers that projects only id and name. Embedded arrays queried as their own table use $unwind and $group so the parent document keeps its shape.

Limits

Where MongoDB differs.

  • Some SQL features do not carry over. Counts, sums and averages run as a $group stage, but analytics directives (window-style rankings) and database functions are SQL-only. Check before you rely on an aggregate-heavy question being portable.
  • Relationships are declared. Nothing is inferred from field names; a missing declaration means a missing join.
  • No schema management. Collections are discovered from your data; the engine does not create or migrate them.
  • Tested version. The test suite runs against MongoDB 7.

Go deeper

Related pages.