Skip to main content
Glama
sureshbandi

PostgreSQL MCP Server

by sureshbandi

šŸ”Œ PostgreSQL MCP Server (Python & Docker)

A clean, fully executable implementation of a custom Model Context Protocol (MCP) server built in Python using Anthropic's FastMCP framework. This project connects Claude Desktop directly to a local PostgreSQL database running securely in Docker.

This repository contains all the code and configuration files showcased in the step-by-step YouTube tutorial.


šŸ—ļø Architecture Overview

The connection is established using a simple client-server model defined by the Model Context Protocol: ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” JSON-RPC (stdio) ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ Claude Desktop │ <──────────────────────────> │ Python MCP Server │ │ (MCP Client) │ │ (FastMCP) │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ │ SQL │ (Authentication) ā–¼ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ PostgreSQL │ │ (Docker Container)│ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

  • Authentication: The Python script uses a secure username/password credential set to authenticate with the Postgres database.

  • Authorization: Claude is authorized strictly to fetch and view products via the @mcp.tool() wrapper. It does not have access or permissions to perform destructive database modifications.


Related MCP server: PostgreSQL MCP Server for Claude Desktop

šŸ“ Project Structure

mcp-postgres-demo/
ā”œā”€ā”€ db/
│   └── init.sql         # Seed data & table schema definitions
ā”œā”€ā”€ docker-compose.yml   # Multi-container local database orchestrator
ā”œā”€ā”€ server.py            # FastMCP Server with stdio & SSE transport modes
ā”œā”€ā”€ requirements.txt     # Locked project dependencies
└── .gitignore           # Keeps local environments and OS junk out of Git

šŸš€ Quick Start Guide
1. Clone & Set Up a Virtual Environment
Isolate your Python workspace to avoid dependency version conflicts:
# Clone this repository
git clone [https://github.com/](https://github.com/)<your-username>/claude-postgres-mcp-connector.git
cd claude-postgres-mcp-connector

# Create the virtual environment
python -m venv venv

# Activate it (macOS/Linux)
source venv/bin/activate

# Activate it (Windows PowerShell)
.\venv\Scripts\Activate.ps1

2. Install Project Dependencies
Install the locked dependencies defined in our requirement manifests:

pip install -r requirements.txt
3. Launch the Database (Docker)
We use Docker Compose to spin up a pre-configured Postgres database.
docker-compose up -d
Note: The docker-compose.yml mounts our SQL script using the :ro (Read-Only) volume flag. This is a secure best-practice protecting our local init.sql initialization script from being corrupted or altered by runtime database mutations.
F
license - not found
-
quality - not tested
C
maintenance

Maintenance

–Maintainers
–Response time
–Release cycle
–Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    Enables secure chat-based interaction with PostgreSQL databases through Claude Desktop. Features GitHub OAuth authentication, role-based access control, and enterprise-grade security for database queries and operations.
    1
    MIT
  • F
    license
    -
    quality
    D
    maintenance
    Enables Claude Desktop to interact with PostgreSQL databases through natural language for schema exploration, data analysis, and query execution. Users can search schemas, describe tables, and perform read or write operations without needing to write manual SQL.
  • F
    license
    -
    quality
    D
    maintenance
    Enables Claude Desktop to query a PostgreSQL brand database through MCP. Supports local stdio and remote HTTP/SSE deployments with API key authentication for secure database access.

View all related MCP servers

Related MCP Connectors

  • Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.

  • Connect Claude to Fathom meeting recordings, transcripts, and summaries

  • Connect your team's living knowledge base — docs, data, issues, CRM — to Claude and ChatGPT.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sureshbandi/mcp-postgres-tutorial'

If you have feedback or need assistance with the MCP directory API, please join our Discord server