# JaviMaligno/postgres_mcp [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/JaviMaligno/postgres_mcp  
**GitHub Stars:** 10  
**npm Downloads (last month):** 58  
**Views:** 3  
**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 read-only SQL queries against the database
- **execute** — Execute write operations (INSERT/UPDATE/DELETE) when enabled
- **explain_query** — Get EXPLAIN plan for query optimization
- **list_schemas** — List all schemas in the database
- **list_tables** — List tables in a specific schema
- **describe_table** — Get table structure (columns, types, constraints)
- **list_views** — List views in a schema
- **describe_view** — Get view definition and columns
- **list_functions** — List functions and procedures
- **table_stats** — Get table statistics (row count, size, bloat)
- **list_indexes** — List indexes for a table
- **list_constraints** — List constraints (PK, FK, UNIQUE, CHECK)
- **get_database_info** — Get database version and connection info
- **search_columns** — Search for columns by name across all tables
- **list_databases** — List the configured connections by alias, with host, database, write permission and which is the default. Never returns credentials.

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

```json
"mcpServers": {
  "postgres-mcp": {
    "command": "npx",
    "args": ["-y","npx"],
    "env": {
      "POSTGRES_USER": "",
      "POSTGRES_PASSWORD": "",
      "POSTGRES_DB": ""
    }
  }
}
```

**Requires environment variables:** `POSTGRES_USER`, `POSTGRES_PASSWORD`, `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 JaviMaligno/postgres_mcp MCP server does

JaviMaligno/postgres_mcp MCP server connects MCP-compatible clients to PostgreSQL databases. It provides tools for running read-only SQL, inspecting database structure, examining indexes and constraints, reviewing table statistics, and retrieving database information. The server also includes an optional write tool for INSERT, UPDATE, and DELETE operations when write access is enabled.

The repository contains equivalent TypeScript and Python implementations. The TypeScript package is the recommended option for Smithery deployments and requires Node.js 20 or newer. The Python package requires Python 3.10 or newer. Both implementations support the documented MCP protocol revision and retain compatibility with clients using the earlier initialization style.

## How it works

JaviMaligno/postgres_mcp MCP server reads connection settings from the process environment rather than accepting credentials as tool arguments. A single connection can use PostgreSQL host, port, user, password, database, and SSL mode variables. For multiple databases, `POSTGRES_CONNECTIONS` defines named aliases; each tool can select an alias with its optional `database` argument, while omitted arguments use the configured default.

Multiple connections are opened lazily, so an unused configured database does not open a connection pool. The server can also apply per-connection write permissions. If no connection is explicitly marked as default, the first declared connection is used. Credentials are not returned by `list_databases`, which reports aliases and non-secret connection details instead.

MCP prompts support guided database exploration, query construction, performance analysis, and schema documentation. MCP resources expose browsable schema, table, and database information through `postgres://` resource URIs.

## Setup and configuration

The TypeScript implementation can be run with `npx @javiagui/postgresql-mcp` or installed globally with npm. The Python implementation is installed with `pipx install postgresql-mcp` and runs as `postgresql-mcp`. Configuration examples are provided for Claude Code and Cursor, and the README states compatibility with Claude Desktop and other MCP clients.

For a basic connection, `POSTGRES_USER`, `POSTGRES_PASSWORD`, and `POSTGRES_DB` are required. `POSTGRES_HOST` defaults to `localhost`, `POSTGRES_PORT` defaults to `5432`, and `POSTGRES_SSLMODE` defaults to `prefer`. `ALLOW_WRITE_OPERATIONS` defaults to false. `QUERY_TIMEOUT` defaults to 30 seconds, and `MAX_ROWS` defaults to 1,000 returned rows.

`POSTGRES_CONNECTIONS` and the individual `POSTGRES_*` settings are mutually exclusive. Connection entries can use discrete fields or a PostgreSQL URL, with discrete fields taking precedence when both are present.

## Tools and capabilities

JaviMaligno/postgres_mcp MCP server exposes tools for:

- Executing read-only queries and, when permitted, write statements.
- Producing `EXPLAIN` plans for query optimization.
- Listing schemas, tables, views, functions, and procedures.
- Describing table columns, types, constraints, and view definitions.
- Finding indexes and constraints such as primary keys, foreign keys, unique constraints, and checks.
- Reporting table row counts, size, and bloat statistics.
- Searching for column names across tables.
- Returning PostgreSQL version and connection information.
- Listing configured database aliases without exposing credentials.

## Limitations and notes

Write operations are disabled by default and must be enabled explicitly. The server enforces query limits through the configured timeout and maximum-row settings. Connection credentials must remain in the environment; callers cannot supply a host, user, password, or connection string through a tool argument. The README identifies MIT as the project license.

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

