Get the FREE Ultimate OpenClaw Setup Guide β†’

pgsql

πŸ”§ A powerful tool server based on the Model Context Protocol (MCP), enabling interaction with PostgreSQL databases via MCP calls.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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)

  1. Install the server tool:
uv tool install pgsql-mcp-server
  1. 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)

  1. Run the server directly using uvx:
uvx pgsql-mcp-server --dsn "postgresql://user:password@localhost:5432/db"

Option C: Install via pip (alternative)

  1. Install package from PyPI:
pip install pgsql-mcp-server
  1. 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

Sponsor this space

Reach thousands of developers β†—