Postgres
Enables comprehensive PostgreSQL database management through natural language including queries, schema operations, user management, and administrative tasks. Features enterprise-grade connection pooling, transaction support, and full database admini
What is Postgres?
Postgres is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to enables comprehensive postgresql database management through natural language including queries, schema operations, user management, and administrative tasks. features enterprise-grade connection pool...
Enables comprehensive PostgreSQL database management through natural language including queries, schema operations, user management, and administrative tasks. Features enterprise-grade connection pooling, transaction support, and full database admini
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- Enables comprehensive PostgreSQL database management through
Use Cases
Maintainer
Works with
Installation
Manual Installation
npx postgres-mcp-serverConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use Postgres
The Postgres MCP Server connects AI assistants directly to a PostgreSQL database, allowing them to execute SQL queries, inspect table schemas, and retrieve sample data through natural language. It exposes a `query` tool and resource endpoints for listing tables and browsing schema information, making it easy to explore and manage your database without leaving your AI client. Connection pooling and optional TLS support make it suitable for both local development and production database environments. Developers use it to run ad-hoc queries, debug data issues, and perform schema discovery through conversation.
Prerequisites
- Node.js 18 or later installed
- A running PostgreSQL database with a valid connection string
- The `DATABASE_URL` environment variable set to your connection string (e.g., `postgres://user:pass@localhost:5432/mydb`)
- An MCP-compatible client such as Claude Desktop or Cursor
Obtain your PostgreSQL connection string
Gather your PostgreSQL host, port, username, password, and database name. Form a connection string in the format `postgres://user:password@host:port/dbname`. If your database uses TLS, you may also need a CA certificate path.
Set the DATABASE_URL environment variable
Export the connection string so the MCP server can find it at runtime. You can place this in your shell profile or pass it directly in the MCP client configuration.
export DATABASE_URL="postgres://myuser:mypassword@localhost:5432/mydb"Test the server locally with npx
Run the server using npx to confirm it starts and connects successfully before wiring it into your MCP client. The `--transport stdio` flag is required for Claude Desktop integration.
npx --yes pg-mcp-server --transport stdioAdd the server to your MCP client configuration
Open your Claude Desktop (or other MCP client) configuration file and add the pg-mcp-server entry. Include the DATABASE_URL in the env block so the process receives it.
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
"env": {
"DATABASE_URL": "postgres://myuser:mypassword@localhost:5432/mydb"
}
}
}
}Enable write operations if needed
By default the server may restrict write operations for safety. Set the `DANGEROUSLY_ALLOW_WRITE_OPS` environment variable to `true` to allow INSERT, UPDATE, DELETE, and DDL statements.
"env": {
"DATABASE_URL": "postgres://...",
"DANGEROUSLY_ALLOW_WRITE_OPS": "true"
}Restart your MCP client and verify connection
Restart Claude Desktop or your MCP client. The postgres server should appear in the connected tools list. Try asking it to list your tables to confirm everything is working.
Postgres Examples
Client configuration
Complete Claude Desktop config block for the Postgres MCP server with read-only access.
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
"env": {
"DATABASE_URL": "postgres://myuser:mypassword@localhost:5432/mydb"
}
}
}
}Prompts to try
Example prompts to use once the server is connected to your AI assistant.
- "Show me all tables in the public schema"
- "Show me the first 5 users from the users table"
- "What columns does the orders table have?"
- "Write a query to find all orders placed in the last 7 days and their total value"
- "How many active users are there in the database?"Troubleshooting Postgres
Connection refused or authentication failed
Double-check that DATABASE_URL is correctly formed and the PostgreSQL server is running and accessible from your machine. Test with `psql "$DATABASE_URL"` from the command line first.
Write operations are rejected or not available
Set `DANGEROUSLY_ALLOW_WRITE_OPS=true` in the env block of your MCP client config. Be aware this allows full write access including schema changes.
SSL/TLS connection errors
Set the `PG_SSL_ROOT_CERT` environment variable to the path of your CA certificate file, or append `?sslmode=require` to your DATABASE_URL connection string.
Frequently Asked Questions about Postgres
What is Postgres?
Postgres is a Model Context Protocol (MCP) server that enables comprehensive postgresql database management through natural language including queries, schema operations, user management, and administrative tasks. features enterprise-grade connection pooling, transaction support, and full database admini It connects AI assistants to external tools and data sources through a standardized interface.
How do I install Postgres?
Follow the installation instructions on the Postgres GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.
Which AI clients work with Postgres?
Postgres works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is Postgres free to use?
Yes, Postgres is open source and available under the MIT License license. You can use it freely in both personal and commercial projects.
Postgres Alternatives — Similar Databases Servers
Looking for alternatives to Postgres? Here are other popular databases servers you can use with Claude, Cursor, and VS Code.
Excelize
★ 20.6kGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
MCP Toolbox for Databases
★ 15.3kOpen source MCP server specializing in easy, fast, and secure tools for Databases.
DBHub
★ 2.8kA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.
Tabularis
★ 2.1kA lightweight, cross-platform database client for developers. Supports MySQL, PostgreSQL and SQLite. Hackable with plugins. Built for speed, security, and aesthetics.
Postgres AI Guide
★ 1.7kMCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
Anyquery
★ 1.7k🏎️ 🏠 ☁️ - Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by design.
Browse More Databases MCP Servers
Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up Postgres in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use Postgres?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.