mcp-postgres-server

mcp-postgres-server

MCP server providing PostgreSQL and Vertica database access with tools for querying, listing tables, and testing connections.

Category
访问服务器

README

PostgreSQL & Vertica MCP Server

A professional Model Context Protocol (MCP) server providing## 🧩 Project Structure

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. Configuration

Edit .env with your database connection strings:

For PostgreSQL:

DB_URL=postgresql://username:password@localhost:5432/database_name

For Vertica:

VERTICA_HOST=localhost
VERTICA_PORT=5433
VERTICA_DB=VMart
VERTICA_USER=dbadmin
VERTICA_PASSWORD=your_password

For Claude Desktop/Zed Editor, see client_json_config_example/ for ready-to-use config templates:

  • claude_desktop_config.json - PostgreSQL only
  • vertica_claude_desktop_config.json - Vertica only
  • combined_claude_desktop_config.json - Both servers
  • zed_settings.json - PostgreSQL only for Zed
  • vertica_zed_settings.json - Vertica only for Zed
  • combined_zed_settings.json - Both servers for Zed

4. Run the Servers

PostgreSQL Server:

  • Linux/macOS: ./run_postgres_mcp.sh
  • Windows: run_postgres_mcp.bat

Vertica Server:

  • Linux/macOS: ./run_vertica_mcp.sh
  • Windows: run_vertica_mcp.bat

Or let Claude Desktop/Zed Editor start the servers automatically when you ask database questions.


🖥️ How to Check if Servers are Running

PostgreSQL Server:

  • Linux/macOS:
    ps aux | grep PostgresMCPServer
    # or
    ps aux | grep "python postgres_main.py"
    
  • Windows:
    tasklist | findstr PostgresMCPServer
    tasklist | findstr python
    

Vertica Server:

  • Linux/macOS:
    ps aux | grep VerticaMCPServer
    # or
    ps aux | grep "python vertica_main.py"
    
  • Windows:
    tasklist | findstr VerticaMCPServer
    tasklist | findstr python
    

If you only see the grep/findstr line, the server is not running.


🔄 Server Lifecycle

  • Automatic: Servers start/stop automatically with Claude Desktop or Zed Editor.
  • Manual: You can start/stop them from the terminal for testing.
  • No need to restart manually during normal use—the editor manages them for you.
  • Multiple servers: You can run both PostgreSQL and Vertica servers simultaneously.

🛠️ Available Tools

Tool Description Example Usage
test_connection Test DB connectivity "Test the database connection"
query Execute SQL queries "Show me the first 5 users"
list_tables List all tables with metadata "List all tables in the database"

🧑‍💻 Manual Testing

PostgreSQL:

uv run python test_connection.py      # Test PostgreSQL connection
uv run python postgres_main.py        # Run PostgreSQL server directly

Vertica:

uv run python test_vertica_connection.py  # Test Vertica connection
uv run python vertica_main.py             # Run Vertica server directly

🧩 Project Structure

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

🛟 Troubleshooting

Connection failed?

  • PostgreSQL: Check if PostgreSQL is running: pg_isready -h localhost -p 5432
  • Vertica: Check if Vertica is running and accessible on the configured port
  • Verify credentials in .env

Server won't start?

  • PostgreSQL: Test connection: uv run python test_connection.py
  • Vertica: Test connection: uv run python test_vertica_connection.py
  • Check logs: tail -f logs/app.log

Editor integration issues?

  • Linux/macOS: Ensure full path to wrapper scripts in editor config and make them executable
  • Windows: Ensure full path to .bat scripts in editor config with proper backslashes
  • Use the appropriate config templates in client_json_config_example/
  • Restart your editor after config changes

🔒 Security Notes

  • Parameterized queries prevent SQL injection
  • All DB operations are logged
  • Supports read-only DB users for safety
  • Error messages are sanitized

📄 License

MIT License — see the LICENSE file for details.

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add your feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选