pgsql
π§ A powerful tool server based on the Model Context Protocol (MCP), enabling interaction with PostgreSQL databases via MCP calls.
claude mcp add --transport stdio twn39-pgsql-mcp-server uvx pgsql-mcp-server --dsn postgresql://user:password@localhost:5432/db
How to use
This PgSQL MCP Server exposes a set of MCP tools to interact with a PostgreSQL database asynchronously. Built on FastMCP with SQLAlchemy and asyncpg, it supports schema discovery, table and column inspection, index and foreign key details, and DDL/DML/DCL operations via MCP calls. You can inspect the available tools with the MCP Inspector and issue calls to perform tasks such as listing schemas, viewing table structures, running queries, and applying transactional changes to the database. Typical workflows include fetching schema information to understand a database layout, executing read queries (DQL) to retrieve data, and performing DDL statements like creating or altering tables within a transaction-safe context.
How to install
Prerequisites:
- Python 3.10+
- Internet access to fetch dependencies
Option A: Using uv (recommended)
- Install the server tool:
uv tool install pgsql-mcp-server
- Run the server with a DSN to connect to PostgreSQL:
pgsql-mcp-server --dsn "postgresql://user:password@localhost:5432/db"
Option B: Run directly with uvx (no installation required)
- Run the server directly using uvx:
uvx pgsql-mcp-server --dsn "postgresql://user:password@localhost:5432/db"
Option C: Install via pip (alternative)
- Install package from PyPI:
pip install pgsql-mcp-server
- Run the server with a DSN:
pgsql-mcp-server --dsn "postgresql://user:password@localhost:5432/db"
Additional notes
Tips and considerations:
- Ensure PostgreSQL is reachable from the host where you run the MCP server and that the user has appropriate permissions for the operations you intend to perform.
- For production, consider using TLS/SSL connections and securing credentials (avoid hard-coding passwords in commands).
- The MCP Inspector tool can be used to explore tools, their parameters, and to test calls in a browser-based UI. Start it with the given npx/uvx command as shown in the README.
- Integration tests assume a local PostgreSQL instance. If your DB is remote or uses a non-default port, update the DSN accordingly.
- All DDL, DML, and DCL operations are performed within transactions with error handling and rollback on failure.
- If you encounter environment-variable-related issues, prefer supplying the DSN via the --dsn flag or set DSN in the environment where the command runs.
Related MCP Servers
jupyter
πͺ π§ Model Context Protocol (MCP) Server for Jupyter.
mcp -odoo
A Model Context Protocol (MCP) server that enables AI assistants to securely interact with Odoo ERP systems through standardized resources and tools for data retrieval and manipulation.
falcon
Connect AI agents to CrowdStrike Falcon for automated security analysis and threat hunting
beemcp
BeeMCP: an unofficial Model Context Protocol (MCP) server that connects your Bee wearable lifelogger to AI via the Model Context Protocol
MCP-MultiServer-Interoperable-Agent2Agent-LangGraph-AI-System
This project demonstrates a decoupled real-time agent architecture that connects LangGraph agents to remote tools served by custom MCP (Modular Command Protocol) servers. The architecture enables a flexible and scalable multi-agent system where each tool can be hosted independently (via SSE or STDIO), offering modularity and cloud-deployable execut
Helios
An AI IDE secure coding MCP service