A Model Context Protocol server that enables AI models to interact with both MySQL and MongoDB databases through a standardized interface, supporting comprehensive database operations including queries, schema management, and CRUD operations.
这是一个基于 enemyrr/mcp-mysql-server 项目的二次开发版本,添加了MongoDB支持。
This is a fork of enemyrr/mcp-mysql-server with added MongoDB support.
这是一个Model Context Protocol服务器,提供MySQL和MongoDB数据库操作功能。该服务器使AI模型能够通过标准化接口与MySQL和MongoDB数据库交互。
A Model Context Protocol server that provides MySQL and MongoDB database operations. This server enables AI models to interact with MySQL and MongoDB databases through a standardized interface.
作者 | Author: yaoxiaolinglong
二次开发原因 | Reason for Fork: 原项目只支持MySQL数据库,但在实际应用中经常需要使用MongoDB。由于找不到现成的MongoDB MCP工具,因此在原项目基础上添加了MongoDB支持,使其成为一个同时支持MySQL和MongoDB的数据库服务器。
The original project only supports MySQL database, but MongoDB is often needed in practical applications. Due to the lack of ready-made MongoDB MCP tools, MongoDB support was added to the original project, making it a database server that supports both MySQL and MongoDB.
通过Smithery为Claude Desktop自动安装MySQL/MongoDB数据库服务器:
To install MySQL/MongoDB Database Server for Claude Desktop automatically via Smithery:
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
mysql-mongodb
command
node /absolute/path/to/mcp-mongodb-mysql-server/build/index.js
注意 | Note: 将
/absolute/path/to/
替换为您克隆并构建项目的实际路径。Replace
/absolute/path/to/
with the actual path where you cloned and built the project.
您可以通过以下三种方式配置MySQL数据库连接:
You can configure the MySQL database connection in three ways:
DATABASE_URL=mysql://user:password@host:3306/database
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数据库连接:
You can configure the MongoDB database connection in three ways:
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数据库,使用URL、工作区路径或直接凭据。
Connect to MySQL database using URL, workspace path, or direct credentials.
执行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] } });
执行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", "john@example.com"] } });
列出连接的数据库中的所有表。
List all tables in the connected database.
use_mcp_tool({ server_name: "mysql-mongodb", tool_name: "list_tables" });
获取特定表的结构。
Get the structure of a specific table.
use_mcp_tool({ server_name: "mysql-mongodb", tool_name: "describe_table", arguments: { table: "users" } });
创建一个新表,指定字段和索引。
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 } ] } });
向现有表添加新列。
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数据库,使用URL、工作区路径或数据库名称。
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" } });
列出连接的MongoDB数据库中的所有集合。
List all collections in the connected MongoDB database.
use_mcp_tool({ server_name: "mysql-mongodb", tool_name: "mongodb_list_collections" });
在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 } } });
向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: "john@example.com", age: 30 }, { name: "Jane Smith", email: "jane@example.com", age: 25 } ] } });
更新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) } });
从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) } });
在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 } } });
服务器提供以下详细错误消息:| The server provides detailed error messages for:
欢迎贡献!请随时提交Pull Request到 https://github.com/yaoxiaolinglong/mcp-mongodb-mysql-server
Contributions are welcome! Please feel free to submit a Pull Request to https://github.com/yaoxiaolinglong/mcp-mongodb-mysql-server
本项目基于 enemyrr/mcp-mysql-server 开发,感谢原作者的贡献。
This project is based on enemyrr/mcp-mysql-server. Thanks to the original author for their contribution.
MIT
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!