DB MCP Server
Enables Claude Code to execute read-only queries and DML operations on Oracle and PostgreSQL databases, and to list or describe database tables.
README
DB MCP Server
English | 中文
一个基于 TypeScript 实现的 Model Context Protocol 服务,让 Claude Code 可以直接查询 Oracle、PostgreSQL 和 MySQL 数据库。
支持的数据库
- Oracle(通过
oracledb驱动,默认 thin 模式) - PostgreSQL(通过
pg驱动) - MySQL(通过
mysql2驱动)
提供的工具
list_tables:列出指定 schema / 数据库下的表describe_table:查看表结构、字段类型和约束execute_query:执行只读的SELECT查询execute_dml:执行INSERT/UPDATE/DELETE/DDL语句
每个工具都支持可选参数 dataSource("oracle"、"postgres" 或 "mysql")。如果只配置了一种数据库,会默认使用该数据库。
环境要求
- Node.js 20+
- 至少配置一个数据库的环境变量
安装
本项目强制使用 pnpm 管理依赖。
cd C:\Users\ASUS\db-mcp-server
pnpm install
pnpm run build
如果你用 npm install 或 yarn install,preinstall 脚本会报错并阻止安装。
配置
1. 环境变量 / .env 文件
支持两种配置方式,优先级如下:
- 系统环境变量(最高优先级)
- 项目根目录下的
.env文件
示例 .env:
# Oracle 配置
ORACLE_USER=your_user
ORACLE_PASSWORD=your_password
ORACLE_DSN=localhost:1521/ORCLPDB1
# PostgreSQL 配置
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_DATABASE=your_db
# MySQL 配置
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_user
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_db
也可以在启动 Claude Code 前用 PowerShell 设置:
$env:ORACLE_USER = "your_user"
$env:ORACLE_PASSWORD = "your_password"
$env:ORACLE_DSN = "localhost:1521/ORCLPDB1"
$env:POSTGRES_HOST = "localhost"
$env:POSTGRES_PORT = "5432"
$env:POSTGRES_USER = "your_user"
$env:POSTGRES_PASSWORD = "your_password"
$env:POSTGRES_DATABASE = "your_db"
$env:MYSQL_HOST = "localhost"
$env:MYSQL_PORT = "3306"
$env:MYSQL_USER = "your_user"
$env:MYSQL_PASSWORD = "your_password"
$env:MYSQL_DATABASE = "your_db"
claude
2. 在 Claude Code 中注册 MCP Server
在 C:\Users\ASUS\.mcp.json 中添加:
{
"mcpServers": {
"db-mcp-server": {
"command": "cmd",
"args": [
"/c",
"cd /d C:\\Users\\ASUS\\db-mcp-server && node dist\\index.js"
]
}
}
}
在 C:\Users\ASUS\.claude\settings.local.json 中启用:
{
"enabledMcpjsonServers": [
"db-mcp-server"
]
}
修改环境变量、.mcp.json 或重新构建后,请重启 Claude Code 使配置生效。
构建与运行
pnpm run build
node dist/index.js
开发调试
无需编译,直接使用 tsx 运行:
pnpm tsx src/index.ts
Oracle Thick 模式
如果数据库需要使用 thick 模式,请设置:
$env:ORACLE_THICK_MODE = "1"
$env:ORACLE_LIB_DIR = "C:\Users\ASUS\Desktop\instantclient_19_28"
验证
重启 Claude Code 后,可以尝试:
- "列出 Oracle 的表"
- "列出 PostgreSQL 的表"
- "列出 MySQL 的表"
- "描述 postgres 中的 users 表"
- "描述 mysql 中的 users 表"
- "在 oracle 上执行 SELECT * FROM employees"
- "在 mysql 上执行 SELECT * FROM users"
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.
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.
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.
E2B
Using MCP to run code via e2b.
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.