loading…
Search for a command to run...
loading…
A postgresql mcp that you can run DQL SQL via it
A postgresql mcp that you can run DQL SQL via it
一个基于 Model Context Protocol (MCP) 的 PostgreSQL 数据库服务器,允许 AI 助手通过 MCP 协议直接查询 PostgreSQL 数据库。
asyncpg 实现异步连接池,提高性能git clone https://github.com/zzhRooT1998/postgresql-mcp-server.git
cd postgresql-mcp-server
pip install -r requirements.txt
asyncpg>=0.29.0 - PostgreSQL 异步数据库驱动mcp>=1.26.0,<2.0.0 - Model Context Protocol SDKpython postgresql-mcp.py \
--user your_username \
--password your_password \
--database your_database \
--host localhost \
--port 5432
export MCPUSER=your_username
export MCPPASSWORD=your_password
export MCPDATABASE=your_database
export MCPHOST=localhost
export MCPPORT=5432
python postgresql-mcp.py
注意:命令行参数优先级高于环境变量。
在 Cursor 的设置中添加以下 MCP 服务器配置:
{
"mcpServers": {
"postgresql-mcp-server": {
"command": "python",
"args": [
"postgresql-mcp.py",
"--user", "your_username",
"--password", "your_password",
"--database", "your_database",
"--host", "localhost",
"--port", "5432"
],
"cwd": "/path/to/postgresql-mcp-server"
}
}
}
{
"mcpServers": {
"postgresql-mcp-server": {
"command": "python",
"args": [
"postgresql-mcp.py",
"--user", "your_username",
"--password", "your_password",
"--database", "your_database",
"--host", "localhost",
"--port", "5432"
],
"cwd": "D:\\pyApp\\postgresql-mcp-server"
}
}
}
在发布到 Smithery/Glama 之前,请确保完成以下步骤:
创建 GitHub Release
https://github.com/zzhRooT1998/postgresql-mcp-serverv1.0.0)并填写发布说明确保所有必需文件已提交
LICENSE - MIT 许可证文件glama.json - Glama 元数据文件Dockerfile - Docker 配置文件(用于服务器检查)smithery.yaml - Smithery 配置npx @smithery/cli publish --name @zzh/postgresql-mcp-server --transport stdio
zzhRooT1998/postgresql-mcp-server发布后,其他用户可以通过 Smithery 目录一键安装你的 MCP 服务器。
query执行任意 SQL 查询,返回行数据的字符串列表。
参数:
sql (string): 要执行的 SQL 查询语句示例:
SELECT * FROM device_instance LIMIT 10;
返回:
| 参数 | 环境变量 | 命令行参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|---|
| 用户名 | MCPUSER |
--user |
✅ | - | PostgreSQL 用户名 |
| 密码 | MCPPASSWORD |
--password |
✅ | - | PostgreSQL 密码 |
| 数据库名 | MCPDATABASE |
--database |
✅ | - | 要连接的数据库名 |
| 主机地址 | MCPHOST |
--host |
✅ | - | PostgreSQL 主机地址 |
| 端口 | MCPPORT |
--port |
❌ | 5432 |
PostgreSQL 端口号 |
如果未提供数据库凭据(MCPUSER 和 MCPPASSWORD),服务器将进入扫描模式,返回 None 配置。这允许 Smithery 等工具在发布前扫描服务器元数据,而无需实际连接数据库。
postgresql-mcp-server/
├── postgresql-mcp.py # 主程序文件
├── requirements.txt # Python 依赖
├── smithery.yaml # Smithery 发布配置
├── glama.json # Glama/Smithery 元数据文件
├── Dockerfile # Docker 镜像配置(用于服务器检查)
├── LICENSE # MIT 许可证
└── README.md # 本文件
asyncpg.Pool 实现连接池,在 MCP 进程生命周期内复用DB_CONFIG本项目采用 MIT 许可证。
欢迎提交 Issue 和 Pull Request!
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"postgresql-mcp-server2": {
"command": "npx",
"args": []
}
}
}