The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the PostgreSQL MCP Server listing page.
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.
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.
When published to PyPI, install or run the server like a standard Python MCP package:
For local development from source:
Copy the example environment file and update it with your database connection details.
| 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:
From a local checkout before PyPI publication, run:
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.
Most MCP clients accept this mcpServers JSON shape:
For local development from this repository, use the installed console script path instead:
VS Code uses the same command/args/env model in its MCP configuration:
| Tool | Purpose | Safety |
|---|---|---|
postgresql_list_tables | List public base tables | Read-only |
postgresql_describe_table | Show columns and metadata for a table | Read-only |
postgresql_execute_read_query | Run bounded SQL under read-only transaction mode | Read-only |
postgresql_execute_write_query | Run a single approved modifying SQL statement and commit | Destructive |
postgresql_explain_query | Return PostgreSQL EXPLAIN output for a single query | Read-only |
postgresql_get_database_summary | Return database version and table count | Read-only |
postgresql_get_relationships | Inspect foreign-key relationships | Read-only |
postgresql_analyze_indexes | Inspect indexes and sizes | Read-only |
postgresql_preview_table | Return up to 10 rows from a table | Read-only |
postgresql_search_sql_definitions | Search public SQL routines/functions | Read-only |
postgres://list_tables returns public table names.postgres://schema/{table_name} returns a generated schema statement for a table.Without a database, verify syntax with:
With a configured database, start the server and use your MCP client to call list_tables.
This server is published through the standard Python MCP distribution path:
mdev-postgresql-mcp-serverio.github.musaddiq-dev/postgresql-mcp-serveruvxstdioThe 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.
.env or MCP client configs containing credentials.execute_write_query as destructive and require explicit user approval in your MCP client.MIT