PostgreSQL MCP Server

PostgreSQL MCP Server

postgres_mcp_server•byvivekmalipatel

A FastMCP-powered Model Context Protocol server that gives AI assistants structured access to a PostgreSQL database through MCP resources and tools over stdio.

License: MIT•Runtime: Awaiting documentation review•Category: databases storage

WHAT IT DOES

  • •Exposes read-only MCP resources listing tables, showing table schema with column types and constraints, and previewing the first 100 rows of a table.
  • •Provides MCP tools to execute raw SQL queries and perform select operations with filtering, ordering, and pagination.
  • •Supports write and DDL actions through tools: creating and dropping tables, inserting rows, updating and deleting rows matching conditions.
  • •Uses parameterised queries throughout to prevent SQL injection.

BEST FOR

  • •Teams wanting natural-language data operations on their PostgreSQL database from MCP-compatible AI clients.
  • •Users who want AI-assisted schema inspection and CRUD operations without writing SQL.

ABOUT POSTGRES_MCP_SERVER

PostgreSQL MCP Server is cataloged as an MCP server attributed to vivekmalipatel. A FastMCP-powered Model Context Protocol server that gives AI assistants structured access to a PostgreSQL database through MCP resources and tools over stdio. It is categorized under databases storage. See the capability inspector for recorded interfaces and their independent review status; consult upstream documentation for the current interface.

HOW TO INSTALL

Installation configuration is not reviewed. No executable setup is offered for this entry; inspect the source repository before proceeding.

LICENSE

Catalog license label: MIT. Check the source repository's current license and terms before using, modifying or distributing this software.

Capability inspector

Capability definitions are not reviewed. Unreviewed imports are not exposed as trusted interfaces.

Tools (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

Resources (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

Prompts (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

NEWSLETTER - COMING LATER

Newsletter subscriptions are not open yet

Email delivery is not connected. This page does not collect email addresses or create subscriptions.

Browse the registry for current listings instead.

Community Reviews

Coming later

Reviews for PostgreSQL MCP Server are not available yet

Review publishing and storage are not connected. This page does not collect or publish ratings or comments, including after sign-in.

FREQUENTLY ASKED QUESTIONS

What transport does the server use?

It runs over stdio; the server starts and waits on stdin for MCP protocol messages.

How is it protected against SQL injection?

It uses parameterised queries throughout.

Upstream README

View this exact version on GitHub

README.md · ae17a54ce0f0 · Fetched 2026-11-13 10:47:28 UTC

Original upstream text, without AI rewriting. Scripts, forms and unsafe links are filtered for safety.

Showing the last retrieved documentation snapshot; check the source for current changes.

PostgreSQL MCP Server

A FastMCP-powered Model Context Protocol server that gives AI assistants (Claude, Cursor, etc.) full, structured access to a PostgreSQL database — no SQL knowledge required from the user.


Overview

This server exposes your PostgreSQL database as a set of MCP Resources (read-only views) and MCP Tools (read/write actions) over the stdio transport. Any MCP-compatible AI client can connect, inspect your schema, and perform data operations in natural language.

Claude / Cursor / any MCP client
        │  stdio (MCP protocol)
        ▼
 postgres_mcp_server.py   (FastMCP layer — resources & tools)
        │  async
        ▼
 postgres_manager.py      (asyncpg connection pool)
        │
        ▼
  PostgreSQL Database

Features

CategoryCapability
SchemaList all tables, inspect column definitions
ReadsSelect with filters, ordering, and row limits
WritesInsert, update, delete rows
DDLCreate and drop tables
Raw SQLExecute arbitrary queries
SafetyParameterised queries throughout (no SQL injection)
LoggingStructured stdout logs on every tool/resource call

MCP Resources

Resources are read-only, URI-addressable data feeds the AI client can subscribe to.

URIDescription
postgres://tablesJSON list of all tables in the database
postgres://schema/{table_name}Column names, types, and constraints for a table
postgres://data/{table_name}First 100 rows of a table (safe preview)

MCP Tools

Tools are callable actions the AI can invoke on your behalf.

execute_query

Execute any raw SQL statement and get results back as JSON.

query: str  — the SQL to run

create_table

Create a new table with custom column definitions.

table_name: str
columns:    [{"name": "id", "type": "SERIAL PRIMARY KEY"}, ...]

drop_table

Drop a table permanently.

table_name: str

insert_data

Insert a single row into a table.

table_name: str
data:       {"column": value, ...}

update_data

Update rows matching a condition.

table_name:       str
data:             {"column": new_value, ...}
condition:        "id = %s"
condition_params: [42]

delete_data

Delete rows matching a condition.

table_name:       str
condition:        "status = %s"
condition_params: ["inactive"]

select_data

Query a table with optional filtering, ordering, and pagination.

table_name:       str
columns:          ["id", "name"]          (optional, default: *)
condition:        "age > %s"              (optional)
condition_params: [18]                    (optional)
order_by:         "created_at DESC"       (optional)
limit:            100                     (optional, default: 100)

Prerequisites

  • Python 3.8+
  • PostgreSQL server (local or remote)
  • uv package manager (recommended) — or pip
  • An MCP-compatible AI client (Claude Desktop, Cursor, etc.)

Installation

# 1. Clone the repository
git clone https://github.com/VivekMalipatel/Postgres_MCP_Server.git
cd Postgres_MCP_Server

# 2. Create and activate a virtual environment
python -m venv .mcp
source .mcp/bin/activate        # macOS / Linux
# .mcp\Scripts\activate         # Windows

# 3. Install dependencies
pip install -r requirements.txt

Configuration

Create a .env file in the project root:

POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=your_database
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password

Connecting to Claude Desktop

Add the following block to your Claude Desktop MCP config file
(~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "PostgreSQL MCP": {
      "command": "/absolute/path/to/.mcp/bin/uv",
      "args": [
        "run",
        "--with", "mcp[cli]",
        "--with", "asyncpg",
        "--with", "httpx",
        "--with", "python-dotenv",
        "--with", "psycopg2-binary",
        "mcp",
        "run",
        "/absolute/path/to/postgres_mcp_server.py"
      ],
      "env": {
        "POSTGRES_HOST": "localhost",
        "POSTGRES_PORT": "5432",
        "POSTGRES_USER": "your_username",
        "POSTGRES_PASSWORD": "your_password",
        "POSTGRES_DB": "your_database"
      }
    }
  }
}

Replace all /absolute/path/to/ with the actual paths on your machine.
You can omit the env block if you are using a .env file instead.


Running Manually (stdio)

python postgres_mcp_server.py

The server starts and waits on stdin for MCP protocol messages. In normal use, your AI client launches it automatically via the config above.


Dependencies

PackagePurpose
mcp[cli]MCP protocol + FastMCP framework
asyncpgHigh-performance async PostgreSQL driver
psycopg2-binarySynchronous PostgreSQL driver (fallback)
python-dotenv.env file loading
httpxAsync HTTP client (available to tools)
uvicornASGI server (for future HTTP transport)
uvFast Python package runner

Project Structure

Postgres_MCP_Server/
├── postgres_mcp_server.py   # FastMCP server — resources, tools, lifespan
├── postgres_manager.py      # Async DB manager (connection pool, CRUD)
├── requirements.txt
└── .env                     # (create this — not committed)

License

MIT — free to use, modify, and distribute.

Install configuration

Are you the maintainer?

Claim this server with your GitHub account to request manual ownership verification.

README Embed Badge
Markdown

Link to the catalog listing for PostgreSQL MCP Server from your README. This badge does not certify ownership, compatibility or security.

[![MCP catalog listing](https://img.shields.io/badge/MCP-awesome--mcp-orange?style=flat-square)](https://awesome-mcp.com/servers/postgres_mcp_server)

REPOSITORY STATS

GitHub StarsUnavailable
ForksUnavailable

Public repository statistics could not be verified. Check the configured source address; unavailable counts are not zero.

Downloads and pulls

Separate sources, scopes and periods. Never combined or treated as installations, active users or security reviews.

No reviewed package or image identity; download statistics are not listed yet.

Related databases storage MCP Servers

Alternative and complementary servers in the same category

View all in databases storage →
AIStor MCP server
mcp-server-aistor•minio

This is a Model Context Protocol (MCP) server for interacting with AIStor object stores.

Repository stats unavailable
Databases & Storage
InfluxDB v2 MCP Server
influxdb-mcp-server•idoru

A Model Context Protocol (MCP) server that exposes access to an InfluxDB v2 instance using the InfluxDB OSS API v2.

Repository stats unavailable
Databases & Storage