MongoDB

by kiliczsh
Verified
MIT License
1,002
167
  • Apple

Integrations

  • Provides access to MongoDB databases, allowing LLMs to inspect collection schemas and execute MongoDB operations like queries, aggregations, updates, inserts, and creating indexes

MCP MongoDB サーバー


LLMがMongoDBデータベースとやり取りできるようにするモデルコンテキストプロトコルサーバー。このサーバーは、標準化されたインターフェースを介してコレクションスキーマを検査し、MongoDB操作を実行する機能を提供します。

デモ

主な特徴

スマートなオブジェクトID処理

  • 文字列IDとMongoDB ObjectId間のインテリジェントな変換
  • objectIdModeパラメータで設定可能:
    • "auto" : フィールド名に基づいて変換します(デフォルト)
    • "none" : 変換なし
    • "force" : すべての文字列IDフィールドをObjectIdに強制する

柔軟な構成

  • 環境変数:
    • MCP_MONGODB_URI : MongoDB 接続 URI
    • MCP_MONGODB_READONLY : 「true」に設定すると読み取り専用モードが有効になります
  • コマンドラインオプション:
    • --read-onlyまたは-r : 読み取り専用モードで接続する

読み取り専用モード

  • 書き込み操作(更新、挿入、インデックス作成)に対する保護
  • 最適なパフォーマンスを得るために MongoDB のセカンダリ読み取り設定を使用します
  • 実稼働データベースに安全に接続するのに最適

MongoDB 操作

  • 読み取り操作:
    • オプションの実行プラン分析によるドキュメントのクエリ
    • 集計パイプラインを実行する
    • 条件に一致するドキュメントをカウントする
    • コレクションスキーマ情報を取得する
  • 書き込み操作(読み取り専用モードではない場合):
    • ドキュメントの更新
    • 新しいドキュメントを挿入する
    • インデックスを作成する

LLM統合

  • LLMインタラクション強化のためのコレクション完了
  • コンテキスト理解を向上させるスキーマ推論
  • データの洞察を得るための収集分析

インストール

グローバルインストール

npm install -g mcp-mongo-server

開発のために

# Clone repository git clone https://github.com/kiliczsh/mcp-mongo-server.git cd mcp-mongo-server # Install dependencies npm install # Build npm run build # Development with auto-rebuild npm run watch

使用法

基本的な使い方

# Start server with MongoDB URI npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database # Connect in read-only mode npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read-only

環境変数

環境変数を使用してサーバーを構成できます。これは、CI/CD パイプライン、Docker コンテナ、またはコマンド引数で接続の詳細を公開したくない場合に特に便利です。

# Set MongoDB connection URI export MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" # Enable read-only mode export MCP_MONGODB_READONLY="true" # Run server (will use environment variables if no URI is provided) npx -y mcp-mongo-server

Claude Desktop 構成で環境変数を使用する:

{ "mcpServers": { "mongodb-env": { "command": "npx", "args": [ "-y", "mcp-mongo-server" ], "env": { "MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database", "MCP_MONGODB_READONLY": "true" } } } }

Docker で環境変数を使用する:

docker run -e MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" \ -e MCP_MONGODB_READONLY="true" \ mcp-mongo-server

Claude Desktopとの統合

手動設定

Claude Desktop の設定ファイルにサーバー設定を追加します。

MacOS : ~/Library/Application Support/Claude/claude_desktop_config.json Windows : %APPDATA%/Claude/claude_desktop_config.json

コマンドライン引数のアプローチ:

{ "mcpServers": { "mongodb": { "command": "npx", "args": [ "-y", "mcp-mongo-server", "mongodb://muhammed:kilic@localhost:27017/database" ] }, "mongodb-readonly": { "command": "npx", "args": [ "-y", "mcp-mongo-server", "mongodb://muhammed:kilic@localhost:27017/database", "--read-only" ] } } }

環境変数アプローチ:

{ "mcpServers": { "mongodb": { "command": "npx", "args": [ "-y", "mcp-mongo-server" ], "env": { "MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database" } }, "mongodb-readonly": { "command": "npx", "args": [ "-y", "mcp-mongo-server" ], "env": { "MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database", "MCP_MONGODB_READONLY": "true" } } } }

GitHub パッケージの使用法:

{ "mcpServers": { "mongodb": { "command": "npx", "args": [ "-y", "github:kiliczsh/mcp-mongo-server", "mongodb://muhammed:kilic@localhost:27017/database" ] }, "mongodb-readonly": { "command": "npx", "args": [ "-y", "github:kiliczsh/mcp-mongo-server", "mongodb://muhammed:kilic@localhost:27017/database", "--read-only" ] } } }

WindsurfとCursorとの統合

MCP MongoDB サーバーは、Claude Desktop と同様に Windsurf および Cursor で使用できます。

ウィンドサーフィンの構成

Windsurf 構成にサーバーを追加します。

{ "mcpServers": { "mongodb": { "command": "npx", "args": [ "-y", "mcp-mongo-server", "mongodb://muhammed:kilic@localhost:27017/database" ] } } }

カーソルの設定

カーソルの場合は、設定にサーバー構成を追加します。

{ "mcpServers": { "mongodb": { "command": "npx", "args": [ "-y", "mcp-mongo-server", "mongodb://muhammed:kilic@localhost:27017/database" ] } } }

Claude Desktop 構成に示されているのと同じパターンに従って、Windsurf と Cursor の両方で環境変数アプローチを使用することもできます。

自動インストール

Smitheryの使用:

npx -y @smithery/cli install mcp-mongo-server --client claude

mcp-get の使用:

npx @michaellatman/mcp-get@latest install mcp-mongo-server

利用可能なツール

クエリ操作

  • query : MongoDBクエリを実行する
    { collection: "users", filter: { age: { $gt: 30 } }, projection: { name: 1, email: 1 }, limit: 20, explain: "executionStats" // Optional }
  • 集計: 集計パイプラインを実行する
    { collection: "orders", pipeline: [ { $match: { status: "completed" } }, { $group: { _id: "$customerId", total: { $sum: "$amount" } } } ], explain: "queryPlanner" // Optional }
  • count : 一致する文書を数える
    { collection: "products", query: { category: "electronics" } }

書き込み操作

  • 更新: ドキュメントを変更する
    { collection: "posts", filter: { _id: "60d21b4667d0d8992e610c85" }, update: { $set: { title: "Updated Title" } }, upsert: false, multi: false }
  • 挿入: 新しいドキュメントを追加する
    { collection: "comments", documents: [ { author: "user123", text: "Great post!" }, { author: "user456", text: "Thanks for sharing" } ] }
  • createIndex : コレクションのインデックスを作成する
    { collection: "users", indexes: [ { key: { email: 1 }, unique: true, name: "email_unique_idx" } ] }

システム操作

  • serverInfo : MongoDB サーバーの詳細を取得する
    { includeDebugInfo: true // Optional }

デバッグ

MCPサーバーはstdio経由で通信するため、デバッグが困難になる場合があります。MCPインスペクターを使用すると、より詳細な情報を得ることができます。

npm run inspector

これにより、ブラウザでデバッグ ツールにアクセスするための URL が提供されます。

ライセンス

このMCPサーバーはMITライセンスに基づいてライセンスされています。つまり、MITライセンスの条件に従って、ソフトウェアを自由に使用、改変、配布することができます。詳細については、プロジェクトリポジトリのLICENSEファイルをご覧ください。

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

LLMがMongoDBデータベースとやり取りできるようにするモデルコンテキストプロトコルサーバー。このサーバーは、標準化されたインターフェースを介してコレクションスキーマを検査し、MongoDB操作を実行する機能を提供します。

  1. Demo
    1. Key Features
      1. Smart ObjectId Handling
      2. Flexible Configuration
      3. Read-Only Mode
      4. MongoDB Operations
      5. LLM Integration
    2. Installation
      1. Global Installation
      2. For Development
    3. Usage
      1. Basic Usage
      2. Environment Variables
    4. Integration with Claude Desktop
      1. Manual Configuration
      2. GitHub Package Usage:
    5. Integration with Windsurf and Cursor
      1. Windsurf Configuration
      2. Cursor Configuration
      3. Automated Installation
    6. Available Tools
      1. Query Operations
      2. Write Operations
      3. System Operations
    7. Debugging
      1. License
        ID: zc7f7d53hc