universal-db-mcp
Why Universal DB MCP?
Imagine asking your AI assistant: "Show me the top 10 customers by order value this month" and getting instant results from your database - no SQL writing required. Universal DB MCP makes this possible by bridging AI assistants with your databases through the Model Context Protocol (MCP) and HTTP API.
You: "What's the average order value for users who signed up in the last 30 days?"
AI: Let me query that for you...
┌─────────────────────────────────────┐
│ Average Order Value: $127.45 │
│ Total New Users: 1,247 │
│ Users with Orders: 892 (71.5%) │
└─────────────────────────────────────┘✨ Features
17 Database Support - MySQL, PostgreSQL, Redis, Oracle, SQL Server, MongoDB, SQLite, and 10 Chinese domestic databases
55+ Platform Integrations - Works with Claude Desktop, Cursor, VS Code, ChatGPT, Dify, and 50+ other platforms
41 MCP Tools - Connection, query, schema, profile, template, governance, sample-data, PII, audit, CSV export/import (full list)
Flexible Architecture - 2 startup modes (stdio/http) with 4 access methods: MCP stdio, MCP SSE, MCP Streamable HTTP, and REST API
Security First - Read-only mode by default prevents accidental data modifications
Intelligent Caching - Schema caching with configurable TTL for blazing-fast performance
50-100× faster
get_table_info- Per-table metadata path for Oracle/DM, skips full schema scanSmart Sample Data -
generate_sample_dataauto-detects PK type: IDENTITY (skip), UUID (uuid v4), INT/NUMBER (MAX+rowIndex+1)Batch Query Optimization - Up to 100x faster schema retrieval for large databases
Schema Enhancement - Table comments, implicit relationship inference for better Text2SQL accuracy
Multi-Schema Support - Automatic discovery of all user schemas (PostgreSQL, SQL Server, Oracle, DM, and more)
Data Migration - SQL backup (
export_backup) + CSV import/export with RFC 4180 serialization, partitioned reads, batched writes (docs)Data Masking - Automatic sensitive data protection (phone, email, ID card, bank card, etc.)
Data Governance - Profile backup/restore (
export_profiles/import_profiles), schema diff, PII masking, audit log (docs)Connection Stability - Connection pooling, TCP Keep-Alive, and automatic reconnection for long-running sessions
Production Observability - Prometheus
/metricsendpoint + MCPget_metricstool + slow-query ring buffer, zero new dependencies (docs)
See GitHub Releases for full changelog, and docs/03-features/ for per-feature detail.
Smart Sample Data (v4.0.3) -
generate_sample_dataauto-detects PK type: IDENTITY (skip), UUID (uuid v4), INT/NUMBER (MAX+rowIndex+1)
Performance Improvements
Operation | Before | After | Improvement |
| 60-90s | 526-866ms | 50-100× |
| 30-60s | 696-852ms | 50-100× |
| 30-60s | ~150ms | 200× |
Schema cache (50 tables) | ~5s | ~200ms | 25× |
Schema cache (500 tables) | ~50s | ~500ms | 100× |
🛠️ Available Tools (41 total)
Connection (4)
Tool | Description |
| 激活保存的 profile + 建立连接 (替换 v4.x 的 connect_database) |
| 保存命名 profile (host/port/user 等 + permissionMode) |
| 断开当前 profile 的连接 (替换 v4.x 的 disconnect_database) |
| Show connection state, schema cache hit rate, last error |
| Prometheus-style counters + histograms + slow-query ring buffer |
Query / Schema (7)
Tool | Description |
| Run SQL with bound |
| Multi-statement SQL / PL block execution (script permission) |
| Single SQL × multiple param sets (1000-row batch limit) |
| Single-table metadata — 50-100× faster than v3.x (per-table SQL path) |
| N sample rows with PII auto-masking |
| Unique values + counts for enum-like columns |
| Invalidate the schema cache |
Data Generation / Templates (5)
Tool | Description |
| Smart sample data insertion — auto-detects IDENTITY PK (skip), UUID PK (uuid v4), INT PK (MAX+sequence); |
| Save parameterized SQL template ( |
| List templates with tag search |
| Fetch one template by id |
| Delete a template |
| Run a template with params (safe substitution) |
Profile Management (6)
Tool | Description |
| Save named connection profile (credentials encrypted at rest) |
| List with role/tag/enabled filters |
| Fetch one profile |
| Switch active connection (works without current DB connection) |
| Toggle profile active state |
| Delete a profile |
| Disconnect a profile without deleting |
| Dump all profiles (passwords REDACTED by default) |
| Restore profiles from YAML/JSON |
Data Governance (6)
Tool | Description |
| Set per-table/per-column PII masking rules |
| View current PII rules |
| Query recorded query history (filters: db, kind, since, until, onlyErrors) |
| Same data via analytics-friendly API |
| Get EXPLAIN plan only (no advice) |
| EXPLAIN + index-tuning hints |
| Static SQL analysis (issues / warnings) |
| List captured EXPLAIN plans by query hash |
| Diff two plans for the same query hash |
SQL File / CSV (4) ← v4.0.5 恢复
Tool | Description |
| Run a |
| Dump schema as SQL DDL to a file |
| Stream single table to CSV with |
| Import CSV back to existing table in batches (APPEND mode, |
Legacy / Removed (v4.0)
❌
use_tool_group— removed (lazy-load removed in v4.0)❌
use_tool_schema— removed (full schemas intools/listnow)
See tools reference for parameter details.
🚀 Quick Start
v5.0.0 新流程(Profile-based)
所有凭据现在通过 create_profile 管理,不再写进 .mcp.json。同一套 DB 凭据可跨多个项目复用,不需要重复输入。
1. 第一次使用 — 保存 profile
// 在 Claude Desktop / Claude Code 里:
create_profile({
name: "my-dev-db", // /^[a-zA-Z0-9_-]+$/
type: "mysql", // oracle / mysql / postgres / redis / dm / ...
config: {
host: "localhost",
port: 3306,
user: "root",
password: "your_password",
database: "your_database",
},
permissionMode: "readwrite", // safe / readwrite / full(默认 readwrite,含 batch)
})profile 存到 ~/.universal-db-mcp/profiles.db(Windows: %USERPROFILE%\.universal-db-mcp\profiles.db),跨项目保留。
旧
save_profile名字仍兼容(别名 →create_profile)。想更新已有 profile,用update_profile。
2. 激活并绑定项目
use_profile({
name: "my-dev-db",
// recordToProject 默认 true — 自动写 <cwd>/.db-profile,下次 MCP 启动自动激活
// recordToProject: false 显式跳过(临时激活不绑项目)
})下次 MCP 启动时,自动读 <cwd>/.db-profile 并激活指定 profile — 无需手动 use_profile。文件名从 v4.x 的 .profile 改为 .db-profile(避免和 shell/IDE 的 .profile 冲突)。旧 .profile 文件还能作为 fallback 读到(迁移期)。
3. 开始查询
"Show me the structure of the users table"
"Count orders from the last 7 days"
"Find the top 5 products by sales"
数据存储
所有持久化数据都放在 ~/.universal-db-mcp/(可用 DB_GLOBAL_DIR 覆盖):
~/.universal-db-mcp/
├── profiles.db # 全局 profile 注册表
├── config.json # 配置标记
├── my-dev-db/ # profile 名作为子目录(per-profile 隔离)
│ ├── history.db # 查询历史(按 profile 隔离)
│ ├── templates.db # SQL 模板
│ └── plans.db # EXPLAIN 历史
└── other-profile/
├── history.db
├── templates.db
└── plans.db多项目工作流
# 项目 A
cd ~/projects/app-a
# MCP 启动自动激活 — 写 <cwd>/.db-profile (recordToProject: true 是默认行为)
use_profile({name: 'my-dev-db'})
# 项目 B(同一 DB)
cd ~/projects/app-b
use_profile({name: 'my-dev-db'})
# 同一 profile,无需重新保存
# 项目 C(不同 DB — staging)
create_profile({name: 'staging-db', type: 'mysql', config: {...}})
use_profile({name: 'staging-db'})MCP Mode 配置(简化版)
.mcp.json 现在只需要安装信息,不需要凭据:
{
"mcpServers": {
"universal-db-mcp": {
"command": "npx",
"args": ["@joyous-coder/universal-db-mcp"]
}
}
}启动后用 create_profile + use_profile 配连接。v4.x .mcp.json env vars (DB_HOST/DB_USER/DB_PASSWORD/DB_TYPE) 会被静默忽略 +一次性 stderr 提示迁移。
HTTP API Mode
# Set environment variables
export MODE=http
export HTTP_PORT=3000
export API_KEYS=your-secret-key
### HTTP API Mode
```bash
# Set environment variables
export MODE=http
export HTTP_PORT=3000
export API_KEYS=your-secret-key
# Start the server
npx @joyous-coder/universal-db-mcp# Test the API
curl http://localhost:3000/api/healthMCP SSE Mode (Dify and Remote Access)
When running in HTTP mode, the server also exposes MCP protocol endpoints via SSE (Server-Sent Events) and Streamable HTTP. This allows platforms like Dify to connect using the MCP protocol directly.
SSE Endpoint (Legacy):
GET http://localhost:3000/sse?type=mysql&host=localhost&port=3306&user=root&password=xxx&database=mydbStreamable HTTP Endpoint (MCP 2025 Spec, Recommended):
POST http://localhost:3000/mcp
Headers:
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
Body: MCP JSON-RPC requestEndpoint | Method | Description |
| GET | Establish SSE connection (legacy) |
| POST | Send message to SSE session |
| POST | Streamable HTTP endpoint (recommended) |
| GET | SSE stream for Streamable HTTP |
| DELETE | Close session |
See Dify Integration Guide for detailed setup instructions.
📊 Supported Databases
Database | Type | Default Port | Category |
MySQL |
| 3306 | Open Source |
PostgreSQL |
| 5432 | Open Source |
Redis |
| 6379 | NoSQL |
Oracle |
| 1521 | Commercial |
SQL Server |
| 1433 | Commercial |
MongoDB |
| 27017 | NoSQL |
SQLite |
| - | Embedded |
Dameng (达梦) |
| 5236 | Chinese |
KingbaseES |
| 54321 | Chinese |
GaussDB |
| 5432 | Chinese (Huawei) |
OceanBase |
| 2881 | Chinese (Ant) |
TiDB |
| 4000 | Distributed |
ClickHouse |
| 8123 | OLAP |
PolarDB |
| 3306 | Cloud (Alibaba) |
Vastbase |
| 5432 | Chinese |
HighGo |
| 5866 | Chinese |
GoldenDB |
| 3306 | Chinese (ZTE) |
🏗️ Architecture
┌─────────────────────────────────────────────────────────────────────────┐
│ Universal DB MCP │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ Startup Modes: │
│ ┌────────────────────────────┬────────────────────────────────────┐ │
│ │ stdio mode │ http mode │ │
│ │ (npm run start:mcp) │ (npm run start:http) │ │
│ └─────────────┬──────────────┴───────────────┬────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────┐ ┌───────────────────────────────────┐ │
│ │ MCP Protocol │ │ HTTP Server │ │
│ │ (stdio transport) │ │ │ │
│ │ │ │ ┌─────────────────────────────┐ │ │
│ │ Tools: │ │ │ MCP Protocol │ │ │
│ │ • execute_query │ │ │ (SSE / Streamable HTTP) │ │ │
│ │ • get_schema │ │ │ │ │ │
│ │ • get_table_info │ │ │ Tools: (same as stdio) │ │ │
│ │ • clear_cache │ │ │ • execute_query │ │ │
│ │ • get_enum_values │ │ │ • get_schema │ │ │
│ │ • get_sample_data │ │ │ • get_table_info │ │ │
│ │ • save_profile │ │ │ • clear_cache │ │ │
│ │ • dissave_profile │ │ │ • get_enum_values │ │ │
│ │ • get_connection_status│ │ │ • get_sample_data │ │ │
│ │ │ │ │ • save_profile │ │ │
│ │ For: Claude Desktop, │ │ │ • dissave_profile │ │ │
│ │ Cursor, etc. │ │ │ • get_connection_status │ │ │
│ └─────────────┬───────────┘ │ │ │ │ │
│ │ │ │ For: Dify, Remote Access │ │ │
│ │ │ └──────────────┬──────────────┘ │ │
│ │ │ │ │ │
│ │ │ ┌──────────────┴──────────────┐ │ │
│ │ │ │ REST API │ │ │
│ │ │ │ │ │ │
│ │ │ │ Endpoints: │ │ │
│ │ │ │ • /api/connect │ │ │
│ │ │ │ • /api/query │ │ │
│ │ │ │ • /api/schema │ │ │
│ │ │ │ • ... (10+ endpoints) │ │ │
│ │ │ │ │ │ │
│ │ │ │ For: Coze, n8n, Custom │ │ │
│ │ │ └──────────────┬──────────────┘ │ │
│ │ └─────────────────┼─────────────────┘ │
│ │ │ │
│ └──────────────────┬───────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ Core Business Logic │ │
│ │ • Query Execution • Schema Caching │ │
│ │ • Safety Validation • Connection Management │ │
│ └──────────────────────────────────┬───────────────────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ Database Adapter Layer │ │
│ │ MySQL │ PostgreSQL │ Redis │ Oracle │ MongoDB │ SQLite │ ... │ │
│ │ (Connection Pool + TCP Keep-Alive + Auto-Retry) │ │
│ └──────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘🔒 Security
By default, Universal DB MCP runs in read-only mode, blocking all write operations (INSERT, UPDATE, DELETE, DROP, etc.).
Permission Modes
Fine-grained permission control is supported for flexible configuration:
Mode | Allowed Operations | Description |
| SELECT | Read-only, safest |
| SELECT, INSERT, UPDATE | Read/write but no delete |
| All operations | Full control (dangerous!) |
| Custom combination | Specify via |
Permission Types:
read- SELECT queries (always included)insert- INSERT, REPLACEupdate- UPDATEdelete- DELETE, TRUNCATEddl- CREATE, ALTER, DROP, RENAME
Usage Examples:
# Read-only mode (default)
npx @joyous-coder/universal-db-mcp --type mysql ...
# Read/write but no delete
npx @joyous-coder/universal-db-mcp --type mysql --permission-mode readwrite ...
# Custom: only read and insert
npx @joyous-coder/universal-db-mcp --type mysql --permissions read,insert ...
# Full control (equivalent to --danger-allow-write)
npx @joyous-coder/universal-db-mcp --type mysql --permission-mode full ...Permission Configuration by Transport:
⚠️ Different transports use different parameter naming conventions!
Transport | Parameter Location | Permission Mode | Custom Permissions |
STDIO (Claude Desktop) | CLI args |
|
|
SSE (Dify, etc.) | URL Query |
|
|
Streamable HTTP | HTTP Header |
|
|
REST API | JSON Body |
|
|
Best Practices:
Never enable write mode in production
Use dedicated read-only database accounts
Connect through VPN or bastion hosts
Regularly audit query logs
🔌 Supported Platforms
Universal DB MCP works with any platform that supports the MCP protocol or REST API. Here's a comprehensive list:
AI-Powered Code Editors & IDEs
Platform | Access Method | Description | Guide |
MCP stdio | AI-powered code editor with built-in MCP support | ||
MCP stdio | Codeium's AI IDE with Cascade agent | ||
MCP stdio / REST API | Via GitHub Copilot agent mode or Cline/Continue extensions | ||
MCP stdio | High-performance open-source code editor | ||
MCP stdio | JetBrains IDE with MCP support (2025.1+) | ||
MCP stdio | JetBrains Python IDE | ||
MCP stdio | JetBrains JavaScript IDE | ||
MCP stdio | Via JetBrains MCP plugin | ||
MCP stdio | Via MCPHub.nvim plugin | ||
MCP stdio | Via mcp.el package |
AI Coding Assistants
Platform | Access Method | Description | Guide |
MCP stdio | Anthropic's agentic coding tool | ||
MCP stdio | Agent mode in VS Code/JetBrains | ||
MCP stdio / REST API | Autonomous coding agent for VS Code | ||
MCP stdio | Open-source AI code assistant | ||
MCP stdio | Fork of Cline for VS Code | ||
MCP stdio | AI coding assistant | ||
MCP stdio | AWS AI coding assistant | ||
MCP stdio | AI software engineer | ||
MCP stdio | Block's AI coding agent | ||
MCP stdio | Google's command-line AI tool |
Desktop AI Chat Applications
Platform | Access Method | Description | Guide |
MCP stdio | Anthropic's official desktop app | ||
MCP SSE/Streamable HTTP | OpenAI's desktop app with MCP connectors | ||
MCP stdio | Multi-model desktop chat app | ||
MCP stdio | Run local LLMs with MCP support | ||
MCP stdio | Open-source ChatGPT alternative | ||
MCP stdio | Desktop AI chat application | ||
MCP stdio | Open-source chat interface | ||
MCP stdio | Desktop AI assistant | ||
MCP stdio | Cross-platform AI chat | ||
MCP stdio | MCP-focused chat UI | ||
MCP stdio | Multi-platform chat app | ||
MCP stdio | macOS app for local LLMs |
Web-Based AI Platforms
Platform | Access Method | Description | Guide |
MCP SSE/Streamable HTTP | Anthropic's web interface | ||
MCP SSE/Streamable HTTP | Via custom connectors | ||
MCP SSE/Streamable HTTP | LLM app development platform | ||
REST API | ByteDance's AI bot platform | ||
REST API / MCP | Workflow automation platform | ||
MCP stdio | Online IDE with AI agent | ||
MCP SSE/Streamable HTTP | No-code AI agent builder |
Agent Frameworks & SDKs
Platform | Access Method | Description | Guide |
MCP stdio | Popular LLM framework | ||
MCP stdio | Hugging Face agent library | ||
MCP SSE/Streamable HTTP | OpenAI's agent framework | ||
MCP SSE/Streamable HTTP | AWS AI agent service | ||
MCP stdio | Google's Agent Development Kit | ||
MCP stdio | Vercel's AI development kit | ||
MCP stdio | Java/Spring AI framework |
CLI Tools & Terminal
Platform | Access Method | Description | Guide |
MCP stdio | Terminal-based coding agent | ||
MCP stdio | AI-powered terminal | ||
MCP stdio | Chat with Ollama via CLI | ||
MCP stdio | CLI chat with LLMs |
Productivity & Automation
Platform | Access Method | Description | Guide |
MCP stdio | macOS productivity launcher | ||
MCP SSE/Streamable HTTP | Workspace with AI integration | ||
MCP stdio | Via MCP Tools plugin | ||
MCP stdio | Home automation platform |
Messaging Platform Integrations
Platform | Access Method | Description | Guide |
MCP stdio / REST API | Via Slack MCP bots | ||
MCP stdio / REST API | Via Discord MCP bots | ||
MCP stdio | Open-source messaging |
Local LLM Runners
Platform | Access Method | Description | Guide |
MCP stdio | Run local LLMs | ||
MCP stdio | Local LLM desktop app | ||
MCP stdio | Offline ChatGPT alternative |
Development & Testing Tools
Platform | Access Method | Description | Guide |
MCP stdio | Official MCP debugging tool | ||
REST API / MCP | API testing platform |
Note: Any MCP-compatible client can connect via stdio (local) or SSE/Streamable HTTP (remote). Any HTTP client can use the REST API.
📚 Documentation
Getting Started
Deployment
Database Guides
ClickHouse (v3.2.9 — 5 protocol bugs fixed)
DM (达梦) (v3.2.8 — backup + sample-data fixes)
MongoDB (v3.2.7 — authSource + multi-arg)
Features
Data Governance — profile backup, schema diff, PII, audit
Data Migration — CSV import/export (v3.3.0) + SQL backup
Multi-Profile — multi-DB routing, schema aggregation
Observability — Prometheus + slow-query ring buffer
HTTP API
Integrations
AI Editors & IDEs: Cursor | VS Code | JetBrains | Windsurf | Zed | Neovim | Emacs
AI Assistants: Claude Desktop | Claude Code | GitHub Copilot | Cline | Continue
AI Platforms: Dify | Coze | n8n | ChatGPT | LangChain
Desktop Apps: Cherry Studio | LM Studio | Jan | Ollama
Tools: MCP Inspector | Postman
📁 View all 55+ integration guides | 中文版本请在对应文档名后加
.zh-CN
Advanced
Security Guide (security section)
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide before submitting a Pull Request.
# Clone the repository
git clone https://github.com/Anarkh-Lee/universal-db-mcp.git
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test📄 License
This project is licensed under the MIT License.
🌟 Star History
If you find this project useful, please consider giving it a star! Your support helps us continue improving Universal DB MCP.
📝 Changelog
See CHANGELOG.md for a detailed version history.
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/joyous-coder/universal-db-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server