What it does
Postgres MCP is for database work where the agent needs to see the schema and reason about a query. It gives the agent a database connection instead of a pasted table description.
- Explore database schemas and tables.
- Run read-oriented database queries.
- Explain a slow query.
- Suggest indexes from query and schema information.
- Pass the database connection through the server environment.
Available functions
analyze_db_health Analyzes database health. Here are the available health checks: - index - checks for invalid, duplicate, and bloated indexes - connection - checks the number of connection and their utilization - vacuum - checks vacuum health for transaction id wraparound - sequence - checks sequences at risk of exceeding their maximum value - replication - checks replication health including lag and slots - buffer - checks for buffer cache hit rates for indexes and tables - constraint - checks for invalid constraints - all - runs all checks You can optionally specify a single health check or a comma-separated list of health checks. The default is 'all' checks.
Arguments
-
health_type -
stringOptional. Valid values are: all, buffer, connection, constraint, index, replication, sequence, vacuum. Default:all
analyze_query_indexes Analyze a list of (up to 10) SQL queries and recommend optimal indexes
Arguments
-
max_index_size_mb -
integerMax index size in MB Default:10000 -
method -
stringMethod to use for analysis Allowed values: dta, llm Default:dta -
queriesrequired -
arrayList of Query strings to analyze
analyze_workload_indexes Analyze frequently executed queries in the database and recommend optimal indexes
Arguments
-
max_index_size_mb -
integerMax index size in MB Default:10000 -
method -
stringMethod to use for analysis Allowed values: dta, llm Default:dta
execute_sql Execute any SQL query
Arguments
-
sql -
stringSQL to run Default:all
explain_query Explains the execution plan for a SQL query, showing how the database will execute it and provides detailed cost estimates.
Arguments
-
analyze -
booleanWhen True, actually runs the query to show real execution statistics instead of estimates. Takes longer but provides more accurate information. Default:false -
hypothetical_indexes -
arrayA list of hypothetical indexes to simulate. Each index must be a dictionary with these keys: - 'table': The table name to add the index to (e.g., 'users') - 'columns': List of column names to include in the index (e.g., ['email'] or ['last_name', 'first_name']) - 'using': Optional index method (default: 'btree', other options include 'hash', 'gist', etc.) Examples: [ {"table": "users", "columns": ["email"], "using": "btree"}, {"table": "orders", "columns": ["user_id", "created_at"]} ] If there is no hypothetical index, you can pass an empty list. Default:[] -
sqlrequired -
stringSQL query to explain
get_object_details Show detailed information about a database object
Arguments
-
object_namerequired -
stringObject name -
object_type -
stringObject type: 'table', 'view', 'sequence', or 'extension' Default:table -
schema_namerequired -
stringSchema name
get_top_queries Reports the slowest or most resource-intensive queries using data from the 'pg_stat_statements' extension.
Arguments
-
limit -
integerNumber of queries to return when ranking based on mean_time or total_time Default:10 -
sort_by -
stringRanking criteria: 'total_time' for total execution time or 'mean_time' for mean execution time per call, or 'resources' for resource-intensive queries Default:resources
list_objects List objects in a schema
Arguments
-
object_type -
stringObject type: 'table', 'view', 'sequence', or 'extension' Default:table -
schema_namerequired -
stringSchema name