Self-hostedData

MongoDB Agent

**Setup note:** MongoDB does not yet offer a hosted MCP endpoint, so this template requires running the official `mongodb-mcp-server` locally (one `npx` command — see setup steps below) before connecting from Agent Studio. Once running, you can talk to MongoDB the way you talk to a teammate. The server exposes your collections, aggregation framework, indexes and Atlas cluster controls as MCP tools — this template wraps them with a sensible system prompt for analytics, debugging and schema work. Works against any MongoDB connection string (local, Atlas, self-hosted) or Atlas service-account credentials for cluster management.

Default model: Claude Sonnet 4.50 servers

Default model

Claude Sonnet 4.5

MCP servers

Bring your own server URL

Auth

No token required

What you can do

A few things this template does well out of the box.

  • Ask "how many active users signed up last week?" — get a `find()` or aggregation pipeline answer instantly
  • Inspect a collection schema and find documents with missing or inconsistent fields
  • Audit indexes — find unused indexes, missing indexes for slow queries, and duplicate definitions
  • Run aggregation pipelines for cohort analysis, funnel reports, or rolling metrics — without writing the pipeline by hand
  • Manage Atlas clusters: list databases, check replica-set status, surface slow queries from the profiler

How it works

Three steps to go from template to a live chat.

1

Click "Use this template"

Agent Studio opens with the MCP server, model and system prompt pre-filled.

2

Add your MCP server URL

Point the agent to your own MCP endpoint (HTTP or SSE).

3

Start chatting

Ask a question, watch live tool calls and switch models at any time to compare answers.

Getting your access token

A quick walkthrough for the credential this template needs.

  1. 1Install the official server: `npx -y mongodb-mcp-server@latest --transport http --connectionString "mongodb+srv://USER:PASS@your-cluster/your-db" --readOnly` (drop `--readOnly` once you trust write operations).
  2. 2For Atlas cluster-management tools, swap the connection-string flags for `--apiClientId` and `--apiClientSecret` from your **Atlas → Service Accounts** page.
  3. 3The server listens on **http://127.0.0.1:3000** by default — paste `http://localhost:3000/mcp` into Agent Studio's **MCP server URL** field.
  4. 4Leave the **Access token** field blank — auth happens at server start via the connection string. (Tip: run the server in a tmux/screen session so the connection survives terminal restarts.)
  5. 5Send a first message like *"List all databases on this cluster"* to confirm the connection.

Try these prompts

Copy one into the studio to see the agent in action.

  • List all collections in the `production` database with their document counts.

  • Show me the schema for the `orders` collection — sample 100 docs and infer field types.

  • Find users who signed up in the last 7 days and have not logged in since. Group by signup source.

  • Write an aggregation pipeline that returns daily order revenue for the last 30 days, broken down by product category.

  • Which indexes on the `events` collection have not been used in the last 24 hours?

System prompt

The default instructions the model starts with. Edit it any time inside Agent Studio.

You are a MongoDB database assistant connected to a MongoDB cluster via the official mongodb-mcp-server.

Use the available tools to:
- Inspect databases, collections, schemas and indexes
- Run find queries and aggregation pipelines to answer analytical questions
- Profile slow queries and recommend index improvements
- Manage Atlas clusters when service-account credentials are provided (list clusters, check status, surface metrics)

Best practices:
- Always use a sensible `limit` (default 50) on `find` queries to avoid returning huge result sets
- Prefer aggregation pipelines over multiple round-trips for analytics questions
- When suggesting indexes, explain the cardinality and query pattern that motivates the choice
- Never run destructive operations (`drop`, `deleteMany`, mass updates) without explicit confirmation
- For schema inference, sample at least 100 documents and call out fields that vary in type or are sometimes missing

When you write a query or pipeline, show it in a code block before running it — users learn from seeing the MQL.

Ready to try the MongoDB Agent?

Open Agent Studio with this template pre-loaded. Add your token, pick any model, and start chatting.

Use this template

Related templates