PostgreSQL

Provides MCP-based tools to interact with PostgreSQL: run queries, explain plans, manage schemas, and list tables.
  • go

11

GitHub Stars

go

Language

6 months ago

First Indexed

2 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "leixiaotian1-pgsql-mcp-server": {
      "command": "./pgsql-mcp-server",
      "args": [],
      "env": {
        "DB_HOST": "localhost",
        "DB_NAME": "postgres",
        "DB_PORT": "5432",
        "DB_USER": "your_username",
        "DB_SSLMODE": "disable",
        "DB_PASSWORD": "your_password",
        "SERVER_MODE": "stdio"
      }
    }
  }
}

You deploy and run a Model Context Protocol (MCP) server that lets AI assistants securely interact with a PostgreSQL database. It enables executing SQL queries, explaining plans, creating tables, and listing tables through a structured MCP interface, making database operations seamless for AI workflows.

How to use

You will run the MCP server locally and connect your MCP-enabled AI client to perform database tasks. Use the stdio transport for straightforward local testing, or switch to SSE or Streamable HTTP for client tools that require tree-like streaming or HTTP-based MCP transport. The server exposes tools to read data, modify data, manage schemas, and analyze query plans.

How to install

Prerequisites: you need Go 1.23 or later and access to a PostgreSQL database server.

# Build and run the MCP server locally (stdio mode)
# 1) Ensure Go is installed
# 2) Retrieve the server source code and dependencies
# 3) Build the MCP server
go build -o pgsql-mcp-server

# 4) Run the MCP server (stdio mode)
./pgsql-mcp-server

Configuration and environment

Configure your database connection through environment variables. Create a .env file in the project root with these values to connect to your PostgreSQL database.

DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_USER=your_username
DB_PASSWORD=your_pass
DB_SSLMODE=disable
SERVER_MODE=stdio

Available tools

read_query

Executes a SELECT SQL query and returns results for AI consumption.

write_query

Executes an INSERT, UPDATE, or DELETE SQL query to modify data.

create_table

Executes a CREATE TABLE statement to define a new table schema.

list_tables

Lists user-created tables, optionally filtered by a schema.

explain_query

Returns the execution plan for a given SQL query (must start with EXPLAIN).

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational