# PostgreSQL MCP Server [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/musaddiq-dev/postgresql-mcp-server  
**GitHub Stars:** 1  
**Views:** 1  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/postgresql-mcp-server-2

## Description
Python MCP server for PostgreSQL database inspection and querying

## Tools
Capabilities this server exposes over MCP:

- **postgresql_list_tables** — List public base tables
- **postgresql_describe_table** — Show columns and metadata for a table
- **postgresql_execute_read_query** — Run bounded SQL under read-only transaction mode
- **postgresql_execute_write_query** — Run a single approved modifying SQL statement and commit
- **postgresql_explain_query** — Return PostgreSQL `EXPLAIN` output for a single query
- **postgresql_get_database_summary** — Return database version and table count
- **postgresql_get_relationships** — Inspect foreign-key relationships
- **postgresql_analyze_indexes** — Inspect indexes and sizes
- **postgresql_preview_table** — Return up to 10 rows from a table
- **postgresql_search_sql_definitions** — Search public SQL routines/functions

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "postgresql-mcp-server": {
    "command": "uvx",
    "args": ["mdev-postgresql-mcp-server"],
    "env": {
      "POSTGRES_HOST": "",
      "POSTGRES_PORT": "",
      "POSTGRES_USER": "",
      "POSTGRES_DB": ""
    }
  }
}
```

**Requires environment variables:** `POSTGRES_HOST`, `POSTGRES_PORT`, `POSTGRES_USER`, `POSTGRES_DB` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What PostgreSQL MCP Server MCP server does

PostgreSQL MCP Server MCP server exposes PostgreSQL inspection and query operations as MCP tools and resources. It is intended for MCP-compatible hosts such as Claude Desktop, Cursor, Windsurf, Cline, Claude Code, and VS Code. The server connects to one configured PostgreSQL database using host, port, user, database, and optional password settings.

Its read-only capabilities cover public table discovery, column and metadata inspection, bounded SQL queries, query plans, table previews, database summaries, foreign-key relationships, index details, and searches across public SQL routines or functions. It also provides two passive resources: one for public table names and another for a generated schema statement for a selected table.

## How it works

The server uses the stdio MCP transport. When started, it reads its connection settings from the process environment and writes Python logs to stderr so protocol messages remain on stdout. Clients invoke the exposed tools through their normal MCP configuration.

`postgresql_execute_read_query` runs SQL inside PostgreSQL read-only transaction mode, limits the returned rows according to `POSTGRES_READ_QUERY_LIMIT`, and rolls the transaction back after execution. `postgresql_explain_query` returns PostgreSQL `EXPLAIN` output without directly running the target query. `postgresql_preview_table` returns no more than 10 rows.

A separate write operation accepts one statement from the supported INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, or TRUNCATE categories and commits it when the database user permits the operation. Because it can change data or schema, it should not be automatically approved by the MCP client.

## Setup and configuration

PostgreSQL MCP Server MCP server requires Python 3.11 or newer and access to a PostgreSQL database. The published package can be launched with `uvx mdev-postgresql-mcp-server`. For local development, clone the repository, create a virtual environment, install the project with `pip install -e .`, and run `python -m postgresql_mcp_server.server` or the installed console script.

Set `POSTGRES_HOST`, `POSTGRES_PORT`, `POSTGRES_USER`, and `POSTGRES_DB` for the connection. `POSTGRES_PASSWORD` is optional, while `LOG_LEVEL` defaults to `INFO` and `POSTGRES_READ_QUERY_LIMIT` defaults to 1000. The example configuration uses port 5432 and a local host. For shared or public deployments, use a dedicated PostgreSQL user with only the permissions required for the intended operations.

Do not commit environment files or client configurations containing credentials. A read-only role can be granted database connection access, schema usage, and SELECT privileges on the public schema. If write access is available, review generated SQL and require explicit approval before invoking the write tool.

## Tools and capabilities

Available tools include:

- `postgresql_list_tables` for public base tables.
- `postgresql_describe_table` for table columns and metadata.
- `postgresql_execute_read_query` for bounded read-only SQL.
- `postgresql_execute_write_query` for one modifying SQL statement.
- `postgresql_explain_query` for PostgreSQL query plans.
- `postgresql_get_database_summary` for the database version and table count.
- `postgresql_get_relationships` for foreign-key inspection.
- `postgresql_analyze_indexes` for index information and sizes.
- `postgresql_preview_table` for a ten-row table sample.
- `postgresql_search_sql_definitions` for public routines and functions.

The `postgres://list_tables` resource exposes public table names, and `postgres://schema/{table_name}` provides generated schema information for a table.

## Limitations and notes

The server focuses on PostgreSQL and the public schema. Read-query safety is bounded by transaction mode and the configured result limit, but SQL review and database permissions remain important. The write tool is destructive and is not restricted to read-only behavior. Without a configured database, only basic source syntax can be checked with Python compilation; database-backed behavior requires starting the server with valid connection settings.

_Full upstream README: https://allmcps.com/mcp/postgresql-mcp-server-2/readme_

