| name | universal-db-mcp-connector |
| description | Connect AI assistants to 17+ databases (MySQL, PostgreSQL, MongoDB, Oracle, etc.) via MCP protocol using natural language queries |
| triggers | ["set up database connection with MCP","query database with natural language","configure universal db mcp for Claude","connect AI to MySQL/PostgreSQL database","use MCP protocol for database access","integrate database with Cursor/Claude Desktop","setup HTTP API mode for database queries","configure multi-database MCP server"] |
Universal DB MCP Connector
Skill by ara.so — MCP Skills collection.
Universal DB MCP is a connector implementing the Model Context Protocol (MCP) that enables AI assistants to query and analyze databases using natural language. It supports 17 database types including MySQL, PostgreSQL, Oracle, MongoDB, Redis, and Chinese databases like Dameng, KingbaseES, and GaussDB. Works with 50+ platforms including Claude Desktop, Cursor, Windsurf, VS Code, ChatGPT, and Dify.
Architecture Overview
The connector operates in two modes:
- stdio mode - Direct MCP protocol via stdio transport (for Claude Desktop, Cursor)
- http mode - HTTP server exposing MCP via SSE/Streamable HTTP + REST API (for Dify, remote access)
Both modes provide the same MCP tools for database operations.
Installation
Global Installation
npm install -g universal-db-mcp
Project-Local Installation
npm install universal-db-mcp
From Source
git clone https://github.com/Anarkh-Lee/universal-db-mcp.git
cd universal-db-mcp
npm install
npm run build
Supported Databases
| Database | Type Value | Default Port |
|---|
| MySQL | mysql | 3306 |
| PostgreSQL | postgres | 5432 |
| MongoDB | mongodb | 27017 |
| Redis | redis | 6379 |
| Oracle | oracle | 1521 |
| SQL Server | sqlserver | 1433 |
| SQLite | sqlite | N/A |
| Dameng | dm | 5236 |
| KingbaseES | kingbase | 54321 |
| GaussDB | gaussdb | 5432 |
| OceanBase | oceanbase | 2881 |
| TiDB | tidb | 4000 |
| ClickHouse | clickhouse | 8123 |
| PolarDB | polardb | 3306 |
| Vastbase | vastbase | 5432 |
| HighGo | highgo | 5866 |
| GoldenDB | goldendb | 3306 |
Configuration for Claude Desktop
macOS
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"production-mysql": {
"command": "npx",
"args": [
"universal-db-mcp",
"--type", "mysql",
"--host", "localhost",
"--port", "3306",
"--user", "root",
"--password", "${DB_PASSWORD}",
"--database", "myapp",
"--readonly"
]
},
"analytics-postgres": {
"command": "npx",
"args": [
"universal-db-mcp",
Windows
Edit %APPDATA%\Claude\claude_desktop_config.json with the same structure.
Common CLI Arguments
--type <database-type>
--host <hostname>
--port <port>
--user <username>
--password <password>
--database <db-name>
--schema <schema-name>
--readonly
--cache-ttl <seconds>
--mask-sensitive-data
--connection-timeout <ms>
--pool-size <number>
Configuration for Cursor / VS Code
Edit .cursor/config.json or .vscode/settings.json:
{
"mcp.servers": {
"database": {
"command": "npx",
"args": [
"universal-db-mcp",
"--type", "mysql",
"--host", "localhost",
"--user", "root",
"--password", "${DB_PASSWORD}",
"--database", "myapp"
]
}
}
}
HTTP API Mode
Starting the Server
export MODE=http
export HTTP_PORT=3000
export API_KEYS=secret-key-1,secret-key-2
export ENABLE_CORS=true
npx universal-db-mcp
Or with a config file:
export default {
mode: 'http',
http: {
port: 3000,
apiKeys: ['secret-key-1', 'secret-key-2'],
cors: true,
rateLimit: {
windowMs: 60000,
maxRequests: 100
}
}
};
npx universal-db-mcp --config config.ts
MCP over SSE (Legacy)
Connect via Server-Sent Events:
curl -N "http://localhost:3000/sse?type=mysql&host=localhost&port=3306&user=root&password=mypass&database=mydb" \
-H "Authorization: Bearer secret-key-1"
curl -X POST http://localhost:3000/sse/message \
-H "Authorization: Bearer secret-key-1" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "execute_query",
"arguments": {
"query": "SELECT * FROM users LIMIT 10"
}
},
"id": 1
}'
MCP over Streamable HTTP (Recommended)
curl -X POST http://localhost:3000/mcp \
-H "Authorization: Bearer secret-key-1" \
-H "Content-Type: application/json" \
-H "X-DB-Type: mysql" \
-H "X-DB-Host: localhost" \
-H "X-DB-Port: 3306" \
-H "X-DB-User: root" \
-H "X-DB-Password: mypass" \
-H "X-DB-Database: mydb" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "execute_query",
"arguments": {
"query": "SELECT COUNT(*) as total FROM orders WHERE created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)"
}
},
"id": 1
}'
REST API Endpoints
curl http://localhost:3000/api/health
curl -X POST http://localhost:3000/api/connect \
-H "Authorization: Bearer secret-key-1" \
-H "Content-Type: application/json" \
-d '{
"type": "mysql",
"host": "localhost",
"port": 3306,
"user": "root",
"password": "mypass",
"database": "mydb"
}'
curl -X POST http://localhost:3000/api/query \
-H "Authorization: Bearer secret-key-1" \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT * FROM products WHERE price > 100 ORDER BY price DESC LIMIT 10"
}'
curl -X GET http://localhost:3000/api/schema \
-H "Authorization: Bearer secret-key-1"
curl -X POST http://localhost:3000/api/table \
-H "Authorization: Bearer secret-key-1" \
-H "Content-Type: application/json" \
-d '{
"tableName": "users"
}'
curl -X POST http://localhost:3000/api/sample \
-H "Authorization: Bearer secret-key-1" \
-H "Content-Type: application/json" \
-d '{
"tableName": "orders",
"limit": 5
}'
curl -X POST http://localhost:3000/api/cache/clear \
-H "Authorization: Bearer secret-key-1"
curl -X GET http://localhost:3000/api/status \
-H "Authorization: Bearer secret-key-1"
curl -X POST http://localhost:3000/api/disconnect \
-H "Authorization: Bearer secret-key-1"
MCP Tools Available
execute_query
Execute SQL queries (SELECT only in readonly mode).
{
"name": "execute_query",
"arguments": {
"query": "SELECT u.name, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id HAVING order_count > 5"
}
}
get_schema
Get complete database schema with table relationships.
{
"name": "get_schema",
"arguments": {}
}
get_table_info
Get detailed information about a specific table.
{
"name": "get_table_info",
"arguments": {
"tableName": "orders"
}
}
get_sample_data
Get sample rows from a table.
{
"name": "get_sample_data",
"arguments": {
"tableName": "products",
"limit": 10
}
}
get_enum_values
Get all possible values for ENUM columns (MySQL).
{
"name": "get_enum_values",
"arguments": {
"tableName": "users",
"columnName": "status"
}
}
clear_cache
Clear the schema cache to force refresh.
{
"name": "clear_cache",
"arguments": {}
}
connect_database
Dynamically connect to a different database.
{
"name": "connect_database",
"arguments": {
"type": "postgres",
"host": "analytics.example.com",
"port": 5432,
"user": "analyst",
"password": "secure-password",
"database": "analytics"
}
}
disconnect_database
Disconnect from current database.
{
"name": "disconnect_database",
"arguments": {}
}
get_connection_status
Check current connection status.
{
"name": "get_connection_status",
"arguments": {}
}
Common Usage Patterns
Natural Language Queries in Claude
Once configured, ask Claude questions like:
- "Show me the structure of the users table"
- "How many orders were placed in the last 7 days?"
- "What are the top 10 products by revenue this month?"
- "Find all users who haven't placed an order in 90 days"
- "Show me the relationship between users and orders tables"
Claude will automatically:
- Use
get_schema to understand database structure
- Generate appropriate SQL via
execute_query
- Format and explain results
Programmatic Access (TypeScript)
import { MCPClient } from 'universal-db-mcp/client';
const client = new MCPClient({
serverUrl: 'http://localhost:3000/mcp',
apiKey: process.env.API_KEY
});
await client.callTool('connect_database', {
type: 'mysql',
host: 'localhost',
user: 'root',
password: process.env.DB_PASSWORD,
database: 'myapp'
});
const schema = await client.callTool('get_schema', {});
const results = await client.callTool('execute_query', {
query: 'SELECT * FROM users WHERE created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)'
});
console.log(results);
Multi-Database Setup
Configure multiple databases in Claude Desktop:
{
"mcpServers": {
"production-db": {
"command": "npx",
"args": [
"universal-db-mcp",
"--type", "mysql",
"--host", "prod.example.com",
"--user", "readonly",
"--password", "${PROD_DB_PASSWORD}",
"--database", "production",
"--readonly"
]
},
"analytics-db": {
"command": "npx",
"args": [
"universal-db-mcp",
"--type", "postgres",
Dify Integration
In Dify, configure MCP tool:
- Go to Tools → Add Tool → MCP
- Set endpoint:
http://localhost:3000/mcp
- Add headers:
Authorization: Bearer your-api-key
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
Data Masking Example
npx universal-db-mcp \
--type mysql \
--host localhost \
--user root \
--password "${DB_PASSWORD}" \
--database myapp \
--mask-sensitive-data
Automatically masks:
- Phone numbers →
138****5678
- Emails →
user***@example.com
- ID cards →
110***********1234
- Bank cards →
6222****5678
Performance Optimization
const args = [
'universal-db-mcp',
'--type', 'postgres',
'--host', 'db.example.com',
'--user', 'app',
'--password', process.env.DB_PASSWORD,
'--database', 'production',
'--cache-ttl', '600',
'--pool-size', '20',
'--connection-timeout', '5000'
];
Troubleshooting
Connection Issues
Problem: "Connection timeout" or "Cannot connect to database"
Solution:
npx universal-db-mcp \
--type mysql \
--host localhost \
--user root \
--password "test" \
--database test \
--connection-timeout 15000
telnet db.example.com 3306
mysql -h localhost -u root -p
Schema Not Loading
Problem: Schema appears empty or incomplete
Solution:
curl -X POST http://localhost:3000/api/cache/clear \
-H "Authorization: Bearer ${API_KEY}"
--cache-ttl 0
SHOW GRANTS FOR 'username'@'host';
Read-Only Mode Issues
Problem: "Query not allowed in read-only mode"
Solution:
npx universal-db-mcp \
--type mysql \
--host localhost \
--user admin \
--password "${DB_PASSWORD}" \
--database myapp
SSL/TLS Connection
Problem: "SSL connection required"
Solution:
npx universal-db-mcp \
--type mysql \
--host secure.example.com \
--user root \
--password "${DB_PASSWORD}" \
--database myapp \
--ssl-ca /path/to/ca.pem \
--ssl-cert /path/to/client-cert.pem \
--ssl-key /path/to/client-key.pem
npx universal-db-mcp \
--type postgres \
--host secure.example.com \
--user postgres \
--password "${DB_PASSWORD}" \
--database myapp \
--ssl-mode require
Large Result Sets
Problem: Queries timing out or returning too much data
Solution:
SELECT * FROM large_table LIMIT 100;
SELECT * FROM orders
ORDER BY created_at DESC
LIMIT 100 OFFSET 0;
SELECT COUNT(*), AVG(price), MAX(price)
FROM products
WHERE category = 'electronics';
Claude Desktop Not Detecting Server
Problem: MCP server doesn't appear in Claude Desktop
Solution:
- Verify JSON syntax in config file
- Restart Claude Desktop completely
- Check logs:
tail -f ~/Library/Logs/Claude/mcp*.log
type %APPDATA%\Claude\logs\mcp*.log
- Test command manually:
npx universal-db-mcp --type mysql --host localhost --user root --password test --database test
Environment Variables Not Working
Problem: Password/credentials not being read from environment
Solution:
"--password", "${DB_PASSWORD}"
export DB_PASSWORD="mypassword"
"--password", "mypassword"
echo "DB_PASSWORD=mypassword" > ~/.claude/.env
Security Best Practices
- Always use readonly mode in production:
--readonly
- Use environment variables for credentials: Never hardcode passwords
- Enable API keys in HTTP mode:
export API_KEYS=strong-secret-key
- Restrict network access: Firewall rules, VPN, SSH tunnels
- Enable data masking:
--mask-sensitive-data
- Use least-privilege database users: Grant only SELECT permissions
- Monitor query logs: Track what queries are being executed
- Set connection limits:
--pool-size to prevent resource exhaustion
Advanced Configuration
SSH Tunnel for Remote Databases
ssh -L 3307:localhost:3306 user@remote-server.com
npx universal-db-mcp \
--type mysql \
--host localhost \
--port 3307 \
--user root \
--password "${DB_PASSWORD}" \
--database production
Docker Deployment
FROM node:20-alpine
WORKDIR /app
RUN npm install -g universal-db-mcp
ENV MODE=http
ENV HTTP_PORT=3000
ENV API_KEYS=changeme
EXPOSE 3000
CMD ["npx", "universal-db-mcp"]
docker build -t universal-db-mcp .
docker run -d \
-p 3000:3000 \
-e API_KEYS="${API_KEY}" \
-e MODE=http \
universal-db-mcp
Kubernetes Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: universal-db-mcp
spec:
replicas: 2
selector:
matchLabels:
app: universal-db-mcp
template:
metadata:
labels:
app: universal-db-mcp
spec:
containers:
- name: mcp
image: universal-db-mcp:latest
ports:
- containerPort: 3000
env:
- name: MODE
value: "http"
- name: HTTP_PORT
value: "3000"
- name: API_KEYS
valueFrom:
secretKeyRef:
name: mcp-secrets
key: api-keys
---
apiVersion: v1
kind: Service
This skill enables AI coding agents to help developers integrate universal-db-mcp with their databases and AI tools, supporting natural language database queries across 17+ database types and 50+ platforms.