postgres
A Model Control Protocol (MCP) server that allows Claude to interact with PostgreSQL databases using natural language queries
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
trpc-agent-go
trpc-agent-go is a powerful Go framework for building intelligent agent systems using large language models (LLMs) and tools.
station
Station is our open-source runtime that lets teams deploy agents on their own infrastructure with full control.
tiger-cli
Tiger CLI is the command-line interface for Tiger Cloud. It includes an MCP server for helping coding agents write production-level Postgres code.
gopls
MCP server for golang projects development: Expand AI Code Agent ability boundary to have a semantic understanding and determinisic information for golang projects.
kubernetes
A Model Context Protocol (MCP) server for the Kubernetes API.
gcp-cost
💰 An MCP server that enables AI assistants to estimate Google Cloud costs, powered by Cloud Billing Catalog API and built with Genkit for Go