Skip to main content
Glama
kd444

Enterprise PostgreSQL MCP Server

by kd444

Enterprise PostgreSQL MCP Server v2

A production-ready Model Context Protocol (MCP) server for PostgreSQL database interactions.

Features

  • Working MCP Server: Simple and reliable PostgreSQL MCP implementation

  • Read-only by Default: Security-first approach with query validation

  • Multiple Tools: Database listing, table inspection, and SQL queries

  • Cursor Integration: Ready for Cursor IDE integration

  • FastMCP Support: Both simple and FastMCP implementations included

Quick Start

1. Setup Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Configure Database

Set your PostgreSQL connection string:

export PG_DSN="postgresql://postgres:@localhost:5432/your_database"

3. Test the Server

# Test simple MCP server
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | python enterprise_mcp_server.py

# Test list_tables tool
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "list_tables", "arguments": {}}}' | python enterprise_mcp_server.py

Cursor Integration

Add to your Cursor MCP configuration (~/.cursor/mcp.json):

{
    "mcpServers": {
        "enterprise-postgres": {
            "command": "/path/to/venv/bin/python",
            "args": ["/path/to/enterprise_mcp_server.py"],
            "env": {
                "PG_DSN": "postgresql://postgres:@localhost:5432/your_database"
            }
        }
    }
}

Available Tools

  • list_tables: List all tables in the database

  • database_info: Get database connection information

  • sql_query: Execute read-only SQL queries (SELECT, WITH, EXPLAIN, SHOW)

Security

  • Read-only queries only (INSERT, UPDATE, DELETE blocked)

  • Query validation and sanitization

  • Connection string masking in responses

  • Transaction-based execution with rollback

Development

Built with:

  • Python 3.13+

  • asyncpg for PostgreSQL connectivity

  • FastMCP for enhanced MCP features

  • JSON-RPC 2.0 protocol compliance

License

MIT License - see LICENSE file for details.

Related MCP Connectors