Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

postgres-mcp

MCP.Pizza Chef: ipfans

Postgres MCP is an MCP-compliant server that provides a simple HTTP interface for executing read-only SQL queries and exploring PostgreSQL database resources. Built with Go and the Gin web framework, it supports environment variable configuration and offers secure, structured access to PostgreSQL databases for integration with LLMs and AI workflows.

Use This MCP server To

Execute read-only SQL queries on PostgreSQL databases via HTTP List and explore PostgreSQL database resources programmatically Integrate PostgreSQL data into AI workflows using MCP protocol Configure database connections using environment variables or CLI flags Enable secure, read-only database access for LLM-powered applications

README

Postgres MCP (Research Project)

A Model Control Protocol (MCP) server implementation for PostgreSQL databases. This project provides a simple HTTP interface to interact with PostgreSQL databases through MCP, allowing you to execute read-only queries and explore database resources.

Features

  • MCP-compliant HTTP server
  • Read-only SQL query execution
  • Database resource listing
  • Environment variable support through .env files
  • Built with Go and Gin web framework

Prerequisites

  • Go 1.23.6 or later
  • PostgreSQL database
  • Git

Installation

git clone https://github.com/ipfans/postgres-mcp.git
cd postgres-mcp
go mod download

Configuration

You can configure the database connection in two ways:

  1. Using command-line flags:
go run cmd/postgres-mcp/main.go -db "postgres://user:password@localhost:5432/dbname"
  1. Using environment variables:
    • Create a .env file in the project root
    • Add your database URL:
      DATABASE_URL=postgres://user:password@localhost:5432/dbname
      

Usage

  1. Start the server:
go run cmd/postgres-mcp/main.go

The server will start on port 8080 by default.

  1. Interact with the MCP endpoints:
  • List database resources:

    POST http://localhost:8080/mcp
    Content-Type: application/json
    
    {
      "type": "function",
      "name": "resources"
    }
    
  • Execute a read-only query:

    POST http://localhost:8080/mcp
    Content-Type: application/json
    
    {
      "type": "function",
      "name": "query",
      "arguments": {
        "query": "SELECT * FROM your_table LIMIT 10"
      }
    }
    

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

postgres-mcp FAQ

How do I configure the Postgres MCP server to connect to my database?
You can configure it using command-line flags or by setting the DATABASE_URL in a .env file in the project root.
Does Postgres MCP allow write operations on the database?
No, it only supports read-only SQL query execution to ensure data safety.
What are the prerequisites for running Postgres MCP?
You need Go 1.23.6 or later, a PostgreSQL database, and Git to clone the repository.
How does Postgres MCP expose database data to LLMs?
It provides an MCP-compliant HTTP server interface that allows LLMs to query and explore database resources securely.
Can I use Postgres MCP with different LLM providers?
Yes, it is provider-agnostic and works with OpenAI, Claude, Gemini, and others supporting MCP.
What programming language and framework is Postgres MCP built with?
It is built using Go and the Gin web framework for efficient HTTP server implementation.
Is it possible to customize the SQL queries executed by Postgres MCP?
You can execute any read-only SQL queries supported by PostgreSQL through the HTTP interface provided by Postgres MCP.
How do I install Postgres MCP?
Clone the repository from GitHub, download dependencies with 'go mod download', and run the server using Go commands.