此 MCP(模型上下文协议)服务器为 Claude 提供数据库访问能力,支持 SQLite、SQL Server、PostgreSQL 和 MySQL 数据库。
git clone https://github.com/executeautomation/mcp-database-server.git
cd mcp-database-server
npm install
npm run build
有两种方式使用此 MCP 服务器与 Claude 集成:
最简单的方式是全局安装此 MCP 服务器:
npm install -g @executeautomation/database-server
这样就可以直接使用服务器,无需本地构建。
如果你想要修改代码或从本地环境运行:
要与 SQLite 数据库一起使用:
node dist/src/index.js /path/to/your/database.db
要与 SQL Server 数据库一起使用:
node dist/src/index.js --sqlserver --server <server-name> --database <database-name> [--user <username> --password <password>]
必需参数:
--server:SQL Server 主机名或 IP 地址--database:数据库名称可选参数:
--user:用于 SQL Server 身份验证的用户名(如果未提供,则使用 Windows 身份验证)--password:用于 SQL Server 身份验证的密码--port:端口号(默认:1433)要与 PostgreSQL 数据库一起使用:
node dist/src/index.js --postgresql --host <host-name> --database <database-name> [--user <username> --password <password>]
必需参数:
--host:PostgreSQL 主机名或 IP 地址--database:数据库名称可选参数:
--user:用于 PostgreSQL 身份验证的用户名--password:用于 PostgreSQL 身份验证的密码--port:端口号(默认:5432)--ssl:启用 SSL 连接(true/false)--connection-timeout:连接超时时间(以毫秒为单位,默认:30000)要与 MySQL 数据库一起使用:
node dist/src/index.js --mysql --host <host-name> --database <database-name> --port <port> [--user <username> --password <password>]
必需参数:
--host:MySQL 主机名或 IP 地址--database:数据库名称--port:端口号(默认:3306)可选参数:
--user:用于 MySQL 身份验证的用户名--password:用于 MySQL 身份验证的密码--ssl:启用 SSL 连接(true/false 或对象)--connection-timeout:连接超时时间(以毫秒为单位,默认:30000)对于具有 IAM 数据库认证的 Amazon RDS MySQL 实例:
前提条件:
aws configure(使用默认配置文件)AWS_PROFILE=myprofile 环境变量AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 环境变量node dist/src/index.js --mysql --aws-iam-auth --host <rds-endpoint> --database <database-name> --user <aws-username> --aws-region <region>
必需参数:
--host:RDS 终端节点主机名--database:数据库名称--aws-iam-auth:启用 AWS IAM 认证--user:AWS IAM 用户名(也是数据库用户)--aws-region:RDS 实例所在的 AWS 区域注意:对于 AWS IAM 认证,SSL 自动启用
如果你全局安装了包,请使用以下配置 Claude Desktop:
{
"mcpServers": {
"sqlite": {
"command": "npx",
"args": [
"-y",
"@executeautomation/database-server",
"/path/to/your/database.db"
]
},
"sqlserver": {
"command": "npx",
"args": [
"-y",
"@executeautomation/database-server",
"--sqlserver",
"--server", "your-server-name",
"--database", "your-database-name",
"--user", "your-username",
"--password", "your-password"
]
},
"postgresql": {
"command": "npx",
"args": [
"-y",
"@executeautomation/database-server",
"--postgresql",
"--host", "your-host-name",
"--database", "your-database-name",
"--user", "your-username",
"--password", "your-password"
]
},
"mysql": {
"command": "npx",
"args": [
"-y",
"@executeautomation/database-server",
"--mysql",
"--host", "your-host-name",
"--database", "your-database-name",
"--port", "3306",
"--user", "your-username",
"--password", "your-password"
]
},
"mysql-aws": {
"command": "npx",
"args": [
"-y",
"@executeautomation/database-server",
"--mysql",
"--aws-iam-auth",
"--host", "your-rds-endpoint.region.rds.amazonaws.com",
"--database", "your-database-name",
"--user", "your-aws-username",
"--aws-region", "us-east-1"
]
}
}
}
对于本地开发,请配置 Claude Desktop 使用你本地构建的版本:
{
"mcpServers": {
"sqlite": {
"command": "node",
"args": [
"/absolute/path/to/mcp-database-server/dist/src/index.js",
"/path/to/your/database.db"
]
},
"sqlserver": {
"command": "node",
"args": [
"/absolute/path/to/mcp-database-server/dist/src/index.js",
"--sqlserver",
"--server", "your-server-name",
"--database", "your-database-name",
"--user", "your-username",
"--password", "your-password"
]
},
"postgresql": {
"command": "node",
"args": [
"/absolute/path/to/mcp-database-server/dist/src/index.js",
"--postgresql",
"--host", "your-host-name",
"--database", "your-database-name",
"--user", "your-username",
"--password", "your-password"
]
},
"mysql": {
"command": "node",
"args": [
"/absolute/path/to/mcp-database-server/dist/src/index.js",
"--mysql",
"--host", "your-host-name",
"--database", "your-database-name",
"--port", "3306",
"--user", "your-username",
"--password", "your-password"
]
},
"mysql-aws": {
"command": "node",
"args": [
"/absolute/path/to/mcp-database-server/dist/src/index.js",
"--mysql",
"--aws-iam-auth",
"--host", "your-rds-endpoint.region.rds.amazonaws.com",
"--database", "your-database-name",
"--user", "your-aws-username",
"--aws-region", "us-east-1"
]
}
}
}
Claude Desktop 的配置文件通常位于:
~/Library/Application Support/Claude/claude_desktop_config.json~/.config/Claude/claude_desktop_config.jsonMCP 数据库服务器提供了以下工具,Claude 可以使用这些工具:
| 工具 | 描述 | 必需参数 |
|---|---|---|
read_query | 执行 SELECT 查询以读取数据 | query:SQL SELECT 语句 |
write_query | 执行 INSERT、UPDATE 或 DELETE 查询 | query:SQL 修改语句 |
create_table | 在数据库中创建新表 | query:CREATE TABLE 语句 |
alter_table | 修改现有表模式 | query:ALTER TABLE 语句 |
drop_table | 从数据库中删除表 | table_name:表名<br>confirm:安全标志(必须为 true) |
list_tables | 获取所有表的列表 | 无 |
describe_table | 查看表的架构信息 | table_name:表名 |
export_query | 将查询结果导出为 CSV/JSON | query:SQL SELECT 语句<br>format:"csv" 或 "json" |
append_insight | 向备忘录添加业务洞察 | insight:洞察文本 |
list_insights | 列出所有业务洞察 | 无 |
有关如何使用这些工具与 Claude 的实际示例,请参阅 使用示例。
要在开发模式下运行服务器:
npm run dev
在开发过程中监视更改:
npm run watch
MIT