|
| 1 | +# MongoDB MCP Server |
| 2 | + |
| 3 | +A Model Context Protocol server to connect to MongoDB databases and MongoDB Atlas Clusters. |
| 4 | + |
| 5 | +[What is an MCP Server?](https://www.anthropic.com/news/model-context-protocol) |
| 6 | + |
| 7 | +## Characteristics |
| 8 | +Attribute|Details| |
| 9 | +|-|-| |
| 10 | +**Image Source**|Official Image |
| 11 | +**Docker Image**|[mcp/mongodb](https://hub.docker.com/repository/docker/mcp/mongodb) |
| 12 | +**Author**|[mongodb-js](https://github.com/mongodb-js) |
| 13 | +**Repository**|https://github.com/mongodb-js/mongodb-mcp-server |
| 14 | +**Dockerfile**|https://github.com/mongodb-js/mongodb-mcp-server/blob/main/Dockerfile |
| 15 | +**Docker Image built by**|Docker Inc. |
| 16 | +**Docker Scout Health Score**|  |
| 17 | +**Verify Signature**|`COSIGN_REPOSITORY=mcp/signatures cosign verify mcp/mongodb --key https://raw.githubusercontent.com/docker/keyring/refs/heads/main/public/mcp/latest.pub` |
| 18 | +**Licence**|Apache License 2.0 |
| 19 | + |
| 20 | +## Available Tools |
| 21 | +Tools provided by this Server|Short Description |
| 22 | +-|- |
| 23 | +`aggregate`|Run an aggregation against a MongoDB collection| |
| 24 | +`collection-indexes`|Describe the indexes for a collection| |
| 25 | +`collection-schema`|Describe the schema for a collection| |
| 26 | +`collection-storage-size`|Gets the size of the collection| |
| 27 | +`count`|Gets the number of documents in a MongoDB collection| |
| 28 | +`create-collection`|Creates a new collection in a database.| |
| 29 | +`create-index`|Create an index for a collection| |
| 30 | +`db-stats`|Returns statistics that reflect the use state of a single database| |
| 31 | +`delete-many`|Removes all documents that match the filter from a MongoDB collection| |
| 32 | +`drop-collection`|Removes a collection or view from the database.| |
| 33 | +`drop-database`|Removes the specified database, deleting the associated data files| |
| 34 | +`explain`|Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method| |
| 35 | +`find`|Run a find query against a MongoDB collection| |
| 36 | +`insert-many`|Insert an array of documents into a MongoDB collection| |
| 37 | +`list-collections`|List all collections for a given database| |
| 38 | +`list-databases`|List all databases for a MongoDB connection| |
| 39 | +`mongodb-logs`|Returns the most recent logged mongod events| |
| 40 | +`rename-collection`|Renames a collection in a MongoDB database| |
| 41 | +`switch-connection`|Switch to a different MongoDB connection.| |
| 42 | +`update-many`|Updates all documents that match the specified filter for a collection| |
| 43 | + |
| 44 | +--- |
| 45 | +## Tools Details |
| 46 | + |
| 47 | +#### Tool: **`aggregate`** |
| 48 | +Run an aggregation against a MongoDB collection |
| 49 | +Parameters|Type|Description |
| 50 | +-|-|- |
| 51 | +`collection`|`string`|Collection name |
| 52 | +`database`|`string`|Database name |
| 53 | +`pipeline`|`array`|An array of aggregation stages to execute |
| 54 | + |
| 55 | +--- |
| 56 | +#### Tool: **`collection-indexes`** |
| 57 | +Describe the indexes for a collection |
| 58 | +Parameters|Type|Description |
| 59 | +-|-|- |
| 60 | +`collection`|`string`|Collection name |
| 61 | +`database`|`string`|Database name |
| 62 | + |
| 63 | +--- |
| 64 | +#### Tool: **`collection-schema`** |
| 65 | +Describe the schema for a collection |
| 66 | +Parameters|Type|Description |
| 67 | +-|-|- |
| 68 | +`collection`|`string`|Collection name |
| 69 | +`database`|`string`|Database name |
| 70 | + |
| 71 | +--- |
| 72 | +#### Tool: **`collection-storage-size`** |
| 73 | +Gets the size of the collection |
| 74 | +Parameters|Type|Description |
| 75 | +-|-|- |
| 76 | +`collection`|`string`|Collection name |
| 77 | +`database`|`string`|Database name |
| 78 | + |
| 79 | +--- |
| 80 | +#### Tool: **`count`** |
| 81 | +Gets the number of documents in a MongoDB collection |
| 82 | +Parameters|Type|Description |
| 83 | +-|-|- |
| 84 | +`collection`|`string`|Collection name |
| 85 | +`database`|`string`|Database name |
| 86 | +`query`|`object` *optional*|The query filter to count documents. Matches the syntax of the filter argument of db.collection.count() |
| 87 | + |
| 88 | +--- |
| 89 | +#### Tool: **`create-collection`** |
| 90 | +Creates a new collection in a database. If the database doesn't exist, it will be created automatically. |
| 91 | +Parameters|Type|Description |
| 92 | +-|-|- |
| 93 | +`collection`|`string`|Collection name |
| 94 | +`database`|`string`|Database name |
| 95 | + |
| 96 | +--- |
| 97 | +#### Tool: **`create-index`** |
| 98 | +Create an index for a collection |
| 99 | +Parameters|Type|Description |
| 100 | +-|-|- |
| 101 | +`collection`|`string`|Collection name |
| 102 | +`database`|`string`|Database name |
| 103 | +`keys`|`object`|The index definition |
| 104 | +`name`|`string` *optional*|The name of the index |
| 105 | + |
| 106 | +--- |
| 107 | +#### Tool: **`db-stats`** |
| 108 | +Returns statistics that reflect the use state of a single database |
| 109 | +Parameters|Type|Description |
| 110 | +-|-|- |
| 111 | +`database`|`string`|Database name |
| 112 | + |
| 113 | +--- |
| 114 | +#### Tool: **`delete-many`** |
| 115 | +Removes all documents that match the filter from a MongoDB collection |
| 116 | +Parameters|Type|Description |
| 117 | +-|-|- |
| 118 | +`collection`|`string`|Collection name |
| 119 | +`database`|`string`|Database name |
| 120 | +`filter`|`object` *optional*|The query filter, specifying the deletion criteria. Matches the syntax of the filter argument of db.collection.deleteMany() |
| 121 | + |
| 122 | +--- |
| 123 | +#### Tool: **`drop-collection`** |
| 124 | +Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection. |
| 125 | +Parameters|Type|Description |
| 126 | +-|-|- |
| 127 | +`collection`|`string`|Collection name |
| 128 | +`database`|`string`|Database name |
| 129 | + |
| 130 | +--- |
| 131 | +#### Tool: **`drop-database`** |
| 132 | +Removes the specified database, deleting the associated data files |
| 133 | +Parameters|Type|Description |
| 134 | +-|-|- |
| 135 | +`database`|`string`|Database name |
| 136 | + |
| 137 | +--- |
| 138 | +#### Tool: **`explain`** |
| 139 | +Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method |
| 140 | +Parameters|Type|Description |
| 141 | +-|-|- |
| 142 | +`collection`|`string`|Collection name |
| 143 | +`database`|`string`|Database name |
| 144 | +`method`|`array`|The method and its arguments to run |
| 145 | + |
| 146 | +--- |
| 147 | +#### Tool: **`find`** |
| 148 | +Run a find query against a MongoDB collection |
| 149 | +Parameters|Type|Description |
| 150 | +-|-|- |
| 151 | +`collection`|`string`|Collection name |
| 152 | +`database`|`string`|Database name |
| 153 | +`filter`|`object` *optional*|The query filter, matching the syntax of the query argument of db.collection.find() |
| 154 | +`limit`|`number` *optional*|The maximum number of documents to return |
| 155 | +`projection`|`object` *optional*|The projection, matching the syntax of the projection argument of db.collection.find() |
| 156 | +`sort`|`object` *optional*|A document, describing the sort order, matching the syntax of the sort argument of cursor.sort() |
| 157 | + |
| 158 | +--- |
| 159 | +#### Tool: **`insert-many`** |
| 160 | +Insert an array of documents into a MongoDB collection |
| 161 | +Parameters|Type|Description |
| 162 | +-|-|- |
| 163 | +`collection`|`string`|Collection name |
| 164 | +`database`|`string`|Database name |
| 165 | +`documents`|`array`|The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany() |
| 166 | + |
| 167 | +--- |
| 168 | +#### Tool: **`list-collections`** |
| 169 | +List all collections for a given database |
| 170 | +Parameters|Type|Description |
| 171 | +-|-|- |
| 172 | +`database`|`string`|Database name |
| 173 | + |
| 174 | +--- |
| 175 | +#### Tool: **`list-databases`** |
| 176 | +List all databases for a MongoDB connection |
| 177 | +#### Tool: **`mongodb-logs`** |
| 178 | +Returns the most recent logged mongod events |
| 179 | +Parameters|Type|Description |
| 180 | +-|-|- |
| 181 | +`limit`|`integer` *optional*|The maximum number of log entries to return. |
| 182 | +`type`|`string` *optional*|The type of logs to return. Global returns all recent log entries, while startupWarnings returns only warnings and errors from when the process started. |
| 183 | + |
| 184 | +--- |
| 185 | +#### Tool: **`rename-collection`** |
| 186 | +Renames a collection in a MongoDB database |
| 187 | +Parameters|Type|Description |
| 188 | +-|-|- |
| 189 | +`collection`|`string`|Collection name |
| 190 | +`database`|`string`|Database name |
| 191 | +`newName`|`string`|The new name for the collection |
| 192 | +`dropTarget`|`boolean` *optional*|If true, drops the target collection if it exists |
| 193 | + |
| 194 | +--- |
| 195 | +#### Tool: **`switch-connection`** |
| 196 | +Switch to a different MongoDB connection. If the user has configured a connection string or has previously called the connect tool, a connection is already established and there's no need to call this tool unless the user has explicitly requested to switch to a new instance. |
| 197 | +Parameters|Type|Description |
| 198 | +-|-|- |
| 199 | +`connectionString`|`string` *optional*|MongoDB connection string to switch to (in the mongodb:// or mongodb+srv:// format) |
| 200 | + |
| 201 | +--- |
| 202 | +#### Tool: **`update-many`** |
| 203 | +Updates all documents that match the specified filter for a collection |
| 204 | +Parameters|Type|Description |
| 205 | +-|-|- |
| 206 | +`collection`|`string`|Collection name |
| 207 | +`database`|`string`|Database name |
| 208 | +`update`|`object`|An update document describing the modifications to apply using update operator expressions |
| 209 | +`filter`|`object` *optional*|The selection criteria for the update, matching the syntax of the filter argument of db.collection.updateOne() |
| 210 | +`upsert`|`boolean` *optional*|Controls whether to insert a new document if no documents match the filter |
| 211 | + |
| 212 | +--- |
| 213 | +## Use this MCP Server |
| 214 | + |
| 215 | +```json |
| 216 | +{ |
| 217 | + "mcpServers": { |
| 218 | + "mongodb": { |
| 219 | + "command": "docker", |
| 220 | + "args": [ |
| 221 | + "run", |
| 222 | + "-i", |
| 223 | + "--rm", |
| 224 | + "-e", |
| 225 | + "MDB_MCP_CONNECTION_STRING", |
| 226 | + "mcp/mongodb" |
| 227 | + ], |
| 228 | + "env": { |
| 229 | + "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase" |
| 230 | + } |
| 231 | + } |
| 232 | + } |
| 233 | +} |
| 234 | +``` |
| 235 | + |
| 236 | +[Why is it safer to run MCP Servers with Docker?](https://www.docker.com/blog/the-model-context-protocol-simplifying-building-ai-apps-with-anthropic-claude-desktop-and-docker/) |
0 commit comments