universal-db-mcp
Enables natural language querying and schema exploration for ClickHouse databases, providing tools to execute queries, retrieve schema information, and inspect table data.
Enables natural language querying and schema exploration for MongoDB databases, providing tools to execute queries, retrieve schema information, and inspect table data.
Enables natural language querying and schema exploration for MySQL databases, providing tools to execute queries, retrieve schema information, and inspect table data.
Enables natural language querying and schema exploration for PostgreSQL databases, providing tools to execute queries, retrieve schema information, and inspect table data.
Enables natural language querying and schema exploration for Redis databases, providing tools to execute queries, retrieve schema information, and inspect table data.
Enables natural language querying and schema exploration for SQLite databases, providing tools to execute queries, retrieve schema information, and inspect table data.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@universal-db-mcpShow me the top 10 customers by order value this month"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
✨ 特性
支持 17 种数据库 - MySQL、PostgreSQL、Redis(Cluster)、Oracle、SQL Server、MongoDB、SQLite,Hive(Preto)以及 10 种国产数据库
标准协议兼容 - 支持 MCP stdio、MCP SSE、MCP Streamable HTTP 和 REST API
灵活架构 - 2 种启动模式(stdio/http),4 种接入方式:MCP stdio、MCP SSE、MCP Streamable HTTP、REST API
安全第一 - 默认只读模式,防止意外的数据修改
智能缓存 - Schema 缓存支持可配置的 TTL,性能极速
Schema 增强 - 表注释、隐式关系推断,提升 Text2SQL 准确性
多 Schema 支持 - 自动发现所有用户 Schema(PostgreSQL、SQL Server、Oracle、达梦等)
数据脱敏 - 自动保护敏感数据(手机号、邮箱、身份证、银行卡等)
连接稳定性 - 连接池、TCP Keep-Alive、断线自动重试,保障长时间会话稳定运行
Related MCP server: GraphJin
🚀 快速开始
安装
npm install -g universal-db-mcpMCP 模式(Claude Desktop)
将以下配置添加到 Claude Desktop 配置文件:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"my-database": {
"command": "npx",
"args": [
"universal-db-mcp",
"--type", "mysql",
"--host", "localhost",
"--port", "3306",
"--user", "root",
"--password", "your_password",
"--database", "your_database"
]
}
}
}重启 Claude Desktop,然后开始提问:
"帮我查看 users 表的结构"
"统计最近 7 天的订单数量"
"找出销量最高的 5 个产品"
HTTP API 模式
# 设置环境变量
export MODE=http
export HTTP_PORT=3000
export API_KEYS=your-secret-key
# 启动服务
npx universal-db-mcp# 测试 API
curl http://localhost:3000/api/healthMCP SSE 模式(Dify 和远程访问)
在 HTTP 模式下运行时,服务器还会通过 SSE(Server-Sent Events)和 Streamable HTTP 暴露 MCP 协议端点。这使得 Dify 等平台可以直接使用 MCP 协议连接。
SSE 端点(传统方式):
GET http://localhost:3000/sse?type=mysql&host=localhost&port=3306&user=root&password=xxx&database=mydbStreamable HTTP 端点(MCP 2025 规范,推荐):
POST http://localhost:3000/mcp
请求头:
X-DB-Type: mysql
X-DB-Host: localhost
X-DB-Port: 3306
X-DB-User: root
X-DB-Password: your_password
X-DB-Database: your_database
请求体:MCP JSON-RPC 请求端点 | 方法 | 说明 |
| GET | 建立 SSE 连接(传统方式) |
| POST | 向 SSE 会话发送消息 |
| POST | Streamable HTTP 端点(推荐) |
| GET | Streamable HTTP 的 SSE 流 |
| DELETE | 关闭会话 |
📊 支持的数据库
数据库 | 类型参数 | 默认端口 | 分类 |
MySQL |
| 3306 | 开源 |
PostgreSQL |
| 5432 | 开源 |
Redis |
| 6379 | NoSQL |
Oracle |
| 1521 | 商业 |
SQL Server |
| 1433 | 商业 |
MongoDB |
| 27017 | NoSQL |
SQLite |
| - | 嵌入式 |
达梦 |
| 5236 | 国产 |
人大金仓 |
| 54321 | 国产 |
华为 GaussDB |
| 5432 | 国产 |
蚂蚁 OceanBase |
| 2881 | 国产 |
TiDB |
| 4000 | 分布式 |
ClickHouse |
| 8123 | OLAP |
阿里云 PolarDB |
| 3306 | 云数据库 |
海量 Vastbase |
| 5432 | 国产 |
瀚高 HighGo |
| 5866 | 国产 |
中兴 GoldenDB |
| 3306 | 国产 |
🏗️ 架构
┌─────────────────────────────────────────────────────────────────────────┐
│ Universal DB MCP │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ 启动模式: │
│ ┌────────────────────────────┬────────────────────────────────────┐ │
│ │ stdio 模式 │ http 模式 │ │
│ │ (npm run start:mcp) │ (npm run start:http) │ │
│ └─────────────┬──────────────┴───────────────┬────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────┐ ┌───────────────────────────────────┐ │
│ │ MCP 协议 │ │ HTTP 服务器 │ │
│ │ (stdio 传输) │ │ │ │
│ │ │ │ ┌─────────────────────────────┐ │ │
│ │ 工具: │ │ │ MCP 协议 │ │ │
│ │ • execute_query │ │ │ (SSE / Streamable HTTP) │ │ │
│ │ • get_schema │ │ │ │ │ │
│ │ • get_table_info │ │ │ 工具:(与 stdio 相同) │ │ │
│ │ • clear_cache │ │ │ • execute_query │ │ │
│ │ • get_enum_values │ │ │ • get_schema │ │ │
│ │ • get_sample_data │ │ │ • get_table_info │ │ │
│ │ • connect_database │ │ │ • clear_cache │ │ │
│ │ • disconnect_database │ │ │ • get_enum_values │ │ │
│ │ • get_connection_status│ │ │ • get_sample_data │ │ │
│ │ │ │ │ • connect_database │ │ │
│ │ 适用:Claude Desktop, │ │ │ • disconnect_database │ │ │
│ │ Cursor 等 │ │ │ • get_connection_status │ │ │
│ └─────────────┬───────────┘ │ │ │ │ │
│ │ │ │ 适用:Dify、远程访问 │ │ │
│ │ │ └──────────────┬──────────────┘ │ │
│ │ │ │ │ │
│ │ │ ┌──────────────┴──────────────┐ │ │
│ │ │ │ REST API │ │ │
│ │ │ │ │ │ │
│ │ │ │ 端点: │ │ │
│ │ │ │ • /api/connect │ │ │
│ │ │ │ • /api/query │ │ │
│ │ │ │ • /api/schema │ │ │
│ │ │ │ • ...(10+ 端点) │ │ │
│ │ │ │ │ │ │
│ │ │ │ 适用:Coze、n8n、自定义 │ │ │
│ │ │ └──────────────┬──────────────┘ │ │
│ │ └─────────────────┼─────────────────┘ │
│ │ │ │
│ └──────────────────┬───────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ 核心业务逻辑层 │ │
│ │ • 查询执行 • Schema 缓存 │ │
│ │ • 安全校验 • 连接管理 │ │
│ └──────────────────────────────────┬───────────────────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ 数据库适配器层 │ │
│ │ MySQL │ PostgreSQL │ Redis │ Oracle │ MongoDB │ SQLite │ ... │ │
│ │ (连接池 + TCP Keep-Alive + 断线自动重试) │ │
│ └──────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘🔒 安全
默认情况下,Universal DB MCP 运行在只读模式,会阻止所有写操作(INSERT、UPDATE、DELETE、DROP 等)。
权限模式
支持细粒度权限控制,可根据需求灵活配置:
模式 | 允许的操作 | 说明 |
| SELECT | 只读,最安全 |
| SELECT, INSERT, UPDATE | 读写但不能删除 |
| 所有操作 | 完全控制(危险!) |
| 自定义组合 | 通过 |
权限类型:
read- SELECT 查询(始终包含)insert- INSERT, REPLACEupdate- UPDATEdelete- DELETE, TRUNCATEddl- CREATE, ALTER, DROP, RENAME
使用示例:
# 只读模式(默认)
npx universal-db-mcp --type mysql ...
# 读写但不能删除
npx universal-db-mcp --type mysql --permission-mode readwrite ...
# 自定义:只允许读和插入
npx universal-db-mcp --type mysql --permissions read,insert ...
# 完全控制(等价于原来的 --danger-allow-write)
npx universal-db-mcp --type mysql --permission-mode full ...不同传输方式的权限配置:
⚠️ 不同传输方式的参数命名风格不同,请注意区分!
传输方式 | 参数位置 | 权限模式参数 | 自定义权限参数 |
STDIO (Claude Desktop) | 命令行 |
|
|
SSE (Dify 等) | URL Query |
|
|
Streamable HTTP | HTTP Header |
|
|
REST API | JSON Body |
|
|
最佳实践:
生产环境永远不要启用写入模式
使用专用的只读数据库账号
通过 VPN 或跳板机连接
定期审计查询日志
🔌 支持的平台
Universal DB MCP 可与任何支持 MCP 协议或 REST API 的平台配合使用。比如,Cursor,CodeBuddy,Claude Code,Dify等主流平台工具。
提示:任何 MCP 兼容客户端都可以通过 stdio(本地)或 SSE/Streamable HTTP(远程)连接。任何 HTTP 客户端都可以使用 REST API。
📚 文档
快速开始
部署
数据库指南
HTTP API
进阶
📄 许可证
本项目采用 MIT 许可证。
📝 更新日志
详见 CHANGELOG.md 了解详细的版本历史。
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityDmaintenanceProvides universal database operations for AI assistants through MCP, supporting 40+ databases including PostgreSQL, MySQL, MongoDB, Redis, and SQLite with built-in introspection tools for schema exploration.Last updated34MIT
- Alicense-qualityAmaintenanceEnables AI assistants to query databases using natural language, with automatic schema discovery and SQL compilation.Last updated5883,132Apache 2.0
- Alicense-qualityDmaintenanceEnables AI assistants to connect to and interact with PostgreSQL, MySQL, SQLite, and MongoDB databases through natural language, supporting schema exploration, query execution, data export, and more.Last updatedMIT
- Alicense-qualityDmaintenanceEnables natural language querying of SQL databases using AI, supporting multiple database types and automatic schema discovery.Last updated1MIT
Related MCP Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
GibsonAI MCP server: manage your databases with natural language
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/the-Rings/universal-db-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server