MCP-MongoDB-MySQL-Server について
MCP-MongoDB-MySQL-Serverは、MySQLとMongoDBを操作するMCPサーバーで、mcp-mysql-serverにMongoDB対応を加えています。標準化されたインターフェースで両方のデータベースを扱いたいAIモデルや開発者向けです。
主な機能
- 01MySQLとMongoDBへの接続
- 02MySQLのクエリとデータ変更
- 03テーブル確認とスキーマ管理
- 04MongoDBドキュメントの検索・追加・更新・削除
- 05MongoDBコレクションの管理
活用シーン
- 01MCP経由でのMySQLクエリ
- 02MongoDBのドキュメントとコレクションの管理
- 03データベーススキーマの確認と変更
MCP 対応
MySQLとMongoDBへの接続、クエリ、管理を行うツールをクライアントに公開します。接続にはURL、ワークスペースパス、または直接指定した認証情報を使えます。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
MCP-MongoDB-MySQL-Server
enemyrr/mcp-mysql-serverプロジェクトを基に、MongoDBのサポートを追加したフォーク版です。
enemyrr/mcp-mysql-serverのフォークで、MongoDBのサポートが追加されています。
プロジェクト概要 | はじめに
MySQLおよびMongoDBのデータベース操作機能を提供するModel Context Protocolサーバーです。このサーバーにより、AIモデルは標準化されたインターフェースを通じてMySQLおよびMongoDBデータベースとやり取りできます。
MySQLおよびMongoDBのデータベース操作機能を提供するModel Context Protocolサーバーです。このサーバーにより、AIモデルは標準化されたインターフェースを通じてMySQLおよびMongoDBデータベースとやり取りできます。
このフォークについて
作者 | 作者: yaoxiaolinglong
フォークの理由 | フォークの理由: 元のプロジェクトはMySQLデータベースのみをサポートしていますが、実際のアプリケーションではMongoDBが必要になることもよくあります。既製のMongoDB MCPツールが見つからなかったため、元のプロジェクトにMongoDBのサポートを追加し、MySQLとMongoDBの両方をサポートするデータベースサーバーにしました。
元のプロジェクトはMySQLデータベースのみをサポートしていますが、実際のアプリケーションではMongoDBが必要になることもよくあります。既製のMongoDB MCPツールが見つからなかったため、元のプロジェクトにMongoDBのサポートを追加し、MySQLとMongoDBの両方をサポートするデータベースサーバーにしました。
インストールとセットアップ | Cursor IDE向けのインストールとセットアップ
Smithery経由でインストール
Smithery経由で、Claude Desktop向けにMySQL/MongoDB Database Serverを自動的にインストールします。
MySQL/MongoDB Database ServerをSmithery経由でClaude Desktopに自動インストールするには:
npx -y @smithery/cli install @yaoxiaolinglong/mcp-mongodb-mysql-server --client claude
手動インストール
- プロジェクトをクローンしてビルドします:
git clone https://github.com/yaoxiaolinglong/mcp-mongodb-mysql-server.git
cd mcp-mongodb-mysql-server
npm install
npm run build
- Cursor IDEの設定でサーバーを追加します:
- コマンドパレットを開きます(Cmd/Ctrl + Shift + P)
- 「MCP: Add Server」を検索します
- 次のフィールドに入力します:
- 名前:
mysql-mongodb - 種類:
command - コマンド:
node /absolute/path/to/mcp-mongodb-mysql-server/build/index.js
- 名前:
注意:
/absolute/path/to/を、プロジェクトをクローンしてビルドした実際のパスに置き換えてください。
/absolute/path/to/を、プロジェクトをクローンしてビルドした実際のパスに置き換えてください。
データベースの設定
MySQLの設定
MySQLデータベース接続は、次の3つの方法で設定できます。
MySQLデータベース接続は、次の3つの方法で設定できます。
- .envファイル内のデータベースURL(推奨):
DATABASE_URL=mysql://user:password@host:3306/database
- .envファイル内の個別パラメーター:
DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_password
DB_DATABASE=your_database
- ツールから直接接続:
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "connect_db",
arguments: {
url: "mysql://user:password@host:3306/database"
// 或者 | OR
workspace: "/path/to/your/project" // 将使用项目的.env文件 | Will use project's .env
// 或者 | OR
host: "localhost",
user: "your_user",
password: "your_password",
database: "your_database"
}
});
MongoDBの設定
MongoDBデータベース接続は、次の3つの方法で設定できます。
MongoDBデータベース接続は、次の3つの方法で設定できます。
- .envファイル内のMongoDB URL(推奨):
MONGODB_URI=mongodb://user:password@host:27017/database
MONGODB_DATABASE=your_database
- ツールから直接接続:
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "connect_mongodb",
arguments: {
url: "mongodb://user:password@host:27017/database"
// 或者 | OR
workspace: "/path/to/your/project" // 将使用项目的.env文件 | Will use project's .env
// 或者 | OR
database: "your_database" // 将使用默认连接URI | Will use default connection URI
}
});
利用可能なツール
MySQLツール
1. connect_db
URL、ワークスペースのパス、または直接指定した認証情報を使用してMySQLデータベースに接続します。
URL、ワークスペースのパス、または直接指定した認証情報を使用してMySQLデータベースに接続します。
2. query
オプションのプリペアドステートメントパラメーターを指定して、SELECT クエリを実行します。
Execute SELECT queries with optional prepared statement parameters.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "query",
arguments: {
sql: "SELECT * FROM users WHERE id = ?",
params: [1]
}
});
3. execute
オプションのプリペアドステートメントパラメーターを指定して、INSERT、UPDATE、または DELETE クエリを実行します。
Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "execute",
arguments: {
sql: "INSERT INTO users (name, email) VALUES (?, ?)",
params: ["John Doe", "[email protected]"]
}
});
4. list_tables
接続中のデータベースにあるすべてのテーブルを一覧表示します。
List all tables in the connected database.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "list_tables"
});
5. describe_table
指定したテーブルの構造を取得します。
Get the structure of a specific table.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "describe_table",
arguments: {
table: "users"
}
});
6. create_table
指定したフィールドとインデックスを持つ新しいテーブルを作成します。
Create a new table with specified fields and indexes.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "create_table",
arguments: {
table: "users",
fields: [
{
name: "id",
type: "int",
autoIncrement: true,
primary: true
},
{
name: "email",
type: "varchar",
length: 255,
nullable: false
}
],
indexes: [
{
name: "email_idx",
columns: ["email"],
unique: true
}
]
}
});
7. add_column
既存のテーブルに新しい列を追加します。
Add a new column to an existing table.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "add_column",
arguments: {
table: "users",
field: {
name: "phone",
type: "varchar",
length: 20,
nullable: true
}
}
});
MongoDBツール | MongoDB Tools
1. connect_mongodb
URL、ワークスペースのパス、またはデータベース名を使用して、MongoDB データベースに接続します。
Connect to MongoDB database using URL, workspace path, or database name.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "connect_mongodb",
arguments: {
url: "mongodb://user:password@host:27017/database"
}
});
2. mongodb_list_collections
接続中の MongoDB データベースにあるすべてのコレクションを一覧表示します。
List all collections in the connected MongoDB database.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "mongodb_list_collections"
});
3. mongodb_find
オプションのフィルター、上限、スキップ件数、並べ替えを指定して、MongoDB コレクション内のドキュメントを検索します。
Find documents in a MongoDB collection with optional filter, limit, skip, and sort.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "mongodb_find",
arguments: {
collection: "users",
filter: { age: { $gt: 18 } },
limit: 10,
skip: 0,
sort: { name: 1 }
}
});
4. mongodb_insert
MongoDB コレクションにドキュメントを挿入します。
Insert documents into a MongoDB collection.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "mongodb_insert",
arguments: {
collection: "users",
documents: [
{ name: "John Doe", email: "[email protected]", age: 30 },
{ name: "Jane Smith", email: "[email protected]", age: 25 }
]
}
});
5. mongodb_update
MongoDB コレクション内のドキュメントを更新します。
Update documents in a MongoDB collection.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "mongodb_update",
arguments: {
collection: "users",
filter: { name: "John Doe" },
update: { $set: { age: 31 } },
many: false // 只更新一个文档(默认)| Update only one document (default)
}
});
6. mongodb_delete
MongoDB コレクションからドキュメントを削除します。
Delete documents from a MongoDB collection.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "mongodb_delete",
arguments: {
collection: "users",
filter: { name: "John Doe" },
many: false // 只删除一个文档(默认)| Delete only one document (default)
}
});
7. mongodb_create_collection
MongoDB に新しいコレクションを作成します。
Create a new collection in MongoDB.
use_mcp_tool({
server_name: "mysql-mongodb",
tool_name: "mongodb_create_collection",
arguments: {
collection: "new_collection",
options: { capped: true, size: 1000000 }
}
});
機能 | Features
- 複数の接続方法(URL、ワークスペース、直接指定)| Multiple connection methods (URL, workspace, direct)
- MySQL と MongoDB の両方のデータベースをサポート | Support for both MySQL and MongoDB databases
- 安全な接続処理と自動クリーンアップ | Secure connection handling with automatic cleanup
- MySQL クエリパラメーターのプリペアドステートメントに対応 | Prepared statement support for MySQL query parameters
- 両方のデータベースに対応したスキーマ管理ツール | Schema management tools for both databases
- 包括的なエラー処理と検証 | Comprehensive error handling and validation
- TypeScript に対応 | TypeScript support
- ワークスペースの自動検出 | Automatic workspace detection
セキュリティ | Security
- MySQL でプリペアドステートメントを使用して SQL インジェクションを防止します | Uses prepared statements to prevent SQL injection in MySQL
- 環境変数を通じた安全なパスワード処理に対応します | Supports secure password handling through environment variables
- 実行前にクエリと操作を検証します | Validates queries and operations before execution
- 処理後に接続を自動的に閉じます | Automatically closes connections when done
エラー処理 | Error Handling
サーバーは以下の詳細なエラーメッセージを提供します:| The server provides detailed error messages for:
- 接続エラー | Connection failures
- 無効なクエリまたはパラメーター | Invalid queries or parameters
- 設定の不足 | Missing configuration
- データベースエラー | Database errors
- スキーマ検証エラー | Schema validation errors
貢献 | Contributing
貢献を歓迎します! https://github.com/yaoxiaolinglong/mcp-mongodb-mysql-server への Pull Request をお気軽にお送りください。
Contributions are welcome! Please feel free to submit a Pull Request to https://github.com/yaoxiaolinglong/mcp-mongodb-mysql-server
謝辞 | Acknowledgements
本プロジェクトは enemyrr/mcp-mysql-server を基に開発されました。貢献してくださった原作者に感謝します。
This project is based on enemyrr/mcp-mysql-server. Thanks to the original author for their contribution.
ライセンス | License
MIT
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。
