# JaviMaligno/postgres_mcp [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/JaviMaligno/postgres_mcp  
**GitHub Stars:** 12  
**npm Downloads (last month):** 465  
**Views:** 6  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/javimaligno-postgres-mcp

## Description
PostgreSQL MCP server with 14 tools for querying, schema exploration, and table analysis. Features security-first design with SQL injection prevention and read-only by default.

## Tools
Capabilities this server exposes over MCP:

- **query** — Execute a SQL query against the PostgreSQL database. This tool is READ-ONLY by default. Use the "execute" tool for write operations.
- **execute** — Execute a write SQL statement (INSERT, UPDATE, DELETE). WARNING: This tool modifies data. Available only when writes are enabled globally or for the selected database.
- **explain_query** — Get the execution plan for a SQL query (EXPLAIN).
- **list_schemas** — List all schemas in the PostgreSQL database.
- **list_tables** — List all tables in a specific schema.
- **describe_table** — Describe the structure of a table including columns, types, and constraints.
- **table_stats** — Get statistics for a table (row count, size, bloat).
- **list_indexes** — List all indexes for a table.
- **list_constraints** — List all constraints for a table (PK, FK, UNIQUE, CHECK).
- **list_views** — List all views in a schema.
- **describe_view** — Get the definition and columns of a view.
- **list_functions** — List all functions and procedures in a schema.
- **get_database_info** — Get database and connection information.
- **search_columns** — Search for columns by name across all tables.
- **list_databases** — List the databases this server is configured to reach, by alias, with their host, database name, whether writes are allowed, and which one is the default. Credentials are never returned. Call this first when the user mentions a database by name, then pass the alias as the "database" argument of any other tool.

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

```json
"mcpServers": {
  "postgres-mcp": {
    "command": "npx",
    "args": ["@javiagui/postgresql-mcp"],
    "env": {
      "POSTGRES_CONNECTIONS": "",
      "POSTGRES_HOST": "",
      "POSTGRES_PORT": "",
      "POSTGRES_USER": "",
      "POSTGRES_PASSWORD": "",
      "POSTGRES_DB": "",
      "POSTGRES_SSLMODE": "",
      "ALLOW_WRITE_OPERATIONS": ""
    }
  }
}
```

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

## Documentation

## What JaviMaligno/postgres_mcp does

JaviMaligno/postgres_mcp exposes PostgreSQL operations through MCP. It supports direct SQL querying, query-plan inspection, schema browsing, and database metadata inspection. Agents can enumerate schemas, tables, views, functions, indexes, and constraints; inspect table definitions and statistics; search for columns; and retrieve database connection information.

The server also supports controlled data modification. The `execute` tool handles INSERT, UPDATE, and DELETE statements, but write access is disabled by default and must be enabled globally or for the selected connection. The separate `query` tool is intended for read operations.

Optional result protections can mask personal data before results reach the model. Detection can cover email addresses, phone numbers, payment cards, IBANs, and several national identifiers. Column deny lists and allow lists provide additional control over which values are exposed.

## How it works

The server can use either the TypeScript package, installed through npm, or the Python package, installed through pipx. Both implementations provide the same functionality. It is designed to work with Claude Code, Claude Desktop, Cursor, and other MCP-compatible clients.

A single PostgreSQL connection can be configured with standard connection variables. For multiple databases, `POSTGRES_CONNECTIONS` defines aliases and connection details. Each tool can receive a database alias; if omitted, the configured default is used. Connections are opened lazily, so an unused configured database does not open a connection.

Credentials come from the environment or connection configuration rather than tool arguments. The `list_databases` tool reports aliases, hosts, database names, write permissions, and the default connection without returning credentials. Query results are limited by the configured maximum row count, and queries have a configurable timeout.

## Setup and configuration

Install the TypeScript implementation with `npm install -g @javiagui/postgresql-mcp`, or run it directly with `npx @javiagui/postgresql-mcp`. The Python implementation is available with `pipx install postgresql-mcp`.

For a single database, configure `POSTGRES_USER`, `POSTGRES_PASSWORD`, and `POSTGRES_DB`; `POSTGRES_HOST` defaults to `localhost` and `POSTGRES_PORT` to `5432`. `POSTGRES_SSLMODE` controls SSL behavior. `ALLOW_WRITE_OPERATIONS` enables writes globally when set appropriately, while `QUERY_TIMEOUT` and `MAX_ROWS` control query execution and result size.

Use `REDACT_PII`, `REDACT_COLUMNS`, and `ALLOWED_COLUMNS` to configure result masking. Multi-database configurations can set per-connection write and redaction behavior. `POSTGRES_CONNECTIONS` and the plain single-connection variables are mutually exclusive.

## Tools and capabilities

- Run read-only SQL with `query`.
- Run INSERT, UPDATE, or DELETE with `execute` when permitted.
- Inspect plans with `explain_query`.
- Explore schemas, tables, views, functions, indexes, and constraints.
- Inspect table definitions, statistics, view definitions, and database information.
- Find columns across tables with `search_columns`.
- Select a configured database through `list_databases` and per-tool aliases.
- Browse database structure through MCP resources and use guided MCP prompts for exploration, query building, and documentation.

## Limitations and notes

Write operations require explicit permission and remain controlled per connection when multiple databases are configured. When redaction is enabled, `query` and `explain_query` run in a read-only transaction, and results are withheld if masking fails rather than being returned unredacted. Column rules are matched case-insensitively and can use `column`, `table.column`, or `schema.table.column` patterns. Computed expressions have different behavior under deny and allow lists, so strict exposure control is best handled with an allow list and carefully defined source columns.

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

