agr_postgres_mcp
OfficialProvides tools for interacting with PostgreSQL databases, enabling querying, schema inspection, and database administration.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@agr_postgres_mcp Describe the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 |
| Yes | — | PostgreSQL hostname |
| No |
| Database username |
| Yes | — | Database password |
| Yes | — | Database name |
| No |
| Database port |
| No |
| MCP server name (used in logs and tool prefixes) |
| No | auto-detect | Full path to the |
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 |
| Execute arbitrary SQL with configurable output format (table/csv/expanded) and timeout |
| List all tables in a schema |
| Describe a table's columns, types, constraints, and indexes ( |
| List indexes, optionally filtered by table |
| Show table sizes (data, index, total) sorted by size |
| Show live/dead tuples, last vacuum/analyze times |
| Show active database connections from |
| Show current locks with blocking information |
| Show query execution plan ( |
| Show total database size and object counts |
| Estimated row counts for all tables |
| List foreign key constraints, optionally filtered by table |
| Index scan statistics for identifying unused indexes |
| Search for tables or columns by LIKE pattern |
Setup
npm install
npm run buildMCP 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 toolsactive_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.
schema_searchB
Search for tables or columns matching a pattern. Useful for finding tables by name.
Inputs: pattern (required), search_type.
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
Scored across 14 tools
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.
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.
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.
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
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Query, explore, and manage your databases through natural conversation.
Your Supabase account in natural language: run SQL, apply migrations, manage tables, storage, edge f
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables exploration and querying of PostgreSQL databases through natural language. Supports listing tables, viewing schemas, executing SELECT queries, filtering records, and retrieving database statistics.2MIT
- FlicenseNot gradedqualityDmaintenanceEnables interaction with PostgreSQL databases through resources, tools, and prompts for data analysis, including listing tables, executing read-only queries, and generating analysis workflows.-
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to interact deeply with PostgreSQL databases—query data, manage schema, analyze performance, and administer the database.6MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI models to execute SQL queries, list tables, and describe table structures on a local PostgreSQL database.ISC