Universal DB MCP
Enables Claude Desktop to interact with MySQL, PostgreSQL, and Redis databases using natural language for data querying and schema analysis. It provides a secure interface with a default read-only mode to prevent unauthorized database modifications.
README
🔌 MCP 数据库万能连接器
让 Claude Desktop 直接连接你的数据库,用自然语言查询和分析数据
🎯 为什么使用本项目
作为开发者,你是否遇到过这些场景:
- 📊 临时数据分析:想快速查看生产数据库的某些指标,但不想写 SQL?
- 🔍 问题排查:需要跨多个表关联查询,但记不清表结构?
- 🤖 AI 辅助开发:希望 Claude 能直接理解你的数据库结构,生成准确的查询?
MCP 数据库万能连接器 通过 Model Context Protocol (MCP) 协议,让 Claude Desktop 成为你的数据库助手:
✅ 自然语言查询 - 用中文描述需求,Claude 自动生成并执行 SQL
✅ 智能表结构理解 - 自动获取数据库 Schema,提供精准建议
✅ 多数据库支持 - MySQL、PostgreSQL、Redis、Oracle、达梦 一键切换
✅ 安全第一 - 默认只读模式,防止误操作删库
✅ 开箱即用 - 无需复杂配置,一行命令启动
🚀 快速开始
前置要求
- Node.js >= 20
- Claude Desktop 应用
- 至少一个数据库实例(MySQL/PostgreSQL/Redis/Oracle/达梦)
安装
npm install -g universal-db-mcp
或使用 npx 直接运行(无需安装):
npx universal-db-mcp
配置 Claude Desktop
编辑 Claude Desktop 配置文件:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
添加以下配置:
{
"mcpServers": {
"universal-db": {
"command": "npx",
"args": [
"universal-db-mcp",
"--type", "mysql",
"--host", "localhost",
"--port", "3306",
"--user", "root",
"--password", "your_password",
"--database", "your_database"
]
}
}
}
启动使用
- 重启 Claude Desktop
- 在对话中直接询问:
- "帮我查看 users 表的结构"
- "统计最近 7 天的订单数量"
- "找出消费金额最高的 10 个用户"
Claude 会自动调用数据库工具完成查询!
🛡️ 安全模式
默认情况下,本工具运行在只读模式,会拒绝所有写入操作(DELETE、UPDATE、DROP、TRUNCATE)。
如果你需要执行写入操作(请谨慎!),需要显式添加参数:
{
"args": [
"universal-db-mcp",
"--danger-allow-write",
"--type", "mysql",
...
]
}
⚠️ 警告:启用写入模式后,Claude 可以修改你的数据库。请仅在开发环境使用,或确保你完全理解操作的后果。
📖 支持的数据库
| 数据库 | 类型参数 | 默认端口 | 状态 | 说明 |
|---|---|---|---|---|
| MySQL | --type mysql |
3306 | ✅ 已支持 | - |
| PostgreSQL | --type postgres |
5432 | ✅ 已支持 | - |
| Redis | --type redis |
6379 | ✅ 已支持 | - |
| Oracle(12c以上) | --type oracle |
1521 | ✅ 已支持 | - |
| 达梦(DM7/DM8) | --type dm |
5236 | ✅ 已支持 | 驱动自动安装 |
| SQL Server (2012+) | --type sqlserver 或 --type mssql |
1433 | ✅ 已支持 | 支持 Azure SQL Database |
| MongoDB | --type mongo |
- | 🚧 计划中 | - |
| SQLite | --type sqlite |
- | 🚧 计划中 | - |
注意: 达梦数据库驱动 dmdb 会作为可选依赖自动安装。如果安装失败,请手动运行 npm install -g dmdb。
🔧 命令行参数
universal-db-mcp [选项]
选项:
--type <db> 数据库类型 (mysql|postgres|redis|oracle|dm|sqlserver|mssql)
--host <host> 数据库主机地址 (默认: localhost)
--port <port> 数据库端口
--user <user> 用户名
--password <password> 密码
--database <database> 数据库名称
--danger-allow-write 启用写入模式(危险!)
--help 显示帮助信息
🏗️ 架构设计
本项目采用模块化适配器模式,方便社区贡献新的数据库支持:
src/
├── adapters/ # 数据库适配器
│ ├── mysql.ts
│ ├── postgres.ts
│ ├── redis.ts
│ ├── oracle.ts
│ └── dm.ts
├── types/ # TypeScript 类型定义
│ └── adapter.ts
├── utils/ # 工具函数
│ └── safety.ts # 安全检查逻辑
└── server.ts # MCP 服务器主逻辑
🤝 贡献指南
欢迎提交 Issue 和 Pull Request!
如果你想添加新的数据库支持,只需:
- 在
src/adapters/下实现DbAdapter接口 - 添加对应的数据库驱动依赖
- 更新 README 文档
📄 开源协议
MIT License - 自由使用,欢迎 Star ⭐
🙏 致谢
- Model Context Protocol - Anthropic 提供的强大协议
- 所有贡献者和使用者
如果这个项目对你有帮助,请给个 Star ⭐ 支持一下!
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.