Navigation
go-mcp-postgres: Effortless Automation, Zero-Config Deployment - MCP Implementation

go-mcp-postgres: Effortless Automation, Zero-Config Deployment

Plug-and-play MCP server for Postgres automation! Zero setup, no Node.js/Python needed – deploy instantly and automate effortlessly.

Developer Tools
4.5(171 reviews)
256 saves
119 comments

Ranked in the top 4% of all AI tools in its category

About go-mcp-postgres

What is go-mcp-postgres: Effortless Automation, Zero-Config Deployment?

go-mcp-postgres is a lightweight server built for Postgres database automation, designed to eliminate setup hurdles. Inspired by the MySQL version from Zhwt, this tool lets developers perform CRUD operations and schema management without Node.js or Python dependencies. Think of it as a "set and forget" interface that even enforces safety checks like read-only modes and query plan validation. The best part? You don’t need to configure anything beyond specifying your Postgres DSN.

How to use go-mcp-postgres: Effortless Automation, Zero-Config Deployment?

Start by grabbing the binary from GitHub Releases or build it yourself with:

go install github.com/guoling2008/go-mcp-postgres@latest

Configure your server JSON like this:

{
    "mcpServers": {
      "postgres": {
        "command": "go-mcp-postgres",
        "args": ["--dsn", "postgresql://user:pass@host:port/db"]
      }
    }
  }

Pro tip: If you’re on Windows, just swap "go-mcp-postgres" with the full path to your executable. No arguing with the OS here.

go-mcp-postgres Features

Key Features of go-mcp-postgres: Effortless Automation, Zero-Config Deployment?

  • Schema Safety Net: Use list_database, desc_table, and restricted alter_table commands to avoid accidental schema disasters
  • Smart Write Protection: The --read-only flag instantly blocks all DML operations, perfect for dev environments
  • Query Preview: Add --with-explain-check to validate query plans before execution – great for catching slow queries early
  • No-Code Setup: Just point it at your Postgres instance and go. No config files, no YAML parsing – pure command-line simplicity

Use cases of go-mcp-postgres: Effortless Automation, Zero-Config Deployment?

Perfect for:

  • Automating database migrations in CI/CD pipelines without environment dependencies
  • Powering chatbot-driven database interactions in low-code apps
  • Enforcing audit trails by wrapping all write operations through controlled endpoints
  • Teaching SQL basics to new developers with sandboxed read_query access

go-mcp-postgres FAQ

FAQ from go-mcp-postgres: Effortless Automation, Zero-Config Deployment?

  • Q: How do I enable read-only mode?
    Just add --read-only to your startup args. Pro tip: It’s safer to keep this enabled except during active development.
  • Q: Why use this over raw SQL clients?
    Because it gives you API-style abstraction without needing to write middleware. Imagine having a standardized way to handle 90% of common database tasks.
  • Q: Does it support SSL connections?
    Yes, just add sslmode=require to your DSN string. Security folks will love that.
  • Q: Any plans for Oracle/SQLite support?
    Not yet, but the modular design makes adding new backends a weekend project. Pull requests welcome!

Content

go-mcp-postgres

Overview

Copy code from https://github.com/Zhwt/go-mcp-mysql/ and with ai help, I change db from mysql to postgres.

Zero burden, ready-to-use Model Context Protocol (MCP) server for interacting with Postgres and automation. No Node.js or Python environment needed. This server provides tools to do CRUD operations on Postgres databases and tables, and a read-only mode to prevent surprise write operations. You can also make the MCP server check the query plan by using a EXPLAIN statement before executing the query by adding a --with-explain-check flag.

Please note that this is a work in progress and may not yet be ready for production use.

Installation

  1. Get the latest release and put it in your $PATH or somewhere you can easily access.

  2. Or if you have Go installed, you can build it from source:

go install -v github.com/guoling2008/go-mcp-postgres@latest

Usage

Method A: Using Command Line Arguments

{
  "mcpServers": {
    "postgres": {
      "command": "go-mcp-postgres",
      "args": [
        "--dsn",
        "postgresql://user:pass@host:port/db"
      ]
    }
  }
}

Note: For those who put the binary outside of your $PATH, you need to replace go-mcp-postgres with the full path to the binary: e.g.: if you put the binary in the Downloads folder, you may use the following path:

{
  "mcpServers": {
    "postgres": {
      "command": "C:\\Users\\<username>\\Downloads\\go-mcp-postgres.exe",
      "args": [
        ...
      ]
    }
  }
}

Optional Flags

  • Add a --read-only flag to enable read-only mode. In this mode, only tools beginning with list, read_ and desc_ are available. Make sure to refresh/restart the MCP server after adding this flag.
  • By default, CRUD queries will be first executed with a EXPLAIN ? statement to check whether the generated query plan matches the expected pattern. Add a --with-explain-check flag to disable this behavior.

Tools

Schema Tools

  1. list_database
* List all databases in the Postgres server.
* Parameters: None
* Returns: A list of matching database names.
  1. list_table
* List all tables in the Postgres server.
* Parameters: 
  * `name`: If provided, list tables with the specified name, Otherwise, list all tables.
* Returns: A list of matching table names.
  1. create_table
* Create a new table in the Postgres server.
* Parameters: 
  * `query`: The SQL query to create the table.
* Returns: x rows affected.
  1. alter_table
* Alter an existing table in the Postgres server. The LLM is informed not to drop an existing table or column.
* Parameters: 
  * `query`: The SQL query to alter the table.
* Returns: x rows affected.
  1. desc_table
* Describe the structure of a table.
* Parameters: 
  * `name`: The name of the table to describe.
* Returns: The structure of the table.

Data Tools

  1. read_query
* Execute a read-only SQL query.
* Parameters: 
  * `query`: The SQL query to execute.
* Returns: The result of the query.
  1. write_query
* Execute a write SQL query.
* Parameters: 
  * `query`: The SQL query to execute.
* Returns: x rows affected, last insert id: <last_insert_id>.
  1. update_query
* Execute an update SQL query.
* Parameters: 
  * `query`: The SQL query to execute.
* Returns: x rows affected.
  1. delete_query
* Execute a delete SQL query.
* Parameters: 
  * `query`: The SQL query to execute.
* Returns: x rows affected.

Big thanks to https://github.com/Zhwt/go-mcp-mysql/ again.

License

MIT

Related MCP Servers & Clients