JUHE API Marketplace
wongjingping avatar
MCP Server

Postgres MCP Server

A Model Context Protocol server that enables querying PostgreSQL databases with tools for executing SELECT queries, inspecting database schemas, and listing tables through natural language.

0
GitHub Stars
11/23/2025
Last Updated
MCP Server Configuration
1{
2 "name": "postgres",
3 "command": "python",
4 "args": [
5 "main.py"
6 ],
7 "env": {
8 "POSTGRES_HOST": "localhost",
9 "POSTGRES_PORT": "5432",
10 "POSTGRES_USER": "postgres",
11 "POSTGRES_PASSWORD": "postgres",
12 "POSTGRES_DB": "housing"
13 }
14}
JSON14 lines
  1. Home
  2. MCP Servers
  3. postgres-mcp

README Documentation

MCP Postgres Server

A Model Context Protocol server for querying PostgreSQL databases with tools for data retrieval and schema inspection.

Setup

Prerequisites: Python 3.11+ and PostgreSQL

# Install dependencies
pip install -r requirements.txt

# Configure database connection (defaults shown)
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_DB=housing

Usage

Development

Run the following command to start the server in development mode and launch the MCP Inspector:

mcp dev main.py

MCP Client Integration

You can also add the following to your MCP client configuration to use the server:

{
  "mcpServers": {
    "postgres": {
      "command": "python",
      "args": ["main.py"],
      "env": {
        "POSTGRES_HOST": "localhost",
        "POSTGRES_PORT": "5432",
        "POSTGRES_USER": "postgres",
        "POSTGRES_PASSWORD": "postgres",
        "POSTGRES_DB": "housing"
      }
    }
  }
}

See mcp.json for an example of how to add the server in Cursor IDE.

Available Tools

  • query_database - Execute SELECT queries (with SQL injection protection)
  • get_table_schema - Get table column information and constraints
  • list_tables - List all database tables
  • postgres://schema - Access complete database schema (resource)

Comparison with Official MCP Postgres Server

This implementation differs from the official @modelcontextprotocol/server-postgres in several key ways:

FeatureThis Server (Python)Official Server (TypeScript)
SafetyGuards against SQL injectionNo protection
Connection Pooling✅ Built-in (asyncpg)❌ Single connection

Security

  • Only SELECT statements allowed
  • Parameterized queries supported
  • Environment-based configuration (no hardcoded credentials)

Next Steps

  • Implement auth for postgres - currently I'm still relying on env variables which doesn't seem very secure
  • Extend this to run on multiple databases and potentially multiple postgres instances as well
  • Implement table / column pruning

Quick Install

Quick Actions

View on GitHubView All Servers

Key Features

Model Context Protocol
Secure Communication
Real-time Updates
Open Source

Boost your projects with Wisdom Gate LLM API

Supporting GPT-5, Claude-4, DeepSeek v3, Gemini and more.

Enjoy a free trial and save 20%+ compared to official pricing.

Learn More
JUHE API Marketplace

Accelerate development, innovate faster, and transform your business with our comprehensive API ecosystem.

JUHE API VS

  • vs. RapidAPI
  • vs. API Layer
  • API Platforms 2025
  • API Marketplaces 2025
  • Best Alternatives to RapidAPI

For Developers

  • Console
  • Collections
  • Documentation
  • MCP Servers
  • Free APIs
  • Temp Mail Demo

Product

  • Browse APIs
  • Suggest an API
  • Wisdom Gate LLM
  • Global SMS Messaging
  • Temp Mail API

Company

  • What's New
  • Welcome
  • About Us
  • Contact Support
  • Terms of Service
  • Privacy Policy
Featured on Startup FameFeatured on Twelve ToolsFazier badgeJuheAPI Marketplace - Connect smarter, beyond APIs | Product Huntai tools code.marketDang.ai
Copyright © 2025 - All rights reserved