Enables direct execution of PostgreSQL queries including SELECT for data retrieval and INSERT, UPDATE, DELETE, CREATE operations for database modifications, returning structured JSON results.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCP Servershow me the last 10 orders from the customers table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
π PostgreSQL MCP Server
A lightweight Model Context Protocol (MCP) server for executing PostgreSQL queries.
This project enables an MCP-compatible client to run SQL queries (both SELECT and non-SELECT) directly on a PostgreSQL database. The server supports both standard input/output and HTTP (REST API) communication modes.
π§© What is MCP (Model Context Protocol)?
MCP is a universal protocol for connecting external tools, data sources, and services to AI models in a standardized way.
Why MCP? MCP eliminates the need for custom integrations per tool, providing a common API for interacting with various resources.
How does this project fit in? This repo gives you an MCP server for PostgreSQL:
Send SQL queries from any MCP-compatible client.
Receive results in structured JSON.
Seamlessly use PostgreSQL as a knowledge base or app datastore.
Related MCP server: PostgreSQL MCP Server
β¨ Features
Execute direct PostgreSQL queries via MCP.
Supports:
Data retrieval:
SELECTqueries return rows.Database changes:
INSERT,UPDATE,DELETE,CREATE, and more return success status.
Dual operation modes:
stdio(standard in/out)http(REST API server)
Structured logging with loguru.
Built for educational, hackable use (not hardened for production).
β‘ Requirements
Python 3.9+
A running PostgreSQL database
Dependencies:
psycopg2(SQL driver)loguru(logging)mcp(Model Context Protocol library)
π Project Structure
.
βββ .venv/ # Local virtual environment (should be gitignored)
βββ .gitignore # Ignore rules for git
βββ .python-version # Python version file
βββ code.txt # (Optional: dev notes or scratch work)
βββ main.py # CLI entry point to start the server
βββ pyproject.toml # Project dependencies and metadata
βββ README.md # This documentation file
βββ server.py # PostgreSQL MCP server implementation
βββ uv.lock # Dependency lockfile for reproducible installsπ Setup & Usage
1. Clone the repository
git clone https://github.com/<your-username>/<your-repo-name>.git
cd <your-repo-name>2. Install dependencies
uv sync3. Run the server
HTTP mode:
python server.py --mode http --port 9000Stdio mode (for integration as a tool):
python server.py --mode stdioπ§° Development Notes
All logic is contained in
server.py.main.pyshould be a minimal CLI entry point that parses arguments and starts the server.Feel free to reorganize into a package structure if your codebase grows.
π¨βπ» Author
Created with β€οΈ by Loki
π§ Email: logeshwaranshanmugam21@gmail.com
π LinkedIn: Logeshwaran Shanmugam
Tip:
Remember to update your .gitignore to exclude .venv/, __pycache__/, and other cache files for a clean repository.
Happy querying
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.