使用说明
PostgreSQL和Vertica MCP服务器
专业人员 模型上下文协议(MCP) 服务器提供##🧩 项目结构
mcp-postgres-server/
├── postgres_main.py # PostgreSQL server entry point
├── vertica_main.py # Vertica server entry point
├── config.py # Configuration and logging
├── servers/
│ ├── postgres_server.py # PostgreSQL MCP server implementation
│ └── vertica_server.py # Vertica MCP server implementation
├── run_postgres_mcp.sh / run_postgres_mcp.bat # PostgreSQL wrapper scripts
├── run_vertica_mcp.sh / run_vertica_mcp.bat # Vertica wrapper scripts
├── setup_mcp.sh # Setup and testing script
├── test_connection.py # PostgreSQL connection test
├── test_vertica_connection.py # Vertica connection test
├── client_json_config_example/ # Editor config templates for both servers
├── .env.example # Environment template
└── README.md # This file
```se access from AI tools like Claude Desktop and Zed Editor.
**Supports:** PostgreSQL and Vertica databases
---
## 🚀 Features
- **Dual Database Support:** PostgreSQL and Vertica database access
- **Direct Database Access:** Securely run SQL queries from AI assistants
- **Easy Integration:** Works out-of-the-box with Claude Desktop and Zed Editor
- **Cross-Platform:** Supports Linux, macOS, and Windows
- **Automatic Lifecycle:** Server starts/stops automatically with your editor
- **Safe & Audited:** Parameterized queries, error handling, and logging
---
## ⚡ Quick Start
### 1. Prerequisites
- Python 3.13+
- PostgreSQL or Vertica database (or both)
- [`uv`](https://docs.astral.sh/uv/) package manager
### 2. Installation
```bash
git clone https://github.com/Nayab-zak/mcp-postgres-server.git
cd mcp-postgres-server
uv sync
cp .env.example .env # Edit .env with your DB details
3.配置
编辑 .env 使用您的数据库连接字符串:
对于PostgreSQL:
DB_URL=postgresql://username:password@localhost:5432/database_name
对于Vertica:
VERTICA_HOST=localhost
VERTICA_PORT=5433
VERTICA_DB=VMart
VERTICA_USER=dbadmin
VERTICA_PASSWORD=your_password
关于Claude Desktop/Zed编辑器,请参见 client_json_config_example/ 对于即用型配置模板:
claude_desktop_config.json-仅限PostgreSQLvertica_claude_desktop_config.json-仅限Verticacombined_claude_desktop_config.json-两台服务器zed_settings.json-PostgreSQL仅适用于Zedvertica_zed_settings.json-Vertica仅适用于Zedcombined_zed_settings.json-Zed的两台服务器
4.运行服务器
PostgreSQL服务器:
- Linux/macOS:
./run_postgres_mcp.sh - 窗户:
run_postgres_mcp.bat
Vertica服务器:
- Linux/macOS:
./run_vertica_mcp.sh - 窗户:
run_vertica_mcp.bat
或者,当您询问数据库问题时,让Claude Desktop/Zed Editor自动启动服务器。
🖥️ 如何检查服务器是否正在运行
PostgreSQL服务器:
- Linux/macOS:
ps aux | grep PostgresMCPServer # or ps aux | grep "python postgres_main.py" - 窗户:
tasklist | findstr PostgresMCPServer tasklist | findstr python
Vertica服务器:
- Linux/macOS:
ps aux | grep VerticaMCPServer # or ps aux | grep "python vertica_main.py" - 窗户:
tasklist | findstr VerticaMCPServer tasklist | findstr python
如果你只看到 grep/findstr 行,服务器未运行。
🔄 服务器生命周期
- 自动: 服务器使用Claude Desktop或Zed Editor自动启动/停止。
- 手册: 您可以从终端启动/停止它们进行测试。
- 无需手动重新启动 在正常使用期间,编辑器会为您管理它们。
- 多台服务器: 您可以同时运行PostgreSQL和Vertica服务器。
🛠️ 可用工具
| 工具 | 说明 | 示例用法 |
|---|---|---|
test_connection |
测试数据库连接 | “测试数据库连接” |
query |
执行SQL查询 | “显示前5个用户” |
list_tables |
列出所有包含元数据的表 | “列出数据库中的所有表” |
🧑💻 手动测试
PostgreSQL:
uv run python test_connection.py # Test PostgreSQL connection
uv run python postgres_main.py # Run PostgreSQL server directly
眩晕:
uv run python test_vertica_connection.py # Test Vertica connection
uv run python vertica_main.py # Run Vertica server directly
🧩 项目结构
mcp-postgres-server/
├── main.py # Entry point
├── config.py # Configuration and logging
├── servers/
│ └── postgres_server.py # MCP server implementation
├── run_mcp.sh / run_mcp.bat # Wrapper scripts
├── setup_mcp.sh # Setup and testing script
├── test_connection.py # DB connection test
├── client_json_config_example/ # Editor config templates
├── .env.example # Environment template
└── README.md # This file
🛟 故障排除
连接失败?
- PostgreSQL: 检查PostgreSQL是否正在运行:
pg_isready -h localhost -p 5432 - 眩晕: 检查Vertica是否正在运行,并且可以在配置的端口上访问
- 验证中的凭据
.env
服务器无法启动?
- PostgreSQL: 测试连接:
uv run python test_connection.py - 眩晕: 测试连接:
uv run python test_vertica_connection.py - 检查日志:
tail -f logs/app.log
编辑器集成问题?
- Linux/macOS:确保编辑器配置中包装脚本的完整路径,并使其可执行
- Windows:确保完整路径
.bat编辑器配置中带有正确反斜杠的脚本 - 在中使用适当的配置模板
client_json_config_example/ - 更改配置后重新启动编辑器
🔒 安全说明
- 参数化查询可防止SQL注入
- 记录所有数据库操作
- 支持只读数据库用户以确保安全
- 错误消息已被清除
📄 许可证
MIT许可证——有关详细信息,请参阅许可证文件。
🤝 贡献
- 分叉存储库
- 创建功能分支(
git checkout -b feature/your-feature) - 提交您的更改(
git commit -m 'Add your feature') - 推到分支(
git push origin feature/your-feature) - 打开拉取请求