postgres-mcp-server
v1.0.7A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL database management capabilities for AI assistants
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
pg_analyze_database
Analyze PostgreSQL database configuration and performance
| Parameter | Type | Description |
|---|---|---|
analysisType | string | Type of analysis to perform |
connectionString | string | PostgreSQL connection string (optional if POSTGRES_CONNECTION_STRING environment variable or --connection-string CLI option is set) |
pg_debug_database
Debug common PostgreSQL issues
| Parameter | Type | Description |
|---|---|---|
issue * | string | |
connectionString | string | |
logLevel | string |
pg_manage_schema
Manage PostgreSQL schema - get schema info, create/alter tables, manage enums. Examples: operation="get_info" for table lists, operation="create_table" with tableName and columns, operation="get_enums" to list enums, operation="create_enum" with enumName and values
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: get_info (schema/table info), create_table (new table), alter_table (modify table), get_enums (list ENUMs), create_enum (new ENUM) |
columns | array | Column definitions (required for create_table) |
connectionString | string | PostgreSQL connection string (optional) |
enumName | string | ENUM name (optional for get_enums to filter, required for create_enum) |
ifNotExists | boolean | Include IF NOT EXISTS clause (for create_enum) |
operations | array | Alter operations (required for alter_table) |
schema | string | Schema name (defaults to public) |
tableName | string | Table name (optional for get_info to get specific table info, required for create_table/alter_table) |
values | array | ENUM values (required for create_enum) |
pg_manage_functions
Manage PostgreSQL functions - get, create, or drop functions with a single tool. Examples: operation="get" to list functions, operation="create" with functionName="test_func", parameters="" (empty for no params), returnType="TEXT", functionBody="SELECT 'Hello'"
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation to perform: get (list/info), create (new function), or drop (remove function) |
cascade | boolean | Whether to include CASCADE clause (for drop operation) |
connectionString | string | PostgreSQL connection string (optional) |
functionBody | string | Function body code (required for create operation) |
functionName | string | Name of the function (required for create/drop, optional for get to filter) |
ifExists | boolean | Whether to include IF EXISTS clause (for drop operation) |
language | string | Function language (defaults to plpgsql for create) |
parameters | string | Function parameters - required for create operation, required for drop when function is overloaded. Use empty string "" for functions with no parameters |
replace | boolean | Whether to replace the function if it exists (for create operation) |
returnType | string | Return type of the function (required for create operation) |
schema | string | Schema name (defaults to public) |
security | string | Function security context (defaults to INVOKER for create) |
volatility | string | Function volatility (defaults to VOLATILE for create) |
pg_manage_triggers
Manage PostgreSQL triggers - get, create, drop, and enable/disable triggers. Examples: operation="get" to list triggers, operation="create" with triggerName, tableName, functionName, operation="drop" with triggerName and tableName, operation="set_state" with triggerName, tableName, enable
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: get (list triggers), create (new trigger), drop (remove trigger), set_state (enable/disable trigger) |
cascade | boolean | Include CASCADE clause (for drop operation) |
connectionString | string | PostgreSQL connection string (optional) |
enable | boolean | Whether to enable the trigger (required for set_state operation) |
events | array | Trigger events (for create operation, defaults to ["INSERT"]) |
forEach | string | FOR EACH ROW or STATEMENT (for create operation, defaults to ROW) |
functionName | string | Function name (required for create operation) |
ifExists | boolean | Include IF EXISTS clause (for drop operation) |
replace | boolean | Whether to replace trigger if exists (for create operation) |
schema | string | Schema name (defaults to public) |
tableName | string | Table name (optional filter for get, required for create/drop/set_state) |
timing | string | Trigger timing (for create operation, defaults to AFTER) |
triggerName | string | Trigger name (required for create/drop/set_state) |
when | string | WHEN clause condition (for create operation) |
pg_manage_indexes
Manage PostgreSQL indexes - get, create, drop, reindex, and analyze usage with a single tool. Examples: operation="get" to list indexes, operation="create" with indexName, tableName, columns, operation="analyze_usage" for performance analysis
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: get (list indexes), create (new index), drop (remove index), reindex (rebuild), analyze_usage (find unused/duplicate) |
cascade | boolean | Include CASCADE clause (for drop operation) |
columns | array | Column names for the index (required for create operation) |
concurrent | boolean | Create/drop index concurrently (for create/drop operations) |
connectionString | string | PostgreSQL connection string (optional) |
ifExists | boolean | Include IF EXISTS clause (for drop operation) |
ifNotExists | boolean | Include IF NOT EXISTS clause (for create operation) |
includeStats | boolean | Include usage statistics (for get operation) |
indexName | string | Index name (required for create/drop) |
method | string | Index method (for create operation, defaults to btree) |
minSizeBytes | number | Minimum index size in bytes (for analyze_usage operation) |
schema | string | Schema name (defaults to public) |
showDuplicates | boolean | Detect duplicate indexes (for analyze_usage operation) |
showUnused | boolean | Include unused indexes (for analyze_usage operation) |
tableName | string | Table name (optional for get/analyze_usage, required for create) |
target | string | Target name for reindex (required for reindex operation) |
type | string | Type of target for reindex (required for reindex operation) |
unique | boolean | Create unique index (for create operation) |
where | string | WHERE clause for partial index (for create operation) |
pg_manage_constraints
Manage PostgreSQL constraints - get, create foreign keys, drop foreign keys, create constraints, drop constraints. Examples: operation="get" to list constraints, operation="create_fk" with constraintName, tableName, columnNames, referencedTable, referencedColumns
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: get (list constraints), create_fk (foreign key), drop_fk (drop foreign key), create (constraint), drop (constraint) |
cascade | boolean | Include CASCADE clause (for drop_fk/drop operations) |
checkExpression | string | Check expression (for create operation with check constraints) |
columnNames | array | Column names in the table (required for create_fk) |
connectionString | string | PostgreSQL connection string (optional) |
constraintName | string | Constraint name (required for create_fk/drop_fk/create/drop) |
constraintType | string | Filter by constraint type (for get operation) |
constraintTypeCreate | string | Type of constraint to create (for create operation) |
deferrable | boolean | Make constraint deferrable (for create_fk/create operations) |
ifExists | boolean | Include IF EXISTS clause (for drop_fk/drop operations) |
initiallyDeferred | boolean | Initially deferred (for create_fk/create operations) |
onDelete | string | ON DELETE action (for create_fk) |
onUpdate | string | ON UPDATE action (for create_fk) |
referencedColumns | array | Referenced column names (required for create_fk) |
referencedSchema | string | Referenced table schema (for create_fk, defaults to same as table schema) |
referencedTable | string | Referenced table name (required for create_fk) |
schema | string | Schema name (defaults to public) |
tableName | string | Table name (optional filter for get, required for create_fk/drop_fk/create/drop) |
pg_manage_rls
Manage PostgreSQL Row-Level Security - enable/disable RLS and manage policies. Examples: operation="enable" with tableName="users", operation="create_policy" with tableName, policyName, using, check
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: enable/disable RLS, create_policy, edit_policy, drop_policy, get_policies |
check | string | WITH CHECK expression for policy (optional for create_policy/edit_policy) |
command | string | Command the policy applies to (for create_policy) |
connectionString | string | PostgreSQL connection string (optional) |
ifExists | boolean | Include IF EXISTS clause (for drop_policy) |
policyName | string | Policy name (required for create_policy/edit_policy/drop_policy) |
replace | boolean | Whether to replace policy if exists (for create_policy) |
role | string | Role the policy applies to (for create_policy) |
roles | array | List of roles for policy (for edit_policy) |
schema | string | Schema name (defaults to public) |
tableName | string | Table name (required for enable/disable/create_policy/edit_policy/drop_policy, optional filter for get_policies) |
using | string | USING expression for policy (required for create_policy, optional for edit_policy) |
pg_manage_users
Manage PostgreSQL users and permissions - create, drop, alter users, grant/revoke permissions. Examples: operation="create" with username="testuser", operation="grant" with username, permissions, target, targetType
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: create (new user), drop (remove user), alter (modify user), grant (permissions), revoke (permissions), get_permissions (view permissions), list (all users) |
cascade | boolean | Include CASCADE to drop owned objects (for drop/revoke operations) |
connectionLimit | number | Maximum number of connections (for create/alter operations) |
connectionString | string | PostgreSQL connection string (optional) |
createdb | boolean | Allow user to create databases (for create/alter operations) |
createrole | boolean | Allow user to create roles (for create/alter operations) |
ifExists | boolean | Include IF EXISTS clause (for drop operation) |
includeSystemRoles | boolean | Include system roles (for list operation) |
inherit | boolean | Inherit privileges from parent roles (for create/alter operations) |
login | boolean | Allow user to login (for create/alter operations) |
password | string | Password for the user (for create operation) |
permissions | array | Permissions to grant/revoke: ["SELECT", "INSERT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", "ALL"] |
replication | boolean | Allow replication privileges (for create/alter operations) |
schema | string | Filter by schema (for get_permissions operation) |
superuser | boolean | Grant superuser privileges (for create/alter operations) |
target | string | Target object name (for grant/revoke operations) |
targetType | string | Type of target object (for grant/revoke operations) |
username | string | Username (required for create/drop/alter/grant/revoke/get_permissions, optional filter for list) |
validUntil | string | Password expiration date YYYY-MM-DD (for create/alter operations) |
withGrantOption | boolean | Allow user to grant these permissions to others (for grant operation) |
pg_manage_query
Manage PostgreSQL query analysis and performance - operation="explain" for EXPLAIN plans, operation="get_slow_queries" for slow query analysis, operation="get_stats" for query statistics, operation="reset_stats" for clearing statistics
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: explain (EXPLAIN/EXPLAIN ANALYZE query), get_slow_queries (find slow queries from pg_stat_statements), get_stats (query statistics with cache hit ratios), reset_stats (reset pg_stat_stateme… |
analyze | boolean | Use EXPLAIN ANALYZE - actually executes the query (for explain operation) |
buffers | boolean | Include buffer usage information (for explain operation) |
connectionString | string | |
costs | boolean | Include cost estimates (for explain operation) |
format | string | Output format (for explain operation) |
includeNormalized | boolean | Include normalized query text (for get_slow_queries operation) |
limit | number | Number of slow queries to return (for get_slow_queries operation) |
minCalls | number | Minimum number of calls (for get_stats operation) |
minDuration | number | Minimum average duration in milliseconds (for get_slow_queries operation) |
orderBy | string | Sort order (for get_slow_queries and get_stats operations) |
query | string | SQL query to explain (required for explain operation) |
queryId | string | Specific query ID to reset (for reset_stats operation, resets all if not provided) |
queryPattern | string | Filter queries containing this pattern (for get_stats operation) |
verbose | boolean | Include verbose output (for explain operation) |
pg_execute_query
Execute SELECT queries and data retrieval operations - operation="select/count/exists" with query and optional parameters. Examples: operation="select", query="SELECT * FROM users WHERE created_at > $1", parameters=["2024-01-01"]
| Parameter | Type | Description |
|---|---|---|
operation * | string | Query operation: select (fetch rows), count (count rows), exists (check existence) |
query * | string | SQL SELECT query to execute |
connectionString | string | PostgreSQL connection string (optional) |
limit | number | Maximum number of rows to return (safety limit) |
parameters | array | Parameter values for prepared statement placeholders ($1, $2, etc.) |
timeout | number | Query timeout in milliseconds |
pg_execute_mutation
Execute data modification operations (INSERT/UPDATE/DELETE/UPSERT) - operation="insert/update/delete/upsert" with table and data. Examples: operation="insert", table="users", data={"name":"John","email":"john@example.com"}
| Parameter | Type | Description |
|---|---|---|
operation * | string | Mutation operation: insert (add rows), update (modify rows), delete (remove rows), upsert (insert or update) |
table * | string | Table name for the operation |
conflictColumns | array | Columns for conflict resolution in upsert (ON CONFLICT) |
connectionString | string | PostgreSQL connection string (optional) |
data | object | Data object with column-value pairs (required for insert/update/upsert) |
returning | string | RETURNING clause to get back inserted/updated data |
schema | string | Schema name (defaults to public) |
where | string | WHERE clause for update/delete operations (without WHERE keyword) |
pg_execute_sql
Execute arbitrary SQL statements - sql="ANY_VALID_SQL" with optional parameters and transaction support. Examples: sql="CREATE INDEX ...", sql="WITH complex_cte AS (...) SELECT ...", transactional=true
| Parameter | Type | Description |
|---|---|---|
sql * | string | SQL statement to execute (can be any valid PostgreSQL SQL) |
connectionString | string | PostgreSQL connection string (optional) |
expectRows | boolean | Whether to expect rows back (false for statements like CREATE, DROP, etc.) |
parameters | array | Parameter values for prepared statement placeholders ($1, $2, etc.) |
timeout | number | Query timeout in milliseconds |
transactional | boolean | Whether to wrap in a transaction |
pg_manage_comments
Manage PostgreSQL object comments - get, set, remove comments on tables, columns, functions, and other database objects. Examples: operation="get" with objectType="table", objectName="users", operation="set" with comment text, operation="bulk_get" for discovery
| Parameter | Type | Description |
|---|---|---|
operation * | string | Operation: get (retrieve comments), set (add/update comment), remove (delete comment), bulk_get (discovery mode) |
columnName | string | Column name (required when objectType is "column") |
comment | string | Comment text (required for set operation) |
connectionString | string | PostgreSQL connection string (optional) |
filterObjectType | string | Filter by object type in bulk_get operation |
includeSystemObjects | boolean | Include system objects in bulk_get (defaults to false) |
objectName | string | Name of the object (required for get/set/remove) |
objectType | string | Type of database object (required for get/set/remove) |
schema | string | Schema name (defaults to public, required for most object types) |
pg_export_table_data
Export table data to JSON or CSV format
| Parameter | Type | Description |
|---|---|---|
outputPath * | string | absolute path to save the exported data |
tableName * | string | |
connectionString | string | |
format | string | |
limit | integer | |
where | string |
pg_import_table_data
Import data from JSON or CSV file into a table
| Parameter | Type | Description |
|---|---|---|
inputPath * | string | absolute path to the file to import |
tableName * | string | |
connectionString | string | |
delimiter | string | |
format | string | |
truncateFirst | boolean |
pg_copy_between_databases
Copy data between two databases
| Parameter | Type | Description |
|---|---|---|
sourceConnectionString * | string | |
tableName * | string | |
targetConnectionString * | string | |
truncateTarget | boolean | |
where | string |
pg_monitor_database
Get real-time monitoring information for a PostgreSQL database
| Parameter | Type | Description |
|---|---|---|
alertThresholds | object | Alert thresholds |
connectionString | string | |
includeLocks | boolean | |
includeQueries | boolean | |
includeReplication | boolean | |
includeTables | boolean |