mongodb-mcp-server
MongoDB MCP Server
MongoDB データベースおよび MongoDB Atlas と対話するための Model Context Protocol サーバー。
📚 目次
Related MCP server: Mongo MCP Server
前提条件
Node.js (v20.10.0 以降)
node -vMongoDB 接続文字列または Atlas API 認証情報。設定しない限りサーバーは起動しません。
Atlas ツールを使用するには Service Accounts Atlas API 認証情報 が必要です。MongoDB Atlas でサービスアカウントを作成し、その認証情報を認証に使用できます。詳細は Atlas API アクセス を参照してください。
MongoDB 接続文字列をお持ちの場合は、それを使用して MongoDB インスタンスに直接接続できます。
セットアップ
クイックスタート
注: Atlas API 認証情報を使用する場合は、サービスアカウントに必要な最小限の権限のみを必ず割り当ててください。詳細は Atlas API 権限 を参照してください。
ほとんどの MCP クライアントでは、MCP サーバーを追加するために設定ファイルの作成または変更が必要です。
注: 設定ファイルの構文はクライアントによって異なる場合があります。最新の期待される構文については、以下のリンクを参照してください:
VSCode: https://code.visualstudio.com/docs/copilot/chat/mcp-servers
Claude Desktop: https://modelcontextprotocol.io/quickstart/user
Cursor: https://docs.cursor.com/context/model-context-protocol
オプション 1: 接続文字列の引数
接続文字列を引数で渡すことができます。有効なユーザー名とパスワードを使用してください。
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--connectionString",
"mongodb://localhost:27017/myDatabase"
]
}
}
}注: 接続文字列は、ローカルインスタンスでも Atlas クラスターでも、任意の MongoDB クラスターに接続するように設定できます。
オプション 2: Atlas API 認証情報の引数
Atlas API サービスアカウントの認証情報を使用します。Atlas API アクセス セクションのすべての手順に従う必要があります。
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--apiClientId",
"your-atlas-service-accounts-client-id",
"--apiClientSecret",
"your-atlas-service-accounts-client-secret"
]
}
}
}オプション 3: コマンド引数を使用したスタンドアロンサービス
npx コマンドでサーバーを起動します:
npx -y mongodb-mcp-server --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret"引数の完全なリストについては 設定オプション を参照してください
Atlas サービスアカウントの認証情報の設定については Atlas API アクセス を参照してください
オプション 4: 環境変数を使用したスタンドアロンサービス
npx -y mongodb-mcp-server設定ファイルで環境変数を使用するか、環境変数を設定して npx でサーバーを実行できます。
オプション 5: Docker の使用
MongoDB MCP Server は Docker コンテナで実行できます。これにより分離が提供され、ローカルに Node.js をインストールする必要がありません。
環境変数で実行する
MongoDB 接続文字列または Atlas API 認証情報のいずれかを指定できます:
オプション A: 設定なし
docker run --rm -i \
mongodb/mongodb-mcp-server:latestオプション B: MongoDB 接続文字列あり
docker run --rm -i \
-e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" \
mongodb/mongodb-mcp-server:latestオプション C: Atlas API 認証情報あり
docker run --rm -i \
-e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \
-e MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret" \
mongodb/mongodb-mcp-server:latestMCP 設定ファイル内の Docker
オプションなし:
{
"mcpServers": {
"MongoDB": {
"command": "docker",
"args": ["run", "--rm", "-i", "mongodb/mongodb-mcp-server:latest"]
}
}
}接続文字列あり:
{
"mcpServers": {
"MongoDB": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"MDB_MCP_CONNECTION_STRING=mongodb+srv://username:password@cluster.mongodb.net/myDatabase",
"mongodb/mongodb-mcp-server:latest"
]
}
}
}Atlas API 認証情報あり:
{
"mcpServers": {
"MongoDB": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"MDB_MCP_API_CLIENT_ID=your-atlas-service-accounts-client-id",
"-e",
"MDB_MCP_API_CLIENT_SECRET=your-atlas-service-accounts-client-secret",
"mongodb/mongodb-mcp-server:latest"
]
}
}
}🛠️ サポートされているツール
ツール一覧
MongoDB Atlas ツール
atlas-list-orgs- MongoDB Atlas の組織を一覧表示しますatlas-list-projects- MongoDB Atlas のプロジェクトを一覧表示しますatlas-create-project- 新しい MongoDB Atlas プロジェクトを作成しますatlas-list-clusters- MongoDB Atlas のクラスターを一覧表示しますatlas-inspect-cluster- 特定の MongoDB Atlas クラスターを検査しますatlas-create-free-cluster- 無料の MongoDB Atlas クラスターを作成しますatlas-connect-cluster- MongoDB Atlas クラスターに接続しますatlas-inspect-access-list- MongoDB Atlas クラスターにアクセスできる IP/CIDR 範囲を検査しますatlas-create-access-list- MongoDB Atlas クラスターの IP/CIDR アクセスリストを設定しますatlas-list-db-users- MongoDB Atlas のデータベースユーザーを一覧表示しますatlas-create-db-user- MongoDB Atlas のデータベースユーザーを作成しますatlas-list-alerts- プロジェクトの MongoDB Atlas アラートを一覧表示します
注: Atlas ツールは、設定 セクションで認証情報を設定した場合にのみ利用できます。
MongoDB データベースツール
connect- MongoDB インスタンスに接続しますfind- MongoDB コレクションに対して find クエリを実行しますaggregate- MongoDB コレクションに対して集計を実行しますcount- MongoDB コレクション内のドキュメント数を取得しますinsert-one- MongoDB コレクションに単一のドキュメントを挿入しますinsert-many- MongoDB コレクションに複数のドキュメントを挿入しますcreate-index- MongoDB コレクションのインデックスを作成しますupdate-one- MongoDB コレクション内の単一のドキュメントを更新しますupdate-many- MongoDB コレクション内の複数のドキュメントを更新しますrename-collection- MongoDB コレクションの名前を変更しますdelete-one- MongoDB コレクションから単一のドキュメントを削除しますdelete-many- MongoDB コレクションから複数のドキュメントを削除しますdrop-collection- MongoDB データベースからコレクションを削除しますdrop-database- MongoDB データベースを削除しますlist-databases- MongoDB 接続のすべてのデータベースを一覧表示しますlist-collections- 指定されたデータベースのすべてのコレクションを一覧表示しますcollection-indexes- コレクションのインデックスを説明しますcollection-schema- コレクションのスキーマを説明しますcollection-storage-size- コレクションのサイズを MB 単位で取得しますdb-stats- MongoDB データベースに関する統計情報を返します
設定
MongoDB MCP Server は複数の方法で設定できます。優先順位は以下のとおりです(高い順):
コマンドライン引数
環境変数
設定オプション
オプション | 説明 |
| 認証用の Atlas API クライアント ID。Atlas ツールの実行に必要です。 |
| 認証用の Atlas API クライアントシークレット。Atlas ツールの実行に必要です。 |
| 直接データベース接続するための MongoDB 接続文字列。任意。設定しない場合は、MongoDB データと対話する前に |
| ログを保存するフォルダー。 |
| 無効にするツール名、操作タイプ、および/またはツールカテゴリの配列。 |
| true に設定すると、読み取りおよびメタデータ操作タイプのみが許可され、作成/更新/削除操作が無効になります。 |
| disabled に設定すると、テレメトリ収集が無効になります。 |
ログパス
デフォルトのログの場所は以下のとおりです:
Windows:
%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logsmacOS/Linux:
~/.mongodb/mongodb-mcp/.app-logs
無効化されたツール
disabledTools オプションを使用すると、特定のツールまたはツールのカテゴリを無効化できます。このオプションは文字列の配列を受け入れます。各文字列は、ツール名、操作タイプ、またはカテゴリを指定できます。
配列の構成方法は、使用する設定方法のタイプによって異なります:
環境変数設定の場合、カンマ区切りの文字列を使用します:
export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema"。コマンドライン引数設定の場合、スペース区切りの文字列を使用します:
--disabledTools create update delete atlas collectionSchema。
ツールのカテゴリ:
atlas- MongoDB Atlas ツール(クラスターの一覧表示、クラスターの作成など)。mongodb- MongoDB データベースツール(find、aggregate など)。
操作タイプ:
create- リソースを作成するツール(クラスターの作成、ドキュメントの挿入など)。update- リソースを更新するツール(ドキュメントの更新、コレクションの名前変更など)。delete- リソースを削除するツール(ドキュメントの削除、コレクションの削除など)。read- リソースを読み取るツール(find、aggregate、クラスターの一覧表示など)。metadata- メタデータを読み取るツール(データベースの一覧表示、コレクションの一覧表示、コレクションスキーマなど)。
読み取り専用モード
readOnly 設定オプションを使用すると、MCP サーバーを「read」および「metadata」操作タイプのツールのみを使用するように制限できます。有効にすると、「create」、「update」、「delete」の操作タイプを持つすべてのツールはサーバーに登録されません。
これは、データやインフラストラクチャへの変更を許可せずに、分析目的で MongoDB データへのアクセスを提供したいシナリオで役立ちます。
読み取り専用モードは、次の方法で有効にできます:
環境変数:
export MDB_MCP_READ_ONLY=trueコマンドライン引数:
--readOnly
読み取り専用モードがアクティブな場合、この制限により登録が阻止されたツールを示すメッセージがサーバーログに表示されます。
テレメトリ
telemetry 設定オプションを使用すると、テレメトリ収集を無効化できます。有効にすると、MCP サーバーは使用状況データを収集し、MongoDB に送信します。
テレメトリは、次の方法で無効化できます:
環境変数:
export MDB_MCP_TELEMETRY=disabledコマンドライン引数:
--telemetry disabledDO_NOT_TRACK 環境変数:
export DO_NOT_TRACK=1
Atlas API アクセス
Atlas API ツールを使用するには、MongoDB Atlas でサービスアカウントを作成する必要があります:
ℹ️ 注: 各 Atlas 操作に必要な最小権限の詳細については、以下の Atlas API 権限 セクションを参照してください。
サービスアカウントを作成する:
cloud.mongodb.com で MongoDB Atlas にログインします
Access Manager > Organization Access に移動します
Add New > Applications > Service Accounts をクリックします
サービスアカウントの名前、説明、有効期限を入力します(例:「MCP、MCP Server Access、7 days」)
ユースケースに必要な最小限の権限のみを割り当てます。
詳細については Atlas API 権限 を参照してください。
「Create」をクリックします
サービスアカウントの詳細については、MongoDB Atlas ドキュメント を確認してください。
クライアント認証情報を保存する:
作成後、Client ID と Client Secret が表示されます
重要: Client Secret は再度表示されないため、すぐにコピーして保存してください
アクセスリストエントリを追加する:
API アクセスリストに IP アドレスを追加します
MCP サーバーを設定する:
以下の設定方法のいずれかを使用して、
apiClientIdとapiClientSecretを設定します
Atlas API 権限
セキュリティ警告: Organization Owner ロールの付与はほとんど必要なく、セキュリティリスクとなる可能性があります。ユースケースに必要な最小限の権限のみを割り当ててください。
クイックリファレンス: 操作ごとに必要なロール
実行したい操作 | 割り当てる最も安全なロール(場所) |
組織/プロジェクトの一覧表示 | Org Member または Org Read Only (Org) |
新しいプロジェクトの作成 | Org Project Creator (Org) |
プロジェクト内のクラスター/データベースの表示 | Project Read Only (Project) |
プロジェクト内のクラスターの作成/管理 | Project Cluster Manager (Project) |
プロジェクトのアクセスリストの管理 | Project IP Access List Admin (Project) |
データベースユーザーの管理 | Project Database Access Admin (Project) |
ほとんどの操作では、プロジェクトレベルのロールを優先します。管理または表示が必要な特定のプロジェクトにのみ割り当ててください。
組織内のすべてのプロジェクトと設定に対する完全な管理制御が必要な場合を除き、Organization Owner は避けてください。
ロールとその権限の完全なリストについては、Atlas ユーザーロールのドキュメント を参照してください。
設定方法
環境変数
プレフィックス MDB_MCP_ に続けてオプション名を大文字のアンダースコア区切りで使用して、環境変数を設定します:
# Set Atlas API credentials (via Service Accounts)
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
# Set a custom MongoDB connection string
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
export MDB_MCP_LOG_PATH="/path/to/logs"
MCP 設定ファイルの例
環境変数を使用した接続文字列
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
}
}
}
}環境変数を使用した Atlas API 認証情報
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server"],
"env": {
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
}
}
}
}コマンドライン引数
サーバーの起動時に、設定オプションをコマンドライン引数として渡します:
npx -y mongodb-mcp-server --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret" --connectionString="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" --logPath=/path/to/logsMCP 設定ファイルの例
コマンドライン引数を使用した接続文字列
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--connectionString",
"mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
]
}
}
}コマンドライン引数を使用した Atlas API 認証情報
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--apiClientId",
"your-atlas-service-accounts-client-id",
"--apiClientSecret",
"your-atlas-service-accounts-client-secret"
]
}
}
}🤝 コントリビューション
コントリビューションに興味がありますか? 素晴らしい! コードコントリビューション、標準、新しいツールの追加、トラブルシューティング情報に関するガイドラインについては、コントリビューションガイド を確認してください。
This server cannot be deployed
Maintenance
Related MCP Connectors
Model Context Protocol server for Studex tools, notifications, and profile integrations
A Model Context Protocol server for Wix AI tools
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Model Context Protocol server for todo.vu task management and time tracking.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides a standardized interface for AI assistants to interact with MongoDB databases, enabling CRUD operations, schema analysis, and database management through the Model Context Protocol.1-
- -licenseBqualityNot gradedmaintenanceEnables interaction with MongoDB databases through the Model Context Protocol. Provides basic database connectivity checking and status monitoring capabilities.1-
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to interact with MongoDB databases through a complete suite of CRUD operations, administrative tasks, and index management tools. It supports database and collection handling, aggregation pipelines, and comprehensive server monitoring via the Model Context Protocol.146 PyPI3MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with MongoDB databases and MongoDB Atlas for querying data and managing clusters via the Model Context Protocol. It supports both local and cloud-based deployments using connection strings or Atlas API credentials.170,471 npmApache 2.0