Docs Menu
Docs Home
/ /

MongoDB MCP 서버 시작하기

이 가이드 에서는 AI 클라이언트 에서 MongoDB MCP 서버를 구성하고 사용하여 시작하는 방법을 학습 .

MongoDB MCP 서버 사용하려면 다음이 필요합니다.

  • Atlas cluster 또는 자체 호스팅 MongoDB deployment.

    자세한 학습 은 클러스터 만들기 또는 MongoDB 설치를 참조하세요.

  • 지원되는 모든 MCP 클라이언트.

  • 다음 버전 중 하나를 사용하여노드.js가 설치되었습니다.

    • 버전 20.19.0 이상.

    • 버전 22을 사용하는 경우 버전 22.12.0 이상을 사용해야 합니다.

    • 그렇지 않으면 버전 23 이상을 사용하세요.

    참고

    또는 Node.js를 설치할 필요가 없는 Docker 컨테이너 에서 서버 실행 수 있습니다. 자세한학습 은 Docker 사용하기를 참조하세요.

Claude Code, Codex, Cursor 또는 Gemini를 사용하는 경우, AI 클라이언트 용 공식 MongoDB 플러그인 또는 확장의 일부로 MongoDB MCP 서버를 설치할 수 있습니다. 이러한 번들은 MongoDB MCP 서버와 일반적인 MongoDB 작업을 위한 사전 구축된 에이전트 기술을 포함합니다. 자세한 내용은 MongoDB Agent 스킬 문서를 참조하세요.

고객
설치 옵션
포함된 번들

클로드 코드

Atronic Plugin Marketplace에서 공식 MongoDB Claude Plugin을 설치합니다. 자세한 내용은 Claude와 함께하는 MongoDB 참조하세요.

MongoDB MCP 서버와 사전 구축된 에이전트 기술이 포함되어 있습니다.

Codex

Codex 플러그인 마켓플레이스에서 공식 MongoDB Codex 플러그인을 설치합니다. 자세한 내용은 Codex를 사용하는 MongoDB 참조하세요.

MongoDB MCP 서버 및 사전 구축된 에이전트 기술이 포함됩니다.

커서

커서 플러그인 마켓플레이스에서 공식 MongoDB 커서 플러그인을 설치합니다. 자세한 내용은 MongoDB with 커서 참조하세요.

MongoDB MCP 서버 및 사전 구축된 에이전트 기술이 포함됩니다.

Gemini

Gemini 확장 마켓플레이스에서 공식 MongoDB Gemini 확장을 설치합니다. 자세한 내용은 Gemini를 사용하는 MongoDB 참조하세요.

MongoDB MCP 서버 및 사전 구축된 에이전트 기술이 포함됩니다.

이러한 번들 중 하나를 설치한 후 다음 섹션으로 이동하여 MongoDB 배포서버 에 맞게 MongoDB MCP 서버를 구성합니다.

다음과 같은 MongoDB 클러스터 정보도 필요합니다.

  • 연결 문자열. 자세히 학습하려면 연결 문자열 찾기를 참조하세요.

  • 서비스 계정으로 Atlas 사용하는 경우 Atlas 서비스 계정 클라이언트 ID 와 클라이언트 암호가 필요합니다. Atlas 전제 조건을 확인하려면 Atlas 전제 조건을 참조하세요.

MongoDB MCP 서버 JSON 구성 파일 서버 에 MongoDB 에 연결하는 방법과 해당 데이터를 MCP 클라이언트와 주식 방법을 알려줍니다.

초기 JSON 파일 만들려면 MCP 서버 설정 유틸리티를 사용합니다. 유틸리티는 구성 프로세스 안내합니다. 다음 단계를 따르세요.

1

명령줄 에서 실행.

npx mongodb-mcp-server@latest setup
2

유틸리티에 표시되는 지원되는 클라이언트 목록에서 AI 클라이언트 선택합니다. 예시 를 들어 VS Code을 선택합니다.

예시 클라이언트는 다음과 같습니다.

  • 커서

  • VS Code

  • Claude 데스크탑

  • 클로드 코드

  • 코드 열기

  • 윈드서핑

목록에 없는 클라이언트 사용하는 경우 JSON 파일 수동으로 설정하다 해야 합니다. 자세한 내용은 MongoDB MCP 서버 수동 파일 구성을 참조하세요.

3

읽기 전용 모드 사용하여 읽기 작업만 수행하도록 MCP 서버를 제한할 수 있습니다. 읽기 전용 모드 활성화 하려면 Y을 입력합니다.

보안을 위해 쓰기 (write) 작업을 수행해야 하는 경우가 아니라면 항상 읽기 전용 모드 활성화 . 쓰기 (write) 작업은 나중에 활성화 할 수 있습니다. 자세한 내용은 MCP 서버 읽기 전용 모드를 참조하세요.

4

MongoDB cluster 에 대한 연결 문자열 입력합니다.

예를 들어 mongodb+srv://atlasuser:D1fficultP%40ssw0rd@mycluster.abcd1.mongodb.net/myDatabase?retryWrites=true&w=majority입니다.

자세히 학습 연결 문자열 찾기를 참조하세요.

5

서비스 계정으로 Atlas 클러스터 사용하는 경우 Atlas 서비스 계정 클라이언트 식별자를 입력합니다.

자세한 내용은 Atlas 서비스 계정을 참조하세요.

Atlas 서비스 계정 클라이언트 식별자 형식 예시: mdb_sa_id_<objectId>.

6

서비스 계정으로 Atlas 클러스터 사용하는 경우 Atlas 서비스 계정 클라이언트 암호를 입력합니다.

Atlas 서비스 계정 클라이언트 비밀 형식의 예시: mdb_sa_sk_<random-string>.

7

다른 경로를 사용하려면 설정 파일 저장할 경로를 입력합니다.

예를 들어 /Users/user.name/Library/Application Support/Code/User/mcp.json입니다.

유틸리티는 설정 파일 생성합니다. AI 클라이언트 에서 설정 파일 사용하는 방법에 대한 지침을 읽어보세요. 이 유틸리티는 설정 파일 의 위치 도 제공합니다.

파일 구성, 추가 설정 추가 또는 파일 수동 구성에 대한 자세한 내용은 MongoDB MCP 서버 수동 파일 구성을 참조하세요.

이전 섹션에서 생성하거나 업데이트한 JSON 설정 파일 사용하도록 AI 클라이언트 를 다시 시작합니다.

MongoDB MCP 서버를 구성한 후에는 AI 클라이언트 에서 MongoDB 클러스터 액세스 할 수 있습니다.

1

AI 클라이언트 에서 MongoDB MCP 서버 실행 중인지 확인하고 가능한 경우 MCP 도구 목록에 MongoDB MCP 도구가 포함되어 있는지 확인합니다.

2

AI 클라이언트 에서 프롬프트를 실행하여 MongoDB MCP 서버 도구를 테스트합니다. 정확한 응답은 MongoDB deployment 의 데이터와 사용 중인 AI 클라이언트 및 모델에 따라 달라집니다. 다음 샘플 프롬프트는 MCP 서버 MongoDB 배포서버 에 대한 읽기 및 쓰기 (write) 액세스 모두 있다고 가정합니다.

  1. 먼저 다음 프롬프트를 실행 하여 작업할 새 데이터베이스 와 컬렉션 만듭니다.

    Create a new MongoDB collection named "products" and insert
    some sample data into the collection with the following fields:
    - name (string)
    - price (number)
    - category (string)
    - quantity (number)
    - inStock (boolean)
    I'll help you insert sample data into a MongoDB collection named "products" with the specified fields. Let me set this up for you.
    Ran `list-databases` - MongoDB (MCP Server)
    I'll create a sample database called "sample_store" and insert some product data into a "products" collection. Let's create the collection first:
    Ran `create-collection` - MongoDB (MCP Server)
    Now I'll insert sample product data into the "products" collection with all the required fields:
    Ran `insert-many` - MongoDB (MCP Server)
    Let's verify the data was inserted properly by querying the collection:
    Ran `find` - MongoDB (MCP Server)
    The sample data has been successfully inserted into the "products" collection. Here are some details of the inserted documents:
    Laptop:
    Price: $1,299.99
    Category: Electronics
    Quantity: 15
    InStock: true
    Smartphone:
    Price: $799.99
    Category: Electronics
    Quantity: 25
    InStock: true
    Headphones:
    Price: $149.99
    Category: Audio
    Quantity: 40
    InStock: true
    ...
  2. 이제 샘플 데이터가 포함된 MongoDB 컬렉션 있으므로 프롬프트를 실행 MCP 도구를 사용하여 컬렉션과 상호 작용 .

AI 클라이언트 에서 다음 프롬프트를 실행하여 언어 로 데이터를 탐색하고 쿼리 .

Explain the schema of the "products" collection and provide a summary
of the data.
I'll help you explain the schema of the "products" collection and provide a summary of the data. Let me interact with your MongoDB database through the MCP server to get this information.
Ran `collection-schema` - MongoDB (MCP Server)
Now, let me fetch some sample data from the collection to provide you with a summary:
Ran `find` - MongoDB (MCP Server)
Let's also get a count of the total number of documents in the collection:
Ran `count` - MongoDB (MCP Server)
Let me get some aggregated statistics about the data:
Ran `aggregate` - MongoDB (MCP Server)
Ran `aggregate` - MongoDB (MCP Server)
Schema and Data Summary for the "products" Collection
Schema Overview
The "products" collection has the following schema:
1. _id: ObjectId - MongoDB's default unique identifier for each document
2. name: String - The name of the product
3. price: Number - The price of the product in USD
4. category: String - The category the product belongs to
5. quantity: Number - The available quantity of the product
6. inStock: Boolean - Flag indicating whether the product is in stock or not
Data Summary
Overall Statistics:
- Total number of products: 10
- Products in stock: 8
- Products out of stock: 2
- Categories Distribution:
- Electronics: 3 products (Laptop, Smartphone, Gaming Console)
- Audio: 2 products (Headphones, Bluetooth Speaker)
- Kitchen: 2 products (Coffee Maker, Blender)
- Furniture: 1 product (Office Chair)
- Home: 1 product (Desk Lamp)
- Wearables: 1 product (Fitness Tracker)
Price Range:
- Lowest priced item: $29.99 (Desk Lamp)
- Highest priced item: $1,299.99 (Laptop)
Inventory Status:
- Total inventory quantity: 153 items
- Average price across all products: approximately $313.99
- Products with zero quantity: 2 (Fitness Tracker, Blender) - these are marked as out of stock
Category Insights:
- Electronics has the highest average price at approximately $866.66
- Audio products have the highest total quantity (60 items)
- All zero-quantity products are correctly marked as out of stock (false)
This collection appears to be a simple product catalog for a store with various categories of merchandise, including pricing and inventory information
Find all products in the "products" collection that are out of stock
and update them to "in stock".
I'll help you find all products in the "products" collection that are out of stock and update them to be in stock. Let me interact with your MongoDB database through the MCP server to accomplish this.
First, let's find all products that are currently out of stock:
Ran `find` - MongoDB (MCP Server)
Now I'll update these out-of-stock products to be in stock. For this example, I'll also set a reasonable quantity value for each item:
Ran `update-many` - MongoDB (MCP Server)
Let's verify the updates by checking all products that were previously out of stock:
Ran `find` - MongoDB (MCP Server)
Great! I've successfully:
1. Found all products that were out of stock (2 products):
- Fitness Tracker (Wearables category)
- Blender (Kitchen category)
2. Updated these products to:
- Set them as in stock (inStock: true)
- Set their quantity to 10 units each
The update has been completed successfully, and both products are now marked as in stock with 10 units available for each. The MongoDB update operation matched 2 documents and modified 2 documents, confirming that all out-of-stock products have been updated as requested.

Atlas cluster 가 있고 Atlas 전용 MCP 도구를 활성화한 경우 AI 클라이언트 에서 다음 프롬프트를 실행 몇 가지 관리 작업을 수행합니다.

List all my organizations, projects, and clusters in Atlas.
I'll help you list all your MongoDB Atlas organizations, projects, and clusters. Let me retrieve that information for you.
Ran `atlas-list-orgs` - MongoDB (MCP Server)
Now that I've found your organization, let me list all the projects under it.
Ran `atlas-list-projects` - MongoDB (MCP Server)
Now, let me list all the clusters across all your projects:
Ran `atlas-list-clusters` - MongoDB (MCP Server)
Let me get more detailed information about each of your clusters:
Ran `atlas-inspect-cluster` - MongoDB (MCP Server)
Summary of Your Atlas Resources
Organization
- MongoDB (ID: <your-org-id>)
Projects (2)
- Sample Project (ID: <proj-id-1>)
- Test Project (ID: <proj-id-2>)
Clusters (2)
1. Cluster0 (in Sample Project)
- Type: DEDICATED
- Tier: M20
- State: UPDATING
- MongoDB Version: 8.1.1
- Connection String: <connection-string-1>
2. Cluster1 (in Test Project)
- Type: FREE
- Tier: N/A
- State: IDLE
- MongoDB Version: 8.0.10
- Connection String: <connection-string-2>
Create a new database user with read-only access to the "products"
collection, then add my current IP address to my cluster's access list.
I'll help you create a new database user with read-only access to the "products" collection and add your current IP address to your cluster's access list. Let me do this step-by-step.
Ran `atlas-list-orgs` - MongoDB (MCP Server)
First, I need to get information about your available Atlas projects to determine where to create the database user.
Ran `atlas-list-projects` - MongoDB (MCP Server)
Now, let's check which clusters are available:
Ran `atlas-list-clusters` - MongoDB (MCP Server)
Let's create a new database user with read-only access to the "products" collection in the Project with the Cluster. I'll create a user named "products_readonly":
Ran `atlas-create-db-user` - MongoDB (MCP Server)
Great! Now let's add your current IP address to the cluster's access list:
Ran `atlas-create-access-list` - MongoDB (MCP Server)
Let's verify the IP was added by checking the access list:
Ran `atlas-inspect-access-list` - MongoDB (MCP Server)
Perfect! Now let's also verify the user was created by listing all database users:
Ran `atlas-list-db-users` - MongoDB (MCP Server)
Summary of Actions Completed
1. Created a new database user:
- Username: products_readonly
- Password: <generated-password> (save this in a secure location)
- Access: Read-only access to the "products" collection in the "sample_store" database
- Project: Project (ID: <proj-id>)
- Cluster: Sample Cluster
2. Added your current IP address to the cluster's access list:
- IP Address: <your-ip-address>
- Project: Sample Project (ID: <proj-id>)
- Comment: "Added for products_readonly user"
The new user can now connect to your Atlas cluster and read data from the "products" collection, but cannot modify it. Your IP address has been added to the access list, allowing you to connect to the cluster from your current location.

다음 프롬프트를 실행하여 MongoDB 데이터와 관련된 코드를 생성합니다. 스키마 및 데이터 구조와 같은 컨텍스트를 제공하면 보다 정확한 코드 생성이 가능하여 환각이 줄어들고 에이전트 기능이 향상됩니다.

Review the schema of the "products" collection, then generate a Javascript
function that updates the "inStock" field to `false` when a product
reaches a quantity of 0.
I'll first review the schema of the "products" collection to understand its structure, then generate a Javascript function to update the "inStock" field to false when a product reaches a quantity of 0.
Ran `collection-schema` - MongoDB (MCP Server)
Now let me get some sample data from the collection to better understand the current state of the documents:
Ran `find` - MongoDB (MCP Server)
Based on the schema and sample data, I'll now generate a Javascript function that:
- Monitors the products collection
- Updates the "inStock" field to false when a product's quantity reaches 0
- Provides appropriate error handling and logging
Here's the Javascript function:
```
/**
* Updates the inStock field to false when a product's quantity reaches 0
*
* This function can be used in two ways:
* 1. As a one-time update to sync all products (updateAllProducts)
* 2. As an automated trigger after any update operation (setupUpdateTrigger)
*
* @param {Object} client - MongoDB client instance
* @param {string} dbName - Database name (default: 'sample_store')
* @param {string} collectionName - Collection name (default: 'products')
* @returns {Promise} Promise that resolves when the operation completes
*/
async function updateProductStockStatus(client, dbName = 'sample_store', collectionName = 'products') {
try {
// Get reference to the database and collection
const db = client.db(dbName);
const collection = db.collection(collectionName);
// Find all products with quantity 0 but still marked as in stock
const result = await collection.updateMany(
{ quantity: 0, inStock: true },
{ $set: { inStock: false } }
);
console.log(`Updated ${result.modifiedCount} products to out of stock`);
return result;
} catch (err) {
console.error('Error updating product stock status:', err);
throw err;
}
}
/**
* Sets up a change stream to automatically update inStock status
* when quantity changes to 0
*
* @param {Object} client - MongoDB client instance
* @param {string} dbName - Database name (default: 'sample_store')
* @param {string} collectionName - Collection name (default: 'products')
* @returns {ChangeStream} The change stream object
*/
async function setupUpdateTrigger(client, dbName = 'sample_store', collectionName = 'products') {
... (truncated)

MCP 서버 구성에 문제가 있는 경우 MongoDB MCP 서버 문제 해결을 참조하세요.

전체 구성 옵션과 사용 가능한 연장은 MCP 서버 구성 및 연결 및 지원되는연장을 참조하세요.

더 많은 사용 예시는 MongoDB MCP 서버 사용 예시를 참조하세요.

돌아가기

개요