Enables direct execution of PostgreSQL queries including SELECT for data retrieval and INSERT, UPDATE, DELETE, CREATE operations for database modifications, returning structured JSON results.
🚀 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.
✨ Features
- Execute direct PostgreSQL queries via MCP.
- Supports:
- Data retrieval:
SELECT
queries return rows. - Database changes:
INSERT
,UPDATE
,DELETE
,CREATE
, and more return success status.
- Data retrieval:
- 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
🛠 Setup & Usage
1. Clone the repository
2. Install dependencies
3. Run the server
HTTP mode:
Stdio mode (for integration as a tool):
🧰 Development Notes
- All logic is contained in
server.py
. main.py
should 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
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables direct execution of PostgreSQL queries through the Model Context Protocol. Supports both SELECT and non-SELECT operations with dual communication modes (stdio and HTTP REST API).
Related MCP Servers
- -securityFlicense-qualityA Model Context Protocol server providing both read and write access to PostgreSQL databases, enabling LLMs to query data, modify records, and manage database schemas.Last updated -6357
- AsecurityAlicenseAqualityA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.Last updated -18699119AGPL 3.0
- -securityAlicense-qualityA Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.Last updated -23MIT License
- -securityFlicense-qualityA Model Context Protocol server implementation that provides a simple interface to interact with PostgreSQL databases, enabling SQL queries, database operations, and schema management through MCP.Last updated -