DB MCP Server
Enables executing SQL queries, schema introspection, and data management for PostgreSQL and MySQL databases via natural language, supporting local, SSH, and AWS RDS connections.
README
DB MCP Server
A Model Context Protocol (MCP) server for database operations. Execute queries, introspect schemas, and manage data for PostgreSQL and MySQL databases. Works with local databases, SSH tunnels, AWS RDS, RDS Proxy, and any compatible database.
Features
- db_list_instances - List RDS database instances (requires AWS credentials)
- db_test_connection - Test database connectivity and get version info
- db_execute_query - Execute read-only SQL queries (SELECT, SHOW, DESCRIBE, EXPLAIN)
- db_execute_write - Execute write queries (INSERT/UPDATE only, DELETE blocked)
- db_get_schema - Get full database schema with tables, views, and columns
- db_get_tables - List tables and views with filtering options
- db_get_columns - Get column details for a specific table
- db_sample_data - Get sample rows from a table
Installation
Using npx (Recommended)
No installation required. Add directly to your config:
Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql"
}
}
}
}
Claude Code (~/.claude/settings.json):
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql"
}
}
}
}
Manual Installation
# Clone the repository
git clone https://github.com/nikhilchintawar/db-mcp.git
cd db-mcp
# Install dependencies
npm install
# Build
npm run build
Then add to your config:
{
"mcpServers": {
"db": {
"command": "node",
"args": ["/absolute/path/to/db-mcp/build/index.js"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql"
}
}
}
}
Configuration Examples
Local Database
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql",
"DB_SSL": "false"
}
}
}
}
SSH Tunnel
First, establish your SSH tunnel:
ssh -L 5432:rds-endpoint.amazonaws.com:5432 bastion-host
Then configure:
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "admin",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql"
}
}
}
}
AWS RDS / RDS Proxy
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"DB_HOST": "my-proxy.proxy-xxxx.us-east-1.rds.amazonaws.com",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "admin",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql"
}
}
}
}
AWS RDS with Temporary Credentials (Read Replica)
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"AWS_REGION": "eu-west-1",
"AWS_ACCESS_KEY_ID": "your-access-key",
"AWS_SECRET_ACCESS_KEY": "your-secret-key",
"AWS_SESSION_TOKEN": "your-session-token",
"DB_HOST": "my-proxy-readonly.proxy-xxxx.eu-west-1.rds.amazonaws.com",
"DB_PORT": "5432",
"DB_NAME": "mydb",
"DB_USER": "admin",
"DB_PASSWORD": "password",
"DB_ENGINE": "postgresql",
"DB_IS_READ_REPLICA": "true",
"DB_WRITE_MODE": "disabled"
}
}
}
}
AWS Secrets Manager
{
"mcpServers": {
"db": {
"command": "npx",
"args": ["-y", "github:nikhilchintawar/db-mcp"],
"env": {
"AWS_REGION": "us-east-1",
"AWS_PROFILE": "your-profile",
"DB_SECRET_ARN": "arn:aws:secretsmanager:us-east-1:123456789012:secret:mydb-AbCdEf"
}
}
}
}
Configuration
Config File Locations
- Claude Desktop (macOS):
~/Library/Application Support/Claude/claude_desktop_config.json - Claude Desktop (Windows):
%APPDATA%\Claude\claude_desktop_config.json - Claude Code:
~/.claude/settings.json
Environment Variables
| Variable | Required | Description |
|---|---|---|
DB_HOST |
Yes* | Database hostname |
DB_PORT |
No | Database port (default: 5432 for PostgreSQL, 3306 for MySQL) |
DB_NAME |
Yes* | Database name |
DB_USER |
Yes* | Database username |
DB_PASSWORD |
Yes* | Database password |
DB_ENGINE |
Yes* | postgresql or mysql |
DB_SSL |
No | Enable SSL (default: true) |
DB_SECRET_ARN |
No | AWS Secrets Manager ARN (alternative to direct credentials) |
DB_WRITE_MODE |
No | disabled (default), enabled, or auto |
DB_IS_READ_REPLICA |
No | Set to true to block writes |
DB_DEFAULT_LIMIT |
No | Default query row limit (default: 1000) |
DB_DEFAULT_TIMEOUT |
No | Default query timeout in ms (default: 30000) |
*Required unless using DB_SECRET_ARN
AWS Configuration (Optional)
AWS credentials are only needed if using:
DB_SECRET_ARN(Secrets Manager)db_list_instancestool (RDS API)
| Variable | Description |
|---|---|
AWS_REGION |
AWS region (required for AWS features) |
AWS_PROFILE |
AWS credentials profile |
AWS_ACCESS_KEY_ID |
AWS access key |
AWS_SECRET_ACCESS_KEY |
AWS secret key |
AWS_SESSION_TOKEN |
Session token (for temporary credentials) |
Usage Examples
Once configured, you can use natural language to interact with your database:
- "Show me the database schema"
- "List all tables"
- "Get sample data from the users table"
- "Run a query to find all orders from last week"
- "Insert a new record into the settings table"
- "Show me the columns in the products table"
Available Tools
db_list_instances
List RDS database instances (requires AWS credentials).
| Parameter | Required | Description |
|---|---|---|
identifier |
No | Filter by instance identifier |
engine |
No | Filter by engine (postgres, mysql) |
db_test_connection
Test database connection and return status, latency, and version.
| Parameter | Required | Description |
|---|---|---|
| (none) | - | Uses configured connection |
db_execute_query
Execute read-only SQL queries.
| Parameter | Required | Description |
|---|---|---|
sql |
Yes | SELECT, SHOW, DESCRIBE, or EXPLAIN query |
limit |
No | Max rows (default: 1000, max: 10000) |
timeout |
No | Query timeout in ms (default: 30000) |
db_execute_write
Execute write operations (INSERT/UPDATE only).
| Parameter | Required | Description |
|---|---|---|
sql |
Yes | INSERT or UPDATE query |
timeout |
No | Query timeout in ms (default: 30000) |
Note: DELETE, DROP, TRUNCATE, and ALTER are blocked. Fails gracefully on read replicas.
db_get_schema
Get full database schema including tables, views, and columns.
| Parameter | Required | Description |
|---|---|---|
schemaName |
No | Filter by schema (e.g., "public") |
db_get_tables
List tables and views.
| Parameter | Required | Description |
|---|---|---|
schemaName |
No | Filter by schema |
type |
No | table, view, or all (default) |
db_get_columns
Get column details for a specific table.
| Parameter | Required | Description |
|---|---|---|
table |
Yes | Table name |
schemaName |
No | Schema name |
db_sample_data
Get sample rows from a table.
| Parameter | Required | Description |
|---|---|---|
table |
Yes | Table name |
schemaName |
No | Schema name |
limit |
No | Number of rows (default: 10, max: 100) |
Write Protection
The server includes multiple safety mechanisms:
| Mode | Behavior |
|---|---|
disabled (default) |
Blocks all write operations |
enabled |
Allows INSERT/UPDATE on any instance |
auto |
Allows INSERT/UPDATE except on read replicas |
Always blocked: DELETE, DROP, TRUNCATE, ALTER, CREATE, GRANT, REVOKE
Read replica detection works via:
DB_IS_READ_REPLICA=trueenvironment variable- Automatic detection via RDS API (requires
DB_RDS_INSTANCE_IDENTIFIERand AWS credentials)
Development
# Watch mode for development
npm run dev
# Build for production
npm run build
# Test with MCP Inspector
npx @modelcontextprotocol/inspector node build/index.js
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。