Postgres MCP Server

Postgres MCP Server

Enables LLMs to query and analyze PostgreSQL databases through a controlled interface. Supports SQL query execution, table schema inspection, and optional write operations with safety controls.

Category
Visit Server

README

Postgres MCP Server

A Model Context Protocol server for PostgreSQL databases. Enables LLMs to query and analyze PostgreSQL databases through a controlled interface.

Installation

Install MCP Server

Add to your MCP client settings:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
      "env": {
        "DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres"
      }
    }
  }
}

Configuration

  • DATABASE_URL - PostgreSQL connection string (required)
  • DANGEROUSLY_ALLOW_WRITE_OPS - Enable writes (default: false)
  • DEBUG - Enable debug logging (default: false)
  • PG_SSL_ROOT_CERT - Optional path to a TLS CA bundle (e.g., AWS RDS global bundle)

Usage

Transports

  • Default transport is stdio. Switch to HTTP with the --transport flag.
  • HTTP mode serves the MCP Streamable HTTP endpoint at /mcp on PORT (default 3000).
  • Clients that support Streamable HTTP should connect to http://localhost:3000/mcp.

Start commands:

# stdio transport (default, via installed CLI)
pg-mcp-server --transport=stdio

# http transport
pg-mcp-server --transport=http

Tools

  • query - Execute SQL queries
    { "sql": "SELECT * FROM users WHERE active = true LIMIT 10" }
    

Resources

  • postgres://tables - List all tables
  • postgres://table/{schema}/{table} - Get table schema and sample data

Example Prompts

Here's an example prompt to test if your MCP server is working:

Show me the first 5 users from the database

Quick Start with Docker

# Start PostgreSQL with sample data
bun run db:start

# Test with MCP Inspector
bun run inspector

# Stop PostgreSQL
bun run db:stop

Sample tables included: users, products, orders, order_items

Development

# Clone and install
git clone https://github.com/ericzakariasson/pg-mcp-server.git
cd pg-mcp-server
bun install

# Run (stdio transport)
bun run index.ts -- --transport=stdio
DEBUG=true bun run index.ts -- --transport=stdio

# Run (http transport)
bun run index.ts -- --transport=http
DEBUG=true bun run index.ts -- --transport=http
bun test                      # Run tests

Use local build in MCP client settings:

bun run build:js
{
  "mcpServers": {
    "postgres": {
      "command": "node",
      "args": ["/absolute/path/to/pg-mcp-server/lib/index.js", "--transport", "stdio"],
      "env": {
        "DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres"
      }
    }
  }
}

Releases

This repo auto-creates a GitHub Release when you push a tag that matches the version in package.json:

  1. Update CHANGELOG.md and bump the version in package.json.
  2. Commit the changes on main (or your release branch).
  3. Create and push a matching tag:
VERSION=$(jq -r .version package.json)
git tag v"$VERSION"
git push origin v"$VERSION"

The GitHub Actions workflow will validate that the tag (e.g. v0.1.0) matches package.json, then use gh to create a release with generated notes, and publish to npm.

License

MIT - see LICENSE

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured