Prerequisites

Required Environment Variables

  • MDB_MCP_CONNECTION_STRING: The MongoDB connection string, e.g. mongodb+srv://username:password@cluster.mongodb.net/myDatabase

Cloud Setup Steps

  1. Install the Meshagent SDK and all extras:

    pip install "meshagent[all]"
    
  2. Sign up and authenticate for Meshagent:

  3. Start the MCP MongoDB Service in a Meshagent Room:

    meshagent service test \
      --room=test \
      --role=agent \
      --image=meshagent/mcp-mongodb:latest \
      --env MESHAGENT_PORT=8001 \
      --env MDB_MCP_CONNECTION_STRING=<your-mongodb-connection-string> \
      --port="num=8001 path=/webhook liveness=/ type=meshagent.callable" \
      --name=mcp-mongodb-service
    
    • Replace <your-mongodb-connection-string> with your actual MongoDB connection string.
    • This command starts a Meshagent Room with the MCP server available to the room. Rooms will close if they become inactive.
  4. Start a chatbot agent in the Meshagent Room with access to the MongoDB toolkit:

    meshagent chatbot join \
      --room=test \
      --agent-name=sample \
      --name=sample \
      --toolkit=mcp-mongodb
    
    • This starts a chatbot in your Meshagent Room. The agent can now use the MongoDB toolkit.
    • You can add multiple toolkits in the same room with the same agent.
    • After running, the CLI output will include a URL to access the agent and tools via the web.

Tools Available

Tool Summary

ToolShort Description
aggregateRun an aggregation against a MongoDB collection
collection-indexesDescribe the indexes for a collection
collection-schemaDescribe the schema for a collection
collection-storage-sizeGets the size of the collection
countGets the number of documents in a MongoDB collection
create-collectionCreates a new collection in a database.
create-indexCreate an index for a collection
db-statsReturns statistics that reflect the use state of a single database
delete-manyRemoves all documents that match the filter from a MongoDB collection
drop-collectionRemoves a collection or view from the database.
drop-databaseRemoves the specified database, deleting the associated data files
explainReturns statistics describing the execution of the winning plan chosen by the query optimizer
findRun a find query against a MongoDB collection
insert-manyInsert an array of documents into a MongoDB collection
list-collectionsList all collections for a given database
list-databasesList all databases for a MongoDB connection
mongodb-logsReturns the most recent logged mongod events
rename-collectionRenames a collection in a MongoDB database
switch-connectionSwitch to a different MongoDB connection
update-manyUpdates all documents that match the specified filter for a collection

Tools Details

aggregate

Description: Run an aggregation against a MongoDB collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • pipeline (array): Array of aggregation stages

collection-indexes

Description: Describe the indexes for a collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name

collection-schema

Description: Describe the schema for a collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name

collection-storage-size

Description: Gets the size of the collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name

count

Description: Gets the number of documents in a MongoDB collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • query (object, optional): Query filter

create-collection

Description: Creates a new collection in a database. Creates the database if needed.
Parameters:

  • collection (string): Collection name
  • database (string): Database name

create-index

Description: Create an index for a collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • keys (object): Index definition
  • name (string, optional): Name of the index

db-stats

Description: Returns statistics that reflect the use state of a single database
Parameters:

  • database (string): Database name

delete-many

Description: Removes all documents matching a filter
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • filter (object, optional): Deletion criteria

drop-collection

Description: Removes a collection or view from the database
Parameters:

  • collection (string): Collection name
  • database (string): Database name

drop-database

Description: Removes the specified database and its data files
Parameters:

  • database (string): Database name

explain

Description: Returns stats about the winning plan for a query
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • method (array): Method/arguments to run

find

Description: Run a find query
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • filter (object, optional): Query filter
  • limit (number, optional): Max docs to return
  • projection (object, optional): Projection fields
  • sort (object, optional): Sort order

insert-many

Description: Insert multiple documents
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • documents (array): Array of documents

list-collections

Description: List all collections in a database
Parameters:

  • database (string): Database name

list-databases

Description: List all databases

mongodb-logs

Description: Returns recent MongoDB logs
Parameters:

  • limit (integer, optional): Max log entries
  • type (string, optional): Type of logs (global or startupWarnings)

rename-collection

Description: Rename a collection
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • newName (string): New collection name
  • dropTarget (boolean, optional): Drop target if exists

switch-connection

Description: Switch MongoDB connections
Parameters:

  • connectionString (string, optional): MongoDB connection string

update-many

Description: Update all documents matching filter
Parameters:

  • collection (string): Collection name
  • database (string): Database name
  • update (object): Update document
  • filter (object, optional): Selection criteria
  • upsert (boolean, optional): Insert if not found