MongoDB
Prerequisites
- Python 3.8+
- Meshagent CLI
- Access to a MongoDB Atlas Cluster or other MongoDB server.
Required Environment Variables
- MDB_MCP_CONNECTION_STRING: The MongoDB connection string, e.g.
mongodb+srv://username:password@cluster.mongodb.net/myDatabase
Cloud Setup Steps
-
Install the Meshagent SDK and all extras:
-
Sign up and authenticate for Meshagent:
- Follow instructions at Meshagent CLI Get Started.
-
Start the MCP MongoDB Service in a Meshagent Room:
- 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.
- Replace
-
Start a chatbot agent in the Meshagent Room with access to the MongoDB toolkit:
- 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
Tool | Short Description |
---|---|
aggregate | Run an aggregation against a MongoDB collection |
collection-indexes | Describe the indexes for a collection |
collection-schema | Describe the schema for a collection |
collection-storage-size | Gets the size of the collection |
count | Gets the number of documents in a MongoDB collection |
create-collection | Creates a new collection in a database. |
create-index | Create an index for a collection |
db-stats | Returns statistics that reflect the use state of a single database |
delete-many | Removes all documents that match the filter from a MongoDB collection |
drop-collection | Removes a collection or view from the database. |
drop-database | Removes the specified database, deleting the associated data files |
explain | Returns statistics describing the execution of the winning plan chosen by the query optimizer |
find | Run a find query against a MongoDB collection |
insert-many | Insert an array of documents into a MongoDB collection |
list-collections | List all collections for a given database |
list-databases | List all databases for a MongoDB connection |
mongodb-logs | Returns the most recent logged mongod events |
rename-collection | Renames a collection in a MongoDB database |
switch-connection | Switch to a different MongoDB connection |
update-many | Updates 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 namedatabase
(string
): Database namepipeline
(array
): Array of aggregation stages
collection-indexes
Description: Describe the indexes for a collection
Parameters:
collection
(string
): Collection namedatabase
(string
): Database name
collection-schema
Description: Describe the schema for a collection
Parameters:
collection
(string
): Collection namedatabase
(string
): Database name
collection-storage-size
Description: Gets the size of the collection
Parameters:
collection
(string
): Collection namedatabase
(string
): Database name
count
Description: Gets the number of documents in a MongoDB collection
Parameters:
collection
(string
): Collection namedatabase
(string
): Database namequery
(object
, optional): Query filter
create-collection
Description: Creates a new collection in a database. Creates the database if needed.
Parameters:
collection
(string
): Collection namedatabase
(string
): Database name
create-index
Description: Create an index for a collection
Parameters:
collection
(string
): Collection namedatabase
(string
): Database namekeys
(object
): Index definitionname
(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 namedatabase
(string
): Database namefilter
(object
, optional): Deletion criteria
drop-collection
Description: Removes a collection or view from the database
Parameters:
collection
(string
): Collection namedatabase
(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 namedatabase
(string
): Database namemethod
(array
): Method/arguments to run
find
Description: Run a find query
Parameters:
collection
(string
): Collection namedatabase
(string
): Database namefilter
(object
, optional): Query filterlimit
(number
, optional): Max docs to returnprojection
(object
, optional): Projection fieldssort
(object
, optional): Sort order
insert-many
Description: Insert multiple documents
Parameters:
collection
(string
): Collection namedatabase
(string
): Database namedocuments
(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 entriestype
(string
, optional): Type of logs (global
orstartupWarnings
)
rename-collection
Description: Rename a collection
Parameters:
collection
(string
): Collection namedatabase
(string
): Database namenewName
(string
): New collection namedropTarget
(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 namedatabase
(string
): Database nameupdate
(object
): Update documentfilter
(object
, optional): Selection criteriaupsert
(boolean
, optional): Insert if not found