MongoDB MCP Server
Cho phép agent AI của bạn làm việc với cơ sở dữ liệu MongoDB và cụm MongoDB Atlas qua các yêu cầu bằng ngôn ngữ thường.
1.2k sao trên GitHubbởi MongoDBGiấy phép Apache-2.0Cập nhật 18 ngày trước
Cách cài đặt
MCP này chạy cục bộ: nó chạy trên máy tính của bạn.
Nó hoạt động trong các ứng dụng cài trên máy (Claude Desktop, Claude Code, Cursor, VS Code…). Hãy chọn ứng dụng của bạn:
Dán vào terminal:
claude mcp add mongodb -- npx -y mongodb-mcp-server
Những gì cần điền
| Tên | Mô tả | Bắt buộc |
|---|---|---|
MDB_MCP_AGGREGATION_COUNT_MAX_TIME_MS_CAP | Deprecated. Use aggregationCountTimeoutMs instead. | Không |
MDB_MCP_AGGREGATION_COUNT_TIMEOUT_MS | The maximum time in milliseconds for the count phase of aggregation operations. This is used to limit the time spent counting documents when determining if results were capped. | Không |
MDB_MCP_ALLOW_REQUEST_OVERRIDES | When set to true, allows configuration values to be overridden via request headers and query parameters. | Không |
MDB_MCP_API_CLIENT_ID | Atlas API client ID for authentication. Required for running Atlas tools. | Không |
MDB_MCP_API_CLIENT_SECRET | Atlas API client secret for authentication. Required for running Atlas tools. | Không |
MDB_MCP_ASSISTANT_BASE_URL | Base URL for the MongoDB Assistant API. | Không |
MDB_MCP_ATLAS_TEMPORARY_DATABASE_USER_LIFETIME_MS | Time in milliseconds that temporary database users created when connecting to MongoDB Atlas clusters will remain active before being automatically deleted. | Không |
MDB_MCP_CONFIRMATION_REQUIRED_TOOLS | Comma separated values of tool names that require user confirmation before execution. Requires the client to support elicitation. | Không |
MDB_MCP_CONNECTION_IDLE_TIMEOUT_MS | Milliseconds a MongoDB connection may stay unused (no tool call touching it) before it is closed to release the underlying connection pool and its server-side state. Applied per connection regardless of its connection scope; the preconfigured connection is excluded, and the reaper runs on this cadence. Set to 0 to disable reaping; must not be negative. | Không |
MDB_MCP_CONNECTION_SCOPE | Visibility scope for MongoDB connections created at runtime. With 'session' (the default), each MCP session only sees the connections it created (plus the shared 'preconfigured' one) and they are closed when the session ends. With 'global', connections are shared across all sessions and survive session rotation. Deprecated: the MCP protocol is moving to sessionless, so this option will soon be removed and the connection scope will default to 'global'. For shared-server use cases, use the Atlas-Managed MCP server or build an authenticated library using the @mongodb-js/mcp-cli package. Note: on the sessionless (2026-07-28) HTTP path, a request without an mcp-session-id falls back to the shared ('global') scope so it can still persist connections across requests; the legacy sessionful path always carries a server-issued session. | Không |
MDB_MCP_CONNECTION_STRING | MongoDB connection string for direct database connections, exposed under the connectionId "preconfigured". Optional, if not set, you'll need to call the connect tool before interacting with MongoDB data. Deprecated: prefer the "preconfigured" entry of connectionStrings. | Không |
MDB_MCP_CONNECTION_STRINGS | MongoDB connection strings keyed by name, as a JSON object (e.g. {"preconfigured": "mongodb://...", "analytics": "mongodb://..."}). Each name becomes a connectionId that the MongoDB tools can use directly, so one server can reach several deployments. Connections are opened on first use. Environment variable or config file only. | Không |
MDB_MCP_DANGEROUS_HOST_BINDING | When set to true, allows binding the HTTP server (and monitoring server) to a non-loopback host such as 0.0.0.0, a LAN IP, or an empty host (all interfaces). Binding to a non-loopback host exposes the server to the entire network and can allow unauthorized access. Off by default: the server refuses to start on a non-loopback host unless this is true. | Không |
MDB_MCP_DISABLE_SERVER_SIDE_JS | When set to true, disallows the use of server-side JavaScript operators (such as $where, $function, and $accumulator) in query filters and aggregation pipelines. | Không |
MDB_MCP_DISABLE_UNTRUSTED_DATA_WARNING | When set to true, tool responses include potentially untrusted data (such as documents or query results) as-is, without wrapping it in delimiters and a prompt-injection warning. | Không |
MDB_MCP_DISABLED_TOOLS | Comma separated values of tool names, operation types, and/or categories of tools that will be disabled. | Không |
MDB_MCP_DRY_RUN | When true, runs the server in dry mode: dumps configuration and enabled tools, then exits without starting the server. | Không |
MDB_MCP_ELICITATION_TIMEOUT_MS | Time in milliseconds the user has to respond to an elicitation request (such as a tool confirmation prompt) before it fails. | Không |
MDB_MCP_EVICTION_IDLE_GRACE_M_S | How long a session must be idle before it becomes eligible for least-recently-used eviction when the HTTP transport is at its maxSessions cap (only used when transport is 'http'). Swept back to idleTimeoutMs when larger. | Không |
MDB_MCP_EXPORT_CLEANUP_INTERVAL_MS | Time in milliseconds between export cleanup cycles that remove expired export files. | Không |
MDB_MCP_EXPORT_TIMEOUT_MS | Time in milliseconds after which an export is considered expired and eligible for cleanup. | Không |
MDB_MCP_EXPORTS_PATH | Folder to store exported data files. | Không |
MDB_MCP_EXTERNALLY_MANAGED_SESSIONS | When true, the 2025-era HTTP transport accepts a session ID supplied externally through the 'mcp-session-id' header. When an external ID is supplied, the initialization request is optional, and an implicitly re-initialized session restores the client's previously negotiated capabilities from the session store. | Không |
MDB_MCP_HEALTH_CHECK_HOST | Deprecated. Use monitoringServerHost instead. Host address to bind the healthCheck HTTP server to (only used when transport is 'http'). If provided, healthCheckPort must also be set. | Không |
MDB_MCP_HEALTH_CHECK_PORT | Deprecated. Use monitoringServerPort instead. Port number for the healthCheck HTTP server (only used when transport is 'http'). If provided, healthCheckHost must also be set. | Không |
MDB_MCP_HTTP_BODY_LIMIT | Maximum size of the HTTP request body in bytes (only used when transport is 'http'). This value is passed as the optional limit parameter to the Express.js json() middleware. | Không |
MDB_MCP_HTTP_HEADERS | Header that the HTTP server will validate when making requests (only used when transport is 'http'). | Không |
MDB_MCP_HTTP_HOST | Host address to bind the HTTP server to (only used when transport is 'http'). | Không |
MDB_MCP_HTTP_PORT | Port number for the HTTP server (only used when transport is 'http'). Use 0 for a random port. | Không |
MDB_MCP_HTTP_RESPONSE_TYPE | The HTTP response type for tool responses: 'sse' for Server-Sent Events, 'json' for standard JSON responses. | Không |
MDB_MCP_IDLE_TIMEOUT_MS | Idle timeout for a client to disconnect (only applies to http transport). | Không |
MDB_MCP_INDEX_CHECK | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. | Không |
MDB_MCP_LOG_PATH | Folder to store logs. | Không |
MDB_MCP_LOGGERS | Comma separated values of logger types. | Không |
MDB_MCP_MAX_ACTIVE_CONNECTIONS | Maximum number of MongoDB connections a single scope (an MCP session by default, see connectionScope) can hold open. When exceeded, the scope's least-recently-used connection is closed and its connectionId revoked. The preconfigured connection does not count towards the limit. | Không |
MDB_MCP_MAX_BYTES_PER_QUERY | The maximum size in bytes for results from a find or aggregate tool call. This serves as an upper bound for the responseBytesLimit parameter in those tools. | Không |
MDB_MCP_MAX_DOCUMENTS_PER_QUERY | The maximum number of documents that can be returned by a find or aggregate tool call. For the find tool, the effective limit will be the smaller of this value and the tool's limit parameter. | Không |
MDB_MCP_MAX_SESSIONS | Maximum number of concurrent sessions the HTTP transport will hold in memory (only used when transport is 'http'). Each session holds a full server instance, transport, and timers, so choose a value based on your deployment's available memory; the default is a conservative safety net rather than a recommended production value. | Không |
MDB_MCP_MAX_TIME_M_S | Deprecated. Use timeoutMs instead. The maximum time in milliseconds that operations are allowed to run on the MongoDB server. | Không |
MDB_MCP_MCP_CLIENT_LOG_LEVEL | Minimum severity level for log messages forwarded to the MCP client. | Không |
MDB_MCP_MONITORING_SERVER_FEATURES | Features to expose on the monitoring server: health-check, metrics, and process-metrics. process-metrics exposes /metrics with Node.js process metrics (only used when transport is 'http' and monitoringServerHost/monitoringServerPort are set). | Không |
MDB_MCP_MONITORING_SERVER_HOST | Host address to bind the monitoring HTTP server to (only used when transport is 'http'). If provided, monitoringServerPort must also be set. | Không |
MDB_MCP_MONITORING_SERVER_PORT | Port number for the monitoring HTTP server (only used when transport is 'http'). If provided, monitoringServerHost must also be set. | Không |
MDB_MCP_NOTIFICATION_TIMEOUT_MS | Notification timeout for a client to be aware of disconnect (only applies to http transport). | Không |
MDB_MCP_PREVIEW_FEATURES | Comma separated values of preview features that are enabled. | Không |
MDB_MCP_QUERY_COUNT_MAX_TIME_MS_CAP | Deprecated. Use queryCountTimeoutMs instead. | Không |
MDB_MCP_QUERY_COUNT_TIMEOUT_MS | The maximum time in milliseconds for the count phase of find operations. This is used to limit the time spent counting documents when determining if results were capped. | Không |
MDB_MCP_READ_ONLY | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. | Không |
MDB_MCP_TELEMETRY | When set to disabled, disables telemetry collection. | Không |
MDB_MCP_TIMEOUT_MS | The maximum time in milliseconds that MongoDB operations are allowed to run, applied as the driver's timeoutMS (client-side operation timeout, CSOT) on each connection. It bounds the entire operation, including server selection and network round trips. | Không |
MDB_MCP_TRANSPORT | Either 'stdio' or 'http'. | Không |
MDB_MCP_VOYAGE_API_KEY | API key for Voyage AI embeddings service (required for creating Atlas Local deployments with auto-embed vector search capabilities). | Không |
Xong rồi! Giờ hãy thử
Khởi động lại ứng dụng và dán một trong các yêu cầu này vào khung chat:
Cho tôi xem các collection trong cơ sở dữ liệu myDatabase.
Tìm mười tài liệu mới nhất trong collection orders.
Đây là gì
Máy chủ này kết nối agent AI của bạn với MongoDB. Với một chuỗi kết nối, nó hoạt động với mọi triển khai MongoDB, cục bộ hoặc Atlas, và với thông tin xác thực API của Atlas, nó cũng có thể quản lý Atlas. README khuyên dùng chế độ chỉ đọc theo mặc định, để agent có thể xem dữ liệu mà không thay đổi nó.
Nó làm được gì
- Kết nối với cơ sở dữ liệu MongoDB bằng chuỗi kết nối
- Dùng các công cụ Atlas với thông tin xác thực API của tài khoản dịch vụ
- Chạy ở chế độ chỉ đọc với
--readOnly - Thiết lập có hướng dẫn với
npx -y mongodb-mcp-server@latest setup - Kết nối với máy chủ MCP Atlas do MongoDB lưu trữ qua OAuth bằng plugin mongodb-atlas
Khi nào nên dùng
- ›Khi bạn muốn agent duyệt một collection MongoDB và giải thích nội dung của nó.
- ›Khi bạn muốn quản lý một cụm Atlas bằng cách hỏi trong chat.
- ›Khi bạn muốn truy cập cơ sở dữ liệu không thể ghi, nên bạn thêm --readOnly.
Bạn cần gì
Skill đi kèm tốt
MCP hay skill?
MCP cho agent đôi tay. Skill dạy cách dùng đôi tay đó đúng cách. Kết hợp lại, kết quả tốt hơn và tốn ít token hơn.
azure-mgmt-mongodbatlas-dotnetGiúp agent của bạn quản lý MongoDB Atlas như tài nguyên Azure. Cho phép gộp thanh toán và quản lý về một mối.nocobase-app-plugin-database-explorerGiúp agent xem các kết nối cơ sở dữ liệu, collection và trường của ứng dụng NocoBase ở chế độ chỉ đọc, và thiết lập quyền truy cập cho vai trò khác.prisma-database-setupGiúp agent thiết lập Prisma với PostgreSQL, MySQL, SQLite, MongoDB và các cơ sở dữ liệu khác, đồng thời sửa lỗi kết nối.Câu hỏi thường gặp
Có miễn phí và mã nguồn mở không?
Máy chủ do MongoDB xuất bản và chạy bằng npx hoặc Docker. README không nêu giá của chính máy chủ.
Nó có thể thay đổi dữ liệu của tôi không?
Chỉ khi bạn cho phép. Mọi ví dụ trong README đều có --readOnly, và bạn bỏ nó đi để bật các thao tác ghi.
Tôi nên truyền bí mật bằng cách nào?
README khuyên dùng biến môi trường thay vì tham số dòng lệnh, vì tham số có thể xuất hiện trong danh sách tiến trình và nhật ký.
Nó cần thông tin xác thực nào?
Hoặc một chuỗi kết nối MongoDB, hoặc thông tin xác thực API của tài khoản dịch vụ Atlas. Các công cụ Atlas cần thông tin xác thực tài khoản dịch vụ.
Có tùy chọn lưu trữ cho Atlas không?
Có. Plugin mongodb-atlas kết nối với máy chủ MCP Atlas do MongoDB lưu trữ qua OAuth, nên bạn không chạy gì cục bộ.
Tôi có thể chạy trong Docker không?
Có. Image là mongodb/mongodb-mcp-server:latest, với chuỗi kết nối được truyền qua biến môi trường.
Nếu không hoạt động
- ›Kiểm tra node -v hiển thị 22.13 trở lên, vì hỗ trợ Node 20 đã bị ngừng.
- ›Kiểm tra chuỗi kết nối có tên người dùng và mật khẩu hợp lệ.
- ›Để dùng công cụ Atlas, đảm bảo tài khoản dịch vụ có quyền tối thiểu cần thiết và cả client id lẫn secret đều đã được đặt.
5 skill mới mỗi tuần. Đọc chỉ 1 phút.