Skip to main content
Glama
agr_postgres_mcp

agr_postgres_mcp

Official

agr_postgres_mcp

MCP server for interacting with PostgreSQL databases via psql. Designed for use with Claude Code as a Model Context Protocol (MCP) server.

Configuration

The server is configured entirely through environment variables:

Variable

Required

Default

Description

PG_HOST

Yes

—

PostgreSQL hostname

PG_USER

No

postgres

Database username

PG_PASSWORD

Yes

—

Database password

PG_DATABASE

Yes

—

Database name

PG_PORT

No

5432

Database port

PG_SERVER_NAME

No

postgres

MCP server name (used in logs and tool prefixes)

PSQL_PATH

No

auto-detect

Full path to the psql binary

If PSQL_PATH is not set, the server searches common locations:

  • /opt/homebrew/opt/postgresql@15/bin/psql

  • /opt/homebrew/opt/postgresql@13/bin/psql

  • /Applications/Postgres.app/Contents/Versions/15/bin/psql

  • /Applications/Postgres.app/Contents/Versions/14/bin/psql

  • /usr/local/bin/psql

  • /usr/bin/psql

Related MCP server: PostgreSQL MCP Server

Tools

Tool

Description

query

Execute arbitrary SQL with configurable output format (table/csv/expanded) and timeout

list_tables

List all tables in a schema

describe_table

Describe a table's columns, types, constraints, and indexes (\d+ equivalent)

list_indexes

List indexes, optionally filtered by table

table_sizes

Show table sizes (data, index, total) sorted by size

table_stats

Show live/dead tuples, last vacuum/analyze times

active_connections

Show active database connections from pg_stat_activity

locks

Show current locks with blocking information

explain

Show query execution plan (EXPLAIN / EXPLAIN ANALYZE)

database_size

Show total database size and object counts

row_counts

Estimated row counts for all tables

foreign_keys

List foreign key constraints, optionally filtered by table

index_usage

Index scan statistics for identifying unused indexes

schema_search

Search for tables or columns by LIKE pattern

Setup

npm install
npm run build

MCP Configuration

Add an entry to .mcp.json for each database instance:

{
  "mcpServers": {
    "pg-alpha": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/agr_postgres_mcp/dist/index.js"],
      "env": {
        "PG_SERVER_NAME": "alpha",
        "PG_HOST": "your-db-host.example.com",
        "PG_USER": "postgres",
        "PG_PASSWORD": "your-password",
        "PG_DATABASE": "your-database",
        "PSQL_PATH": "/path/to/psql"
      }
    }
  }
}

Multiple instances can be configured by adding additional entries with different PG_SERVER_NAME and PG_HOST values.

Available Tools

14 tools
active_connectionsA

Show active database connections with their state, query, and duration.

Inputs: no named parameters.

database_sizeA

Show the total database size and individual table sizes.

Inputs: no named parameters.

describe_tableA

Describe a table's columns, types, constraints, and indexes. Equivalent to psql \d+ command.

Inputs: table (required).

explainA

Show the query execution plan for a SQL query using EXPLAIN. Does not execute the query.

Inputs: sql (required), analyze.

foreign_keysA

List foreign key constraints, optionally filtered by table.

Inputs: table.

index_usageA

Show index usage statistics to identify unused or rarely used indexes.

Inputs: table.

list_indexesB

List all indexes in the database, optionally filtered by table name.

Inputs: table.

list_tablesB

List all tables in the database with their schema, name, type, and owner.

Inputs: schema.

locksA

Show current locks in the database with blocking information.

Inputs: no named parameters.

queryB

Execute a SQL query against the PostgreSQL database. Returns the query results as text. Use LIMIT clauses on exploratory queries.

Inputs: sql (required), format, timeout.

row_countsA

Show estimated row counts for all tables, sorted by count descending.

Inputs: limit.

table_sizesA

Show table sizes including data, indexes, and total. Sorted by total size descending.

Inputs: limit.

table_statsA

Show table statistics including live/dead tuples, last vacuum/analyze times.

Inputs: limit, table.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 14 tools

    Disambiguation4/5

    Most tools target a distinct diagnostic concern such as schema, indexes, locks, or statistics. The main overlap is between database_size and table_sizes, which both report table sizes, but the rest are clearly separable.

    Naming Consistency4/5

    All names are snake_case and readable, but conventions are mixed: list_/describe_ prefixes appear on some tools while others use bare nouns like locks and table_sizes or bare verbs like query and explain. This is mostly predictable but not fully consistent.

    Tool Count5/5

    With 14 tools, the server is well-scoped for PostgreSQL inspection and administration. Each tool covers a meaningful diagnostic or query task without excessive redundancy.

    Completeness4/5

    The toolkit provides strong coverage of schema discovery, query analysis, sizes, stats, indexes, and locking. It lacks explicit tools for database objects like views or functions and for write operations, but the generic query tool fills those gaps, so the core diagnostic surface is complete.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables exploration and querying of PostgreSQL databases through natural language. Supports listing tables, viewing schemas, executing SELECT queries, filtering records, and retrieving database statistics.
      2
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with PostgreSQL databases through resources, tools, and prompts for data analysis, including listing tables, executing read-only queries, and generating analysis workflows.
      -