# pgops [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/arzharch/pgops-mcp  
**GitHub Stars:** 0  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/pgops

## Description
Safe, audited PostgreSQL operations for AI agents: queries, migrations, EXPLAIN, containers

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

```json
"mcpServers": {
  "pgops": {
    "command": "uvx",
    "args": ["pgops-mcp"],
    "env": {
      "PGOPS_DSN": ""
    }
  }
}
```

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

## Documentation

## What pgops MCP server does

The pgops MCP server gives an AI client structured access to PostgreSQL operations rather than exposing an unrestricted query shell. Its capabilities cover schema inspection, read queries, guarded writes, parsed `EXPLAIN` output, index advice, database health checks, migration planning and execution, migration history, and environment diagnostics.

The pgops MCP server also exposes tools for inspecting container logs and statistics. Container restart and command execution are optional gated capabilities: they are registered only in approval mode, require confirmation tokens, and remain constrained by the server's safety rules. Diagnostic command execution uses a read-only allowlist rather than providing a general shell.

## How it works

Before a statement runs, the server classifies it and selects the appropriate database connection role. Unbounded `DELETE` and `UPDATE` statements are blocked, while destructive operations require explicit confirmation. Clients that support user elicitation can display the approval request to the human; otherwise, a single-use token is bound to the exact statement. The assistant cannot approve its own action.

Executed statements are written to an append-only audit log with timing and verdict information. Timeout tiers support cancellation of runaway queries. Migration planning performs dry-run and lock-impact analysis, including safer alternatives such as concurrent index creation. Query explanation returns a parsed plan and diagnostic guidance instead of only raw `EXPLAIN` data.

For remote access, the server supports HTTP with RS256 agent tokens. Tokens can carry read, write, or admin scopes, and tools without a scope mapping require admin access. HTTP startup requires a public key, while stdio runs as a client-spawned subprocess without opening a port.

## Setup and configuration

Set `PGOPS_DSN` to the PostgreSQL connection string. A client can launch the server with `uvx pgops-mcp`, or run the published container image with Docker. A self-check command is available for testing the connection before adding the server to a client configuration.

The container option requires attention to networking and audit persistence. Use `host.docker.internal` or a Compose service name instead of `localhost` when the database is outside the container. Mount a volume at `/var/lib/pgops` if audit records must survive container removal.

Claude Desktop, Cursor, and VS Code configurations are shown in the project documentation. HTTP deployments additionally require generating an RS256 keypair, issuing agent tokens, and passing the public key to the server.

## Tools and capabilities

The documented tool groups include:

- `schema.inspect` for database structure
- `query.read`, `query.write`, and `query.explain` for reads, guarded writes, and plan analysis
- `index.advise` and `db.health` for performance and health checks
- `migration.plan`, `migration.describe`, `migration.apply`, `migration.rollback`, and `migration.history`
- `env.topology`, `env.correlate`, `container.logs`, and `container.stats`
- Approval-gated `container.restart` and `container.exec`

Resources include schema views, health, migration, audit, and configuration data. Prompts support slow-query diagnosis, safe migration planning, incident triage, index-health review, and explanation of the safety model. `migration.describe` uses the connected model through MCP sampling and does not ship an API key. Table-name completion is available for schema resources.

## Limitations and notes

The server is an MCP executable, not a Python library, and its `pgops.*` internals do not promise API stability. HTTP access must be authenticated with agent tokens; stdio does not require authentication because the client starts the process locally. Docker socket access is root-equivalent on the host, so container controls default to read-only behavior.

The pgops MCP server supports PostgreSQL extensions and custom types through catalog-based inspection, including the documented `pgvector` and HNSW index cases. It does not provide a general-purpose shell through `container.exec`, and dangerous operations still depend on client support for prompts or the fallback confirmation-token flow.

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

