For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

MongoDB MCP Server Usage Examples

This page demonstrates how to use the MongoDB MCP Server through practical examples with natural language prompts. Each example shows the prompt you can enter in your AI client and an example response you might receive from the large language model (LLM).

You can use the examples on this page as starting points for your own interactions with the MongoDB MCP Server.

Note

The exact output you receive will vary depending on your data, AI client, and the LLM you're using. Private information such as organization IDs, project IDs, and passwords are redacted in these examples.

Before running these examples, ensure that you have the following:

The following examples demonstrate how to manage your Atlas infrastructure by using the MongoDB MCP Server.

Get an overview of your Atlas account structure and available resources.

Show my Atlas organizations and projects

Set up a new Atlas project with a cluster and all necessary access configurations in a single workflow.

Create a new Atlas project named myNewProject and create a
free cluster named myNewCluster in the new project, add
access list for my current IP, create a database user named
myNewUser with read and write access to the new cluster, and
return the connection string for the new cluster

To look up the region codes and human-readable locations that Atlas supports for a cloud provider use atlas-get-regions. This is useful for resolving a natural-language location, such as "Iowa" or "Northern Europe", to the exact region code that tools like atlas-create-cluster and atlas-upgrade-cluster expect.

What Atlas regions are available on GCP?

Use atlas-create-cluster to create a dedicated Atlas cluster with M10–M80 instance sizes. To create a free-tier cluster instead, use atlas-create-free-cluster.

The tool requires projectId, clusterName, provider, and regions.

Create a dedicated Atlas cluster named myDedicatedCluster
in project myProject on AWS in US East

Non-Default Options

To specify a non-default cluster type, instance size, or backup settings, include those options in your prompt:

Create a dedicated Atlas cluster named myShardedCluster
in project myProject on AWS in US East with cluster type
SHARDED, instance size M30, and continuous backups enabled

Multiple Regions

To distribute a cluster across multiple regions, name up to three regions in your prompt. The tool treats the regions as an ordered list: the first region has the highest priority and holds the primary node. The tool distributes electable nodes as three nodes in one region, two and one node across two regions, or two, two, and one node across three regions.

Create a dedicated Atlas cluster named myMultiRegionCluster
in project myProject on AWS across US East, Ohio, and Ireland

Encryption at Rest with a Customer-Managed Key

To encrypt a cluster with a customer-managed key, name the key provider in your prompt. The provider must already have a valid Encryption at Rest configuration in the project. The tool selects an existing configuration, it can't create or modify one. To learn how to configure a key provider, see Encryption at Rest using Customer Key Management.

If you don't name a provider, the tool uses the customer-managed key configured for the cluster's cloud provider when a valid configuration exists. Otherwise, the cluster uses the default Atlas Encryption at Rest.

Create a dedicated Atlas cluster named myEncryptedCluster
in project myProject on AWS in US East, encrypted with our
AWS customer-managed key

The atlas-upgrade-cluster tool supports the following upgrade paths:

  • Free to Flex

  • Free to M10

  • Flex to M10

The tool also scales a dedicated cluster to a different M10–M80 instance size and updates its compute autoscaling settings.

Connected to a Cluster

If you configured a connection string in your MCP settings, or you connected using the atlas-connect-cluster tool, the MCP Server infers the cluster name, project, and current tier from your connection.

Upgrade my current Atlas cluster to Flex

Not Connected to a Cluster

If you do not have an active cluster connection, provide the cluster name and project in your prompt. You can optionally specify the target tier, provider, and region.

Upgrade my Atlas cluster named myFlexCluster
in project myProject to M10 on AWS in US East

Scaling a Dedicated Cluster

To scale a dedicated cluster, specify at least one of the following options:

  • The new instance size

  • Whether to enable compute autoscaling

  • The minimum or maximum instance size for autoscaling

Scale my Atlas cluster named myDedicatedCluster
in project myProject to M30 and let it autoscale
between M20 and M50

The atlas-pause-resume-cluster tool pauses or resumes a dedicated (M10+) Atlas cluster. Free and Flex clusters cannot be paused.

The tool requires the following parameters:

  • projectId

  • clusterName

  • action. Set action to PAUSE or RESUME.

Pause a Cluster

When you pause a cluster, it becomes unavailable for connections and does not incur compute costs. If the cluster is your current active connection, the MCP Server automatically disconnects from it after the cluster is paused.

Pause cluster test-cluster-1 from project XXX

Resume a Cluster

When you resume a cluster, it does not become immediately available for connections. Use atlas-inspect-cluster to poll the cluster state until it reaches IDLE.

Resume cluster test-cluster-1 from project XXX

The following examples demonstrate how you can use the MongoDB MCP Server to explore and understand your MongoDB data.

Discover what databases are available in your cluster and get insights about their contents.

Show my Atlas databases

Dive deeper into a specific database to understand its structure and collections.

Show the collections in the Atlas sample_mflix database

Analyize your MongoDB data to identify patterns and trends.

Summarize the Atlas movies collection by thrillers

The following examples demonstrate how to use the MongoDB MCP Server to perform common database operations.

Add new data to your collections.

Add a document to the movies_copy collection

Create and customize new collections.

Create a new collection to store movie purchases data that
includes geospatial and timeseries fields

Create a backup or duplicate of an existing collection.

Make a copy of the movies collection named movies_copy

The following example demonstrates how to export query results for sharing or further processing in external tools.

Generate comprehensive reports and export them for use in other applications or for sharing with team members.

The exported results are saved to a file on the computer that runs the MCP Server. You can also access the exported data through the exported-data resource using the AI client application.

The export file is stored in the file system path specified by the exportPath configuration option. The export file is eligible for deletion after the time period specified by the exportTimeout configuration option. For additional details, see Export Data from MongoDB MCP Server.

Summarize and export the contents of the movies collection.

You can use the MCP Server with local Atlas deployments. To use the MCP Server tools with local Atlas deployments, you must install Docker. For an introduction to local Atlas deployments, see Create a Local Atlas Deployment.

The following examples show how to use the MongoDB MCP Server to interact with and create local Atlas deployments.

The following example lists local Atlas deployments.

List all local Atlas deployments.

The following example connects to a local Atlas deployment named local7356 and lists the databases.

Connect to my local Atlas deployment local7356 and list the
databases.

The following example creates a new local Atlas deployment with a database and an example collection. To run the example, you must disable read only mode.

Create a new local Atlas deployment, connect to it, create a
collection with sample pizza orders data, and then retrieve the
sample data.

The following example deletes a local Atlas deployment named local5528. To run the example, you must disable read only mode.

Delete my local Atlas deployment local5528.

After the atlas-local-delete-deployment tool deletes the local Atlas deployment, the AI client might respond that the deployment has already been deleted. This is because the atlas-local-delete-deployment tool ran successfully and the local Atlas deployment no longer exists.

The following examples demonstrate how you can use the MongoDB MCP Server to identify and resolve performance issues. The actual output for your prompts will depend on whether your cluster is experiencing performance issues, so your output might not match the examples exactly.

These examples use the atlas-get-performance-advisor tool to retrieve recommendations from the Performance Advisor.

Identify and analyze slow-performing queries to understand performance bottlenecks.

Note

When performing slow query analysis, the MongoDB MCP Server retrieves a sample of slow queries, capped at 50 queries. The sample includes up to 50 most recent slow queries that match any specified conditions in your prompt to ensure optimal performance and response times.

Query for all slow queries in the cluster:

Show me slow queries in my cluster

Query for general performance issues:

How is my cluster performance?

Query for a specific operation type, duration, or namespace:

Show me slow writes for the past 24 hours in the movies collection

Query for a specific execution time:

Show me queries longer than 5 seconds

Use the Performance Advisor to suggest indexes to create or drop to improve performance.

What indexes should I create or drop to improve performance?

Get recommendations for improving your database schema design and structure.

Suggest schema improvements for my database

The following examples demonstrate how to use the MongoDB MCP Server to work with MongoDB Vector Search. To learn more about how the MCP Server works with vector search, see Vector Search Support.

Note

To use automatic embedding generation, you must configure the MCP Server with a Voyage AI API key.

Create, drop, and list vector search indexes for your collections.

Create a vector search index on the sample_db.products collection
for the embeddings field with 1024 dimensions
using dot product similarity
Show me all vector search indexes on the sample_db.products collection
Drop the vector search index from the sample_db.products collection

When you configure a Voyage AI API key, the MCP Server automatically generates embeddings when inserting documents. You can provide raw text values, and the server generates the embeddings for fields with vector search indexes.

Insert documents into the sample_db database and products collection.
Use the voyage-3-large embedding model to generate
vector embeddings from descriptions for the `embeddings` field.
1. name: "Headphones", description: "Premium wireless noise-canceling headphones with 30-hour battery"
2. name: "Earbuds", description: "True wireless earbuds with active noise cancellation"
3. name: "Monitor", description: "24-inch 4K monitor with 1ms response time"
4. name: "Keyboard", description: "Mechanical keyboard with customizable RGB lighting"
5. name: "Mouse", description: "Wireless ergonomic mouse with programmable buttons"

When you configure a Voyage AI API key, the MCP Server automatically generates embeddings when running vector search queries. You can provide the raw text and the server automatically generates embeddings for the query.

Run a vector search query on sample_db.products on the 'embeddings' field
using the vector search index to find products that I can use to listen to music.

The following examples demonstrate how to use the MongoDB MCP Server to work with MongoDB Search. To learn more about how the MCP Server works with lexical search, see Lexical Search Support.

Create, drop, and list lexical search indexes for your collections.

Create a lexical search index on the sample_db.products collection
for the description field
Show me all lexical search indexes on the sample_db.products collection
Drop the lexical search index from the sample_db.products collection

Run lexical search queries with the aggregate tool using the $search aggregation stage.

Run a lexical search query on sample_db.products on the 'description' field
using the lexical search index to find products that mention wireless.

Use the aggregate tool with the $searchMeta aggregation stage to return metadata about a lexical search, such as a count of matching documents, instead of the matching documents themselves.

How many products have "wireless" in the description on
sample_db.products using the lexical search index

For more information about configuring and using the MongoDB MCP Server:

Learn about all available configuration options and connection methods.

Explore the complete list of tools and their capabilities.

Understand how to securely deploy and use the MCP Server.