Pgsql MCP Server

A Model Context Protocol (MCP) server that provides tools for interacting with a PostgreSQL database. It enables AI assistants to execute SQL

Local serverstdioGo

What is the Pgsql MCP server?

Pgsql MCP server exists for a simple reason — assistants are far more useful when they can act on Pgsql directly instead of describing what you should do. A Model Context Protocol (MCP) server that provides tools for interacting with a PostgreSQL database. It enables AI assistants to execute SQL queries, explain statements, create tables, and list database tables via the MCP protocol.

What the assistant can call

Once Pgsql is connected, these are the calls the assistant has available:

  • read_query — Executes a SELECT SQL query
  • write_query — Executes an INSERT, UPDATE, or DELETE SQL query
  • create_table — Executes a CREATE TABLE SQL statement
  • list_tables — Lists all user-created tables in the database
  • explain_query — Returns the execution plan for a given SQL query
  • Prerequisites — The Prerequisites tool exposed by this server
  • Installation — 1. Clone the repository: bash git clone https://github.com/leixiaotian1/pgsql-mcp-server.git cd pgsql-mcp-server
  • stdio — The server communicates over standard input and output. This is the default mode and is ideal for local testing or direct integration with
  • streamableHttp — The server uses the Streamable HTTP transport, a more modern and flexible HTTP-based transport for MCP

Setting it up

Setup follows the usual MCP pattern — install or clone the server, register it in your client's configuration file, restart the client. The configuration blocks on this page cover the common clients.

Configuration and credentials

You will need 7 environment variables: DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD, DB_SSLMODE, SERVER_MODE. Keep credentials in your client's env block or a secrets manager rather than in a file you might commit.

  • Go 1.23 or later - A PostgreSQL database server

Choosing this one

Plenty of database access servers cover similar ground. The differences that matter in practice are scope of access and how much setup stands between you and a working tool call. Pgsql's toolset — read_query, write_query, create_table and 6 more — is a fair guide to whether it matches your workflow. It is maintained by leixiaotian1; worth a glance at recent repository activity before you build anything load-bearing on it.

We check each listing at SyncDev against the project's documentation before it goes live — if something here drifts out of date, it is a bug worth reporting.

Before you rely on it

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • With 9 tools registered it takes up a noticeable share of the context window; turn it off in projects that never touch Pgsql.
  • MCP clients confirm each tool call by default. Leave that on until you have watched what the pgsql mcp server does with a few real requests.

Available tools

ToolWhat it does
read_queryExecutes a SELECT SQL query.
write_queryExecutes an INSERT, UPDATE, or DELETE SQL query.
create_tableExecutes a CREATE TABLE SQL statement.
list_tablesLists all user-created tables in the database.
explain_queryReturns the execution plan for a given SQL query.
PrerequisitesThe Prerequisites tool exposed by this server.
Installation1. Clone the repository: bash git clone https://github.com/leixiaotian1/pgsql-mcp-server.git cd pgsql-mcp-server
stdioThe server communicates over standard input and output. This is the default mode and is ideal for local testing or direct integration with command-line-based MCP clients.
streamableHttpThe server uses the Streamable HTTP transport, a more modern and flexible HTTP-based transport for MCP.

How to install the Pgsql MCP server

{
  "mcpServers": {
    "pgsql-mcp-server": {
      "command": "/path/to/pgsql-mcp-server",
      "args": [],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "postgres",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password",
        "DB_SSLMODE": "disable",
        "SERVER_MODE": "stdio"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Configuration as documented by the project. Restart the client after saving.

Configuration

  • Go 1.23 or later - A PostgreSQL database server
VariableDescriptionRequired
DB_HOSTEndpoint or connection string the server talks to.Optional
DB_PORTConfiguration value read at startup.Optional
DB_NAMEConfiguration value read at startup.Optional
DB_USERConfiguration value read at startup.Optional
DB_PASSWORDConfiguration value read at startup.Optional
DB_SSLMODEConfiguration value read at startup.Optional
SERVER_MODEConfiguration value read at startup.Optional

Example prompts to try

  • Use Pgsql to read query.
  • Use Pgsql to write query.
  • Use Pgsql to create table.

Frequently asked questions

It connects Pgsql to MCP-compatible AI assistants such as Claude and Cursor, exposing 9 tools (read_query, write_query, create_table, and more) that the assistant can call on your behalf. Instead of copying data back and forth by hand, the assistant works with Pgsql directly.