# postgres-mcp [Health: Active]

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

## Description
PostgreSQL MCP wrapper with .env credential mapping, tool selection, and safe read-only defaults.

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

```json
"mcpServers": {
  "postgres-mcp": {
    "command": "npx",
    "args": ["-y","@edelciomolina/postgres-mcp"],
    "env": {
      "MCP_KEY_URL": "",
      "MCP_KEY_HOST": "",
      "MCP_KEY_PORT": "",
      "MCP_KEY_NAME": "",
      "MCP_KEY_SSLMODE": "",
      "MCP_KEY_USER": "",
      "MCP_KEY_PASS": "",
      "POSTGRES_MCP_ALLOW_WRITE": ""
    }
  }
}
```

**Requires environment variables:** `MCP_KEY_URL`, `MCP_KEY_HOST`, `MCP_KEY_PORT`, `MCP_KEY_NAME`, `MCP_KEY_SSLMODE`, `MCP_KEY_USER`, `MCP_KEY_PASS`, `POSTGRES_MCP_ALLOW_WRITE` — 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 does

The postgres-mcp MCP server connects an MCP client to PostgreSQL through a native server built with the Model Context Protocol SDK and the `pg` package. It gives an agent structured access to database information instead of requiring the agent to guess table names, columns, or relationships.

The server can expose schema metadata, query and database analysis functions, monitoring and debugging operations, and a database graph containing relationships inferred from the live schema. It also provides semantic descriptions of tables and a query-risk classification capability. These features are intended to help an agent understand the database before retrieving or changing data.

## How it works

At startup, the server resolves PostgreSQL credentials from a `.env` file somewhere in the project tree. The MCP configuration maps names such as `MCP_KEY_HOST` or `MCP_KEY_PASS` to the variable names that actually hold the values in `.env`. This allows an existing environment file to use its own naming convention.

A full connection string can be selected with `MCP_KEY_URL`. When that mapping resolves to a present URL, it takes precedence over the individual host, port, database, SSL mode, user, and password settings.

Tool exposure is controlled through separate `tool=<name>` command-line arguments. With no tool arguments, the server starts with its curated read-only set. This keeps modification and schema-definition operations unavailable unless they are deliberately configured.

## Setup and configuration

The postgres-mcp MCP server requires Node.js 18 or newer and a `.env` file containing PostgreSQL connection information. It can be launched with `npx -y @edelciomolina/postgres-mcp` as a stdio server, or installed through the VS Code MCP interface. In VS Code, the server entry belongs in `mcp.json` and can be edited after installation.

For individual connection fields, map `MCP_KEY_HOST`, `MCP_KEY_PORT`, `MCP_KEY_NAME`, `MCP_KEY_SSLMODE`, `MCP_KEY_USER`, and `MCP_KEY_PASS` to the corresponding `.env` variables. For platforms that provide a connection string, map `MCP_KEY_URL` instead.

## Tools and capabilities

The documented default read-only tools include:

- `pg_execute_query` and `pg_manage_query` for query-related operations
- `pg_inspect_schema` for schema inspection
- `pg_analyze_database` for database analysis
- `pg_monitor_database` and `pg_debug_database` for operational investigation
- `pg_inspect_database_graph` for schema relationships
- `pg_describe_table_semantics` for table meaning and context
- `pg_get_setup_instructions` for setup guidance

`pg_classify_query_risk` can assess query safety before execution. Write-capable examples include `pg_manage_schema` and `pg_manage_indexes`; these are not enabled by default.

## Limitations and notes

Write-capable tools require `POSTGRES_MCP_ALLOW_WRITE=true` in the MCP environment. If write tools are requested without that setting, the server exits during startup. Read-only mode does not expose writes, DDL, or arbitrary SQL by default.

The credentials in the examples are stored in `.env`, while `mcp.json` contains mappings to variable names rather than the secret values. The server uses the URL configuration in preference to separate credential fields when both are available. Tool selection is explicit in the MCP launch arguments, so changing the exposed tool set requires editing that configuration.

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

