A Python Model Context Protocol (MCP) server for inspecting and querying PostgreSQL databases from MCP-compatible clients. It provides schema discovery, safe read-only query execution, query explanation, table previews, index analysis, relationship inspection, and PostgreSQL resources for table metadata.
Features
Python MCP server for PostgreSQL database inspection and querying
Execute read-only SQL in a PostgreSQL read-only transaction
Explain query plans without executing the target query directly
Preview table rows with a fixed limit
Inspect foreign-key relationships and indexes
Expose passive MCP resources for table lists and schema details
Safety Model
postgresql_execute_read_query runs with PostgreSQL read-only transaction mode, caps returned rows by POSTGRES_READ_QUERY_LIMIT, and rolls back after execution. The server also includes postgresql_execute_write_query, which only accepts a single INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, or TRUNCATE statement and can modify data/schema if the connected database user has permission. Do not auto-approve write-capable tools in your MCP client. For public or shared use, run the server with a dedicated read-only PostgreSQL user.
Requirements
Python 3.11+
PostgreSQL database
MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host
Installation
When published to PyPI, install or run the server like a standard Python MCP package:
Copy the example environment file and update it with your database connection details.
cp .env.example .env
Variable
Description
Required
Default
POSTGRES_HOST
PostgreSQL host
Yes
localhost
POSTGRES_PORT
PostgreSQL port
Yes
5432
POSTGRES_USER
PostgreSQL username
Yes
None
POSTGRES_PASSWORD
PostgreSQL password
No
None
POSTGRES_DB
PostgreSQL database name
Yes
None
LOG_LEVEL
Python logging level written to stderr
No
INFO
POSTGRES_READ_QUERY_LIMIT
Maximum rows returned by read queries
No
1000
Example read-only user:
CREATE USER mcp_readonly WITH PASSWORD 'change-me';
GRANT CONNECT ON DATABASE your_database TO mcp_readonly;
GRANT USAGE ON SCHEMA public TO mcp_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO mcp_readonly;
Running
mdev-postgresql-mcp-server
From a local checkout before PyPI publication, run:
python -m postgresql_mcp_server.server
MCP Client Configuration
For published installs, prefer uvx. MCP servers using stdio must write protocol messages only to stdout; this server writes logs to stderr through Python logging.
Claude Desktop / Cursor / Windsurf / Cline
Most MCP clients accept this mcpServers JSON shape:
The mcp-name marker at the top of this README is required for MCP Registry ownership verification. Users should prefer uvx mdev-postgresql-mcp-server in local MCP client configurations.
Security Notes
Do not commit .env or MCP client configs containing credentials.
Use least-privilege database users.
Treat execute_write_query as destructive and require explicit user approval in your MCP client.
Review generated SQL before running write-capable tools.
Noch keine Tool-Liste. Remote-Server erhalten eine nach dem ersten Health-Check.
FAQ
Fragen
Wie installiere ich PostgreSQL MCP Server?
Kopieren Sie auf dieser Seite die stdio-Konfiguration für Cursor, Claude Desktop, Claude Code oder VS Code. Sie nutzt die Installation des Herausgebers, keinen PlugMCP-Proxy.
Benötigt PostgreSQL MCP Server einen API-Schlüssel?
Der Herausgeber nennt diese Umgebungsvariablen: POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB, POSTGRES_READ_QUERY_LIMIT.
Welchen Transport verwendet PostgreSQL MCP Server?
PostgreSQL MCP Server läuft lokal über stdio.
Wann wurde PostgreSQL MCP Server zuletzt geprüft?
Zuletzt geprüft: 2026-11-10. Python MCP server for PostgreSQL database inspection and querying