Get the FREE Ultimate OpenClaw Setup Guide →

postgres

A Model Control Protocol (MCP) server that allows Claude to interact with PostgreSQL databases using natural language queries

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio mgorunuch-postgres-mcp-server postgres-mcp-server \
  --env POSTGRES_CONNECTION_STRING="PostgreSQL connection string (optional). If not provided, defaults to a local PostgreSQL instance."

How to use

This MCP server exposes a PostgreSQL interface for Claude to interact with your PostgreSQL databases using the Model Control Protocol. It supports standard database operations while enforcing safety by default: destructive queries like DROP, TRUNCATE, DELETE, UPDATE, ALTER, CREATE, and INSERT are blocked unless you explicitly enable unsafe execution via the pg_query tool. You can run the server directly or generate a Claude-friendly MCP configuration JSON to wire into Claude's MCP tooling. The server can connect to PostgreSQL via a connection string either provided through the POSTGRES_CONNECTION_STRING environment variable or via command-line options when starting the server (if supported by your binary).

How to install

Prerequisites:\n- A PostgreSQL instance you want to connect to.\n- The postgres-mcp-server binary (install method depends on your platform).\n\nInstall via Homebrew (on macOS):\nbash\n# Add the tap (if using the official repository)\nbrew tap mgorunuch/postgres-mcp-server https://github.com/mgorunuch/postgres-mcp-server\n\n# Install the server\nbrew install mgorunuch/postgres-mcp-server/postgres-mcp-server\n\n\nManual installation: Download the appropriate binary for your platform from the releases page, then move the binary to a directory in your PATH, e.g. /usr/local/bin. Ensure it is executable:\nbash\nchmod +x /path/to/postgres-mcp-server\n\n\nEnvironment setup (optional): If you want to provide the connection string via environment variable, export it before starting the server:\nbash\nexport POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/dbname?sslmode=disable"\n\n\nStart the server: Depending on your installation, run the binary directly:\nbash\npostgres-mcp-server\n

Additional notes

Tips and common issues:\n- If you use Claude Code, you can generate an MCP config with:\n postgres-mcp-server --json --connection-string 'YOUR_CONNECTION_STRING'\n Then paste the resulting JSON into Claude's MCP configuration.\n- By default, destructive queries are blocked. To enable them via the Claude toolset, you must set unsafe: true when using the pg_query tool in Claude.\n- If the server cannot connect to PostgreSQL, check the connection string and network accessibility from the host running the MCP server.\n- You can override the connection string at runtime by using the POSTGRES_CONNECTION_STRING environment variable.\n- If you need to run multiple PostgreSQL instances or databases, create separate MCP server instances with distinct connection strings.

Related MCP Servers

Sponsor this space

Reach thousands of developers