PostgreSQL MCP server

Enables secure interaction with PostgreSQL databases for schema management and CRUD operations with safety features like read-only mode and query plan validation
Back to servers
Provider
guoling2008
Release date
Mar 24, 2025
Language
Go
Stats
4 stars

Go-MCP-Postgres is a ready-to-use Model Context Protocol (MCP) server for interacting with PostgreSQL databases. It provides tools for CRUD operations with options for read-only mode and query plan checking. This lightweight server requires no Node.js or Python environment to function.

Installation

You can install go-mcp-postgres using one of these methods:

Download Binary

Download the latest release from the official GitHub releases page and add it to your $PATH or a location you can easily access.

Build From Source

If you have Go installed, build it from source with:

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

Usage

You can run the MCP server in two different modes:

Standard I/O Mode

Configure your application to use go-mcp-postgres with the following JSON configuration:

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

If the binary is not in your $PATH, specify the full path:

{
  "mcpServers": {
    "postgres": {
      "command": "C:\\Users\\<username>\\Downloads\\go-mcp-postgres.exe",
      "args": [
        "--dsn",
        "postgresql://user:pass@host:port/db"
      ]
    }
  }
}

Server-Sent Events (SSE) Mode

Run the server in SSE mode using:

./go-mcp-postgres --t sse --ip x.x.x.x --port nnnn --dsn postgresql://user:pass@host:port/db --lang en

Optional Flags

  • --lang: Set language (en/zh-CN), defaults to system language
  • --read-only: Enable read-only mode, restricting available tools to those beginning with list, read_ and desc_
  • --with-explain-check: Forces checking query plans before execution using EXPLAIN statements

Available Tools

The MCP server provides various tools for database operations that are automatically localized based on the language parameter.

Schema Management Tools

list_database

  • Lists all available databases
  • Parameters: None
  • Returns: List of database names

list_table

  • Lists database tables
  • Parameters:
    • name: (Optional) Specific table name to filter by
  • Returns: List of matching table names

create_table

  • Creates a new table
  • Parameters:
    • query: SQL CREATE TABLE statement
  • Returns: Confirmation message with affected rows

alter_table

  • Modifies an existing table structure
  • Parameters:
    • query: SQL ALTER TABLE statement
  • Returns: Confirmation message with affected rows

desc_table

  • Shows table structure details
  • Parameters:
    • name: Table name to describe
  • Returns: Detailed table structure information

Data Operation Tools

read_query

  • Executes a read-only SQL query
  • Parameters:
    • query: SQL SELECT statement
  • Returns: Query results

write_query

  • Executes data insertion operations
  • Parameters:
    • query: SQL INSERT statement
  • Returns: Affected rows count and last insert ID

update_query

  • Modifies existing data
  • Parameters:
    • query: SQL UPDATE statement
  • Returns: Number of affected rows

delete_query

  • Removes data from tables
  • Parameters:
    • query: SQL DELETE statement
  • Returns: Number of affected rows

count_query

  • Counts rows in a table
  • Parameters:
    • name: Table name to count
  • Returns: Row count for the specified table

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later