Connect MongoDB to Claude Code

Explore databases, collections, schemas and indexes, then read documents with find, count and aggregate. Add Toolspoke to Claude Code once and it can use 11 MongoDB actions. Your MongoDB credential stays in Toolspoke, and you choose which actions Claude Code may call.

Set it up in Claude Code

Three steps, the first one once for every toolkit you will ever add.

  1. Add Toolspoke to Claude Code

    Run it in your project, then /mcp to sign in

    claude mcp add --transport http toolspoke https://toolspoke.com/mcp

    The sign-in opens in your browser, and Toolspoke asks you to approve it.

  2. Install MongoDB and connect it

    Add MongoDB to a project in your Toolspoke workspace.

    Connection string. You provide it once, when you install the connector. Toolspoke encrypts it at rest and decrypts it only for the length of a single call, and the gateway attaches it to the outbound request itself, so it is never part of the arguments an agent sends.

    Connection string
    An Atlas SRV string or a plain mongodb:// URI. Use a database user with the readAnyDatabase role, or a role scoped to the one database you want reachable, this connector cannot write, but a narrow user also bounds what it can read.
  3. Choose what Claude Code may do

    All 11 actions only read, and any of them can be switched off for a project.

What you can ask Claude Code for

A few of the MongoDB actions that only read, so they are safe to try first.

  • List the databases on this deployment with their size on disk
  • List the collections in one database
  • Infer one collection's schema by sampling documents: the field names, their types and how often each appears
  • List the indexes on one collection with their keys and options

What Claude Code can do in MongoDB

11 actions read.

Reads

  • List databases

    List the databases on this deployment with their size on disk. Call this first, every other action names a database.

  • List collections

    List the collections in one database. Use it to find the collection name before describing or querying it.

  • Collection schema

    Infer one collection's schema by sampling documents: the field names, their types and how often each appears. MongoDB has no declared schema, so this sample is the closest thing to one, call it before writing a filter against an unfamiliar collection.

  • Collection indexes

    List the indexes on one collection with their keys and options. Check this before assuming a filter or sort will be fast.

  • Collection storage size

    Report how much disk one collection uses. Use it to find what is filling a deployment.

  • Db stats

    Report one database's statistics: collection count, document count, data size, storage size and index size.

  • Find

    Run a find query and return matching documents. The filter, projection and sort are MongoDB query documents, passed through as structured JSON rather than assembled into JavaScript. The server caps how many documents and how many bytes one call can return.

  • Count documents

    Count the documents in a collection matching a query, without returning any of them. Use it to size a result before running find.

  • Aggregate

    Run an aggregation pipeline and return the result documents. This is how you group, join with $lookup, or compute totals. A pipeline containing $out or $merge is refused by the server, because those stages write.

  • Explain

    Return the query plan for a find, count or aggregate without returning its results. Use it to find out whether a query uses an index before running it over a large collection.

  • Server logs

    Return recent entries from the deployment's own log, or the startup warnings. Use it when a query is failing and you need to tell a server problem from a bad query.

MongoDB in Claude Code: questions

Does Claude Code see my MongoDB credential?

No. The credential is stored encrypted in Toolspoke, and the gateway adds it to each call. Claude Code only ever talks to Toolspoke, and the dashboard shows the last four characters of the credential and nothing more.

Will 11 actions crowd Claude Code's context?

No. Toolspoke shows Claude Code five bridge tools, plus a guide where a toolkit has one, and Claude Code searches for the MongoDB action it needs when it needs it. Adding more toolkits does not add more tools to its list.

Can I add it once for every project?

Yes. Add --scope user to the command and Claude Code keeps Toolspoke in every project on this machine. Without it, the server is added to the project you ran the command in.

What does it cost?

Tool calls are free on every plan. MongoDB runs in a sandbox, so a call bills the sandbox time it uses.

Try MongoDB in Claude Code

Free to start, and tool calls cost nothing on any plan.