# postgres [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/ofershap/mcp-server-postgres  
**GitHub Stars:** 0  
**npm Downloads (last month):** 186  
**Views:** 8  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/postgres

## Description
PostgreSQL MCP — query databases, inspect schemas, explain queries.

## Tools
Capabilities this server exposes over MCP:

- **query** — Execute SQL (SELECT, WITH, EXPLAIN, SHOW, ANALYZE). Returns a text table.
- **schema** — Tables in a schema (default `public`) with columns and approximate row counts
- **table_info** — One table: columns, types, null/default, PK, exact row count
- **explain** — EXPLAIN (FORMAT TEXT), optional ANALYZE
- **list_schemas** — List non-system schemas

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

```json
"mcpServers": {
  "postgres": {
    "command": "npx",
    "args": ["-y","mcp-pg-server"],
    "env": {
      "DATABASE_URL": ""
    }
  }
}
```

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

## Documentation

## What postgres MCP server does

The postgres MCP server exposes PostgreSQL inspection and query operations to MCP-compatible AI clients. It can execute supported SQL and return results as a text table, list non-system schemas, inspect the tables within a schema, describe one table in detail, and produce PostgreSQL execution plans.

The tool set is oriented toward local development and database exploration. It supports questions such as which schemas exist, what columns a table contains, how many rows it has, or how PostgreSQL plans to run a query.

## How it works

The package runs as an MCP process through `npx mcp-pg-server`. A client starts it with a PostgreSQL connection supplied in the `DATABASE_URL` environment variable. Individual tool calls may instead provide a `connectionString`, which overrides the environment-level connection for that call.

The `query` operation accepts SELECT, WITH, EXPLAIN, SHOW, and ANALYZE statements when read-only mode is active. The `schema` operation reports tables for a selected schema, using `public` by default, along with columns and approximate row counts. `table_info` provides column types, nullability or defaults, primary-key information, and an exact row count for one table.

The separate `explain` operation runs PostgreSQL `EXPLAIN (FORMAT TEXT)` and can optionally include ANALYZE. `list_schemas` returns non-system schemas.

## Setup and configuration

Install requirements through the package runner and configure the client to launch `npx` with `mcp-pg-server`. Set `DATABASE_URL` to a PostgreSQL URL, for example a local database connection. The README provides configurations for Cursor, Claude Desktop, and VS Code.

A typical connection uses this environment variable:

- `DATABASE_URL`: PostgreSQL connection URL used by default.

For one-off connections, pass `connectionString` in the relevant tool call instead of changing the process environment. This can be useful when an assistant needs to inspect a different database during a session.

## Tools and capabilities

The postgres MCP server provides five tools:

- `query`: Executes supported SQL and formats the result as text.
- `schema`: Lists tables, columns, and approximate row counts for a schema.
- `table_info`: Shows detailed metadata and an exact row count for one table.
- `explain`: Returns a text execution plan, with optional ANALYZE.
- `list_schemas`: Lists non-system schemas.

Read-only behavior is enabled by default. Setting `readonly=false` permits INSERT, UPDATE, DELETE, and DDL through the query path. That setting changes the safety boundary, so it should be used only when write access is intended.

## Limitations and notes

This postgres MCP server is aimed at local and development PostgreSQL use rather than enterprise database administration. Read-only mode restricts query statements to SELECT, WITH, EXPLAIN, SHOW, and ANALYZE. Row counts are approximate in `schema` output but exact in `table_info` output. Query results are returned as text tables, and execution plans use PostgreSQL's text format.

_Full upstream README: https://allmcps.com/mcp/postgres/readme_

