/ Annuaire / Playground / MongoDB
● Officiel mongodb-js 🔑 Nécessite votre clé

MongoDB

par mongodb-js · mongodb-js/mongodb-mcp-server

Let Claude query, aggregate, and administer MongoDB Atlas or self-hosted clusters — with read-only defaults you can relax per-tool.

MongoDB's official MCP covers both the driver (CRUD + aggregation on any cluster) and the Atlas control plane (list projects, clusters, users). By default it runs in read-only mode; enable writes explicitly per command family when you need them.

Pourquoi l'utiliser

Fonctionnalités clés

Démo en direct

Aperçu en pratique

mongodb.replay ▶ prêt
0/0

Installer

Choisissez votre client

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server"
      ]
    }
  }
}

Ouvrez Claude Desktop → Settings → Developer → Edit Config. Redémarrez après avoir enregistré.

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server"
      ]
    }
  }
}

Cursor utilise le même schéma mcpServers que Claude Desktop. La config projet l'emporte sur la globale.

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server"
      ]
    }
  }
}

Cliquez sur l'icône MCP Servers dans la barre latérale Cline, puis "Edit Configuration".

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server"
      ]
    }
  }
}

Même format que Claude Desktop. Redémarrez Windsurf pour appliquer.

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "mongodb",
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server"
      ]
    }
  ]
}

Continue utilise un tableau d'objets serveur plutôt qu'une map.

~/.config/zed/settings.json
{
  "context_servers": {
    "mongodb": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "mongodb-mcp-server"
        ]
      }
    }
  }
}

Ajoutez dans context_servers. Zed recharge à chaud à la sauvegarde.

claude mcp add mongodb -- npx -y mongodb-mcp-server

Une seule ligne. Vérifiez avec claude mcp list. Supprimez avec claude mcp remove.

Cas d'usage

Usages concrets : MongoDB

Answer business questions with Mongo aggregation pipelines

👤 PMs and analysts on a Mongo-backed product ⏱ ~15 min beginner

Quand l'utiliser : You need counts, funnels, or top-N lists and don't want to learn $group/$lookup syntax.

Prérequis
  • Read-only connection string — Atlas: create a DB user with readAnyDatabase. Self-hosted: user with read role on relevant DBs.
Déroulement
  1. Discover collections
    List databases, then for app_prod list all collections and their approximate document counts.✓ Copié
    → Collection catalog
  2. Sample and infer schema
    Sample 20 docs from users and orders. Describe the fields and types you see.✓ Copié
    → Per-collection schema description
  3. Run the actual aggregation
    How many orders were placed per country in the last 30 days? Sort desc and limit 20.✓ Copié
    → Results table with the pipeline used

Résultat : Business answers with the exact pipeline preserved for re-running.

Pièges
  • Aggregations without indexes can scan huge collections — Always check .explain() first and make sure a supporting index exists; otherwise add $match narrowly on an indexed field at the top of the pipeline
Combiner avec : notion

Infer and document a messy collection's actual schema

👤 New engineer onboarding to an undocumented Mongo ⏱ ~25 min intermediate

Quand l'utiliser : The collection was 'schemaless' for 3 years and nobody knows which fields actually exist.

Déroulement
  1. Sample broadly
    Sample 500 docs from events. For each top-level field, report presence %, type(s), and a sample value.✓ Copié
    → Field-by-field presence/type matrix
  2. Find schema drift
    Which fields have multiple types across docs? Group by (field, type) and count.✓ Copié
    → List of polymorphic fields
  3. Produce a TypeScript type or JSON schema
    Generate a TypeScript interface for the 'stable' fields (≥95% presence, single type). Mark the rest as optional or unknown.✓ Copié
    → Usable type definition

Résultat : A documented schema with known quirks — the basis for migrations or a validator.

Pièges
  • 500 docs may miss rare but important variants — Sample by time bucket (one per month) to catch legacy shapes
Combiner avec : filesystem

Audit your Atlas projects for security and cost

👤 DevOps/platform teams on Atlas ⏱ ~20 min intermediate

Quand l'utiliser : Quarterly: check which clusters are oversized, which have wide IP allowlists, who has access.

Prérequis
  • Atlas API public+private key — cloud.mongodb.com → Organization Access → API keys; project-scoped
Déroulement
  1. List projects + clusters
    List every project and within each, every cluster with its tier, region, and backup status.✓ Copié
    → Full inventory
  2. Flag risky access
    For each project, dump the IP access list. Flag any entry of 0.0.0.0/0 with the project name.✓ Copié
    → Risky-access report
  3. Suggest rightsizing
    Any cluster on M30+ with fewer than 10GB used? Recommend downgrades.✓ Copié
    → Cost-savings list

Résultat : A short remediation list for your security + finance folks.

Pièges
  • API key scope too narrow to see every project — Use an Organization-level key in read-only mode rather than a project-level one
Combiner avec : notion

Propose and execute a one-off data cleanup safely

👤 Backend engineer fixing a data bug ⏱ ~30 min advanced

Quand l'utiliser : A bug caused bad writes; you need to fix ~10k docs but must not nuke the wrong ones.

Prérequis
  • Writable user (scoped to the target DB only) — Atlas: role with readWrite on that one DB, nothing else
  • --read-only OFF explicitly for this session — Start the MCP without --read-only
Déroulement
  1. Scope the fix with a count
    Count docs in users where status='active' AND last_login IS NULL AND created_at < 2024-01-01. Don't modify anything.✓ Copié
    → Expected-affected count, e.g. 9,873
  2. Dry-run the update
    Show the updateMany pipeline you would run (filter + $set), and show 5 sample docs that would be changed. Do NOT execute.✓ Copié
    → Filter + set preview
  3. Execute with a limit and verify
    Run the update. Then re-run the original count — it should be 0. Report matchedCount and modifiedCount.✓ Copié
    → Counts match expectation; verify query returns 0

Résultat : A clean, auditable fix with counts before and after.

Pièges
  • updateMany with a bad filter nukes the whole collection — Always run the filter as countDocuments first; if the count is surprising, stop and investigate
  • No backup of the affected slice — Copy the matching docs to a <collection>_backup_<date> collection before updating
Combiner avec : filesystem

Suggest missing indexes from slow-query patterns

👤 Backend engineers hunting perf issues ⏱ ~25 min advanced

Quand l'utiliser : Your app is slow on Mongo queries; you want a targeted index plan, not a shotgun.

Déroulement
  1. Check existing indexes
    For orders and users, list every index with its keys and size on disk.✓ Copié
    → Index catalog
  2. Profile a specific query
    Run .explain('executionStats') on this query [paste]. Report totalDocsExamined vs nReturned and the winning plan stage.✓ Copié
    → Explain output
  3. Propose the smallest new index
    Given that plan, propose exactly one index that would convert this to IXSCAN. Justify field order.✓ Copié
    → Concrete createIndex command with rationale

Résultat : A single, justifiable index recommendation per slow query — not a wall of them.

Pièges
  • Over-indexing kills write throughput and balloons storage — Only add an index that serves >1 high-traffic query; compound indexes should reflect ESR (Equality, Sort, Range) order

Combinaisons

Associez-le à d'autres MCPs pour un effet X10

mongodb + notion

Aggregate, then post a shareable report

Compute MAU per plan tier for the last 6 months and create a Notion page in 'Growth / Monthly' with the results as a table.✓ Copié
mongodb + filesystem

Backup a collection slice as JSONL before a cleanup

Find all docs in users matching <filter>, save to /backups/users-cleanup-<date>.jsonl, then delete them.✓ Copié
mongodb + postgres

Cross-DB reconciliation when migrating off Mongo

For every user_id in Mongo users, check whether a corresponding row exists in Postgres users. Report mismatches.✓ Copié

Outils

Ce que ce MCP expose

OutilEntréesQuand appelerCoût
list_databases Start of any exploration session free
list_collections database: str Inventory a database free
find database, collection, filter?, projection?, sort?, limit? Read documents — the main read workhorse free
aggregate database, collection, pipeline: stage[] Grouping, joining, analytics free
count database, collection, filter? Always before destructive writes — confirm scope free
insert_one / insert_many database, collection, document(s) Requires --read-only off writes
update_one / update_many database, collection, filter, update Always preview filter with count first writes
delete_one / delete_many database, collection, filter Dangerous — require explicit user confirmation writes
list_indexes database, collection Perf analysis before suggesting new indexes free
atlas_list_projects / atlas_list_clusters Atlas control-plane audits free

Coût et limites

Coût d'exécution

Quota d'API
Driver: bounded by cluster connection limit. Atlas API: 100 req/min per key.
Tokens par appel
Find/aggregate: scales with result size; use projections and limits.
Monétaire
Free against your existing cluster. Atlas has a free M0 tier for testing.
Astuce
Always project only the fields you need; unbounded finds return large docs that chew context and egress.

Sécurité

Permissions, secrets, portée

Portées minimales : readAnyDatabase (read-only) or read on specific DBs
Stockage des identifiants : MDB_MCP_CONNECTION_STRING for driver; MDB_MCP_API_CLIENT_ID + MDB_MCP_API_CLIENT_SECRET for Atlas
Sortie de données : Driver connects to your cluster; Atlas API to cloud.mongodb.com only
Ne jamais accorder : dbAdminAnyDatabase userAdminAnyDatabase root

Dépannage

Erreurs courantes et correctifs

MongoServerError: Authentication failed

Connection string user/password wrong or the user lacks auth DB. Add ?authSource=admin for Atlas.

Vérifier : mongosh '$MDB_MCP_CONNECTION_STRING' --eval 'db.runCommand({ping:1})'
MongoNetworkError: ETIMEDOUT

IP not in Atlas allowlist. Add your current IP in Atlas → Network Access.

Vérifier : curl ifconfig.me then compare
not authorized on admin to execute command listDatabases

Role too narrow. Grant clusterMonitor or scope tools to a specific DB via listCollections instead.

Write rejected / running in read-only mode

Restart the MCP without --read-only; only do this for the specific fix session.

Alternatives

MongoDB vs autres

AlternativeQuand l'utiliserCompromis
Postgres MCPYou're on Postgres, or considering migrating from MongoRelational — document-style flexibility gone
DBHubYou need one MCP for Mongo + several SQL DBsShallower Mongo feature coverage than the official server

Plus

Ressources

📖 Lire le README officiel sur GitHub

🐙 Voir les issues ouvertes

🔍 Parcourir les 400+ serveurs MCP et Skills