postgres-mcp-server

v1.0.7
@henkey/postgres-mcp-server Checked 1 day ago Published 5 months ago

A 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

ParameterTypeDescription
analysisTypestringType of analysis to perform
connectionStringstringPostgreSQL connection string (optional if POSTGRES_CONNECTION_STRING environment variable or --connection-string CLI option is set)

pg_debug_database

Debug common PostgreSQL issues

ParameterTypeDescription
issue *string
connectionStringstring
logLevelstring

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

ParameterTypeDescription
operation *stringOperation: get_info (schema/table info), create_table (new table), alter_table (modify table), get_enums (list ENUMs), create_enum (new ENUM)
columnsarrayColumn definitions (required for create_table)
connectionStringstringPostgreSQL connection string (optional)
enumNamestringENUM name (optional for get_enums to filter, required for create_enum)
ifNotExistsbooleanInclude IF NOT EXISTS clause (for create_enum)
operationsarrayAlter operations (required for alter_table)
schemastringSchema name (defaults to public)
tableNamestringTable name (optional for get_info to get specific table info, required for create_table/alter_table)
valuesarrayENUM 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'"

ParameterTypeDescription
operation *stringOperation to perform: get (list/info), create (new function), or drop (remove function)
cascadebooleanWhether to include CASCADE clause (for drop operation)
connectionStringstringPostgreSQL connection string (optional)
functionBodystringFunction body code (required for create operation)
functionNamestringName of the function (required for create/drop, optional for get to filter)
ifExistsbooleanWhether to include IF EXISTS clause (for drop operation)
languagestringFunction language (defaults to plpgsql for create)
parametersstringFunction parameters - required for create operation, required for drop when function is overloaded. Use empty string "" for functions with no parameters
replacebooleanWhether to replace the function if it exists (for create operation)
returnTypestringReturn type of the function (required for create operation)
schemastringSchema name (defaults to public)
securitystringFunction security context (defaults to INVOKER for create)
volatilitystringFunction 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

ParameterTypeDescription
operation *stringOperation: get (list triggers), create (new trigger), drop (remove trigger), set_state (enable/disable trigger)
cascadebooleanInclude CASCADE clause (for drop operation)
connectionStringstringPostgreSQL connection string (optional)
enablebooleanWhether to enable the trigger (required for set_state operation)
eventsarrayTrigger events (for create operation, defaults to ["INSERT"])
forEachstringFOR EACH ROW or STATEMENT (for create operation, defaults to ROW)
functionNamestringFunction name (required for create operation)
ifExistsbooleanInclude IF EXISTS clause (for drop operation)
replacebooleanWhether to replace trigger if exists (for create operation)
schemastringSchema name (defaults to public)
tableNamestringTable name (optional filter for get, required for create/drop/set_state)
timingstringTrigger timing (for create operation, defaults to AFTER)
triggerNamestringTrigger name (required for create/drop/set_state)
whenstringWHEN 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

ParameterTypeDescription
operation *stringOperation: get (list indexes), create (new index), drop (remove index), reindex (rebuild), analyze_usage (find unused/duplicate)
cascadebooleanInclude CASCADE clause (for drop operation)
columnsarrayColumn names for the index (required for create operation)
concurrentbooleanCreate/drop index concurrently (for create/drop operations)
connectionStringstringPostgreSQL connection string (optional)
ifExistsbooleanInclude IF EXISTS clause (for drop operation)
ifNotExistsbooleanInclude IF NOT EXISTS clause (for create operation)
includeStatsbooleanInclude usage statistics (for get operation)
indexNamestringIndex name (required for create/drop)
methodstringIndex method (for create operation, defaults to btree)
minSizeBytesnumberMinimum index size in bytes (for analyze_usage operation)
schemastringSchema name (defaults to public)
showDuplicatesbooleanDetect duplicate indexes (for analyze_usage operation)
showUnusedbooleanInclude unused indexes (for analyze_usage operation)
tableNamestringTable name (optional for get/analyze_usage, required for create)
targetstringTarget name for reindex (required for reindex operation)
typestringType of target for reindex (required for reindex operation)
uniquebooleanCreate unique index (for create operation)
wherestringWHERE 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

ParameterTypeDescription
operation *stringOperation: get (list constraints), create_fk (foreign key), drop_fk (drop foreign key), create (constraint), drop (constraint)
cascadebooleanInclude CASCADE clause (for drop_fk/drop operations)
checkExpressionstringCheck expression (for create operation with check constraints)
columnNamesarrayColumn names in the table (required for create_fk)
connectionStringstringPostgreSQL connection string (optional)
constraintNamestringConstraint name (required for create_fk/drop_fk/create/drop)
constraintTypestringFilter by constraint type (for get operation)
constraintTypeCreatestringType of constraint to create (for create operation)
deferrablebooleanMake constraint deferrable (for create_fk/create operations)
ifExistsbooleanInclude IF EXISTS clause (for drop_fk/drop operations)
initiallyDeferredbooleanInitially deferred (for create_fk/create operations)
onDeletestringON DELETE action (for create_fk)
onUpdatestringON UPDATE action (for create_fk)
referencedColumnsarrayReferenced column names (required for create_fk)
referencedSchemastringReferenced table schema (for create_fk, defaults to same as table schema)
referencedTablestringReferenced table name (required for create_fk)
schemastringSchema name (defaults to public)
tableNamestringTable 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

ParameterTypeDescription
operation *stringOperation: enable/disable RLS, create_policy, edit_policy, drop_policy, get_policies
checkstringWITH CHECK expression for policy (optional for create_policy/edit_policy)
commandstringCommand the policy applies to (for create_policy)
connectionStringstringPostgreSQL connection string (optional)
ifExistsbooleanInclude IF EXISTS clause (for drop_policy)
policyNamestringPolicy name (required for create_policy/edit_policy/drop_policy)
replacebooleanWhether to replace policy if exists (for create_policy)
rolestringRole the policy applies to (for create_policy)
rolesarrayList of roles for policy (for edit_policy)
schemastringSchema name (defaults to public)
tableNamestringTable name (required for enable/disable/create_policy/edit_policy/drop_policy, optional filter for get_policies)
usingstringUSING 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

ParameterTypeDescription
operation *stringOperation: create (new user), drop (remove user), alter (modify user), grant (permissions), revoke (permissions), get_permissions (view permissions), list (all users)
cascadebooleanInclude CASCADE to drop owned objects (for drop/revoke operations)
connectionLimitnumberMaximum number of connections (for create/alter operations)
connectionStringstringPostgreSQL connection string (optional)
createdbbooleanAllow user to create databases (for create/alter operations)
createrolebooleanAllow user to create roles (for create/alter operations)
ifExistsbooleanInclude IF EXISTS clause (for drop operation)
includeSystemRolesbooleanInclude system roles (for list operation)
inheritbooleanInherit privileges from parent roles (for create/alter operations)
loginbooleanAllow user to login (for create/alter operations)
passwordstringPassword for the user (for create operation)
permissionsarrayPermissions to grant/revoke: ["SELECT", "INSERT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", "ALL"]
replicationbooleanAllow replication privileges (for create/alter operations)
schemastringFilter by schema (for get_permissions operation)
superuserbooleanGrant superuser privileges (for create/alter operations)
targetstringTarget object name (for grant/revoke operations)
targetTypestringType of target object (for grant/revoke operations)
usernamestringUsername (required for create/drop/alter/grant/revoke/get_permissions, optional filter for list)
validUntilstringPassword expiration date YYYY-MM-DD (for create/alter operations)
withGrantOptionbooleanAllow 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

ParameterTypeDescription
operation *stringOperation: 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…
analyzebooleanUse EXPLAIN ANALYZE - actually executes the query (for explain operation)
buffersbooleanInclude buffer usage information (for explain operation)
connectionStringstring
costsbooleanInclude cost estimates (for explain operation)
formatstringOutput format (for explain operation)
includeNormalizedbooleanInclude normalized query text (for get_slow_queries operation)
limitnumberNumber of slow queries to return (for get_slow_queries operation)
minCallsnumberMinimum number of calls (for get_stats operation)
minDurationnumberMinimum average duration in milliseconds (for get_slow_queries operation)
orderBystringSort order (for get_slow_queries and get_stats operations)
querystringSQL query to explain (required for explain operation)
queryIdstringSpecific query ID to reset (for reset_stats operation, resets all if not provided)
queryPatternstringFilter queries containing this pattern (for get_stats operation)
verbosebooleanInclude 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"]

ParameterTypeDescription
operation *stringQuery operation: select (fetch rows), count (count rows), exists (check existence)
query *stringSQL SELECT query to execute
connectionStringstringPostgreSQL connection string (optional)
limitnumberMaximum number of rows to return (safety limit)
parametersarrayParameter values for prepared statement placeholders ($1, $2, etc.)
timeoutnumberQuery 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"}

ParameterTypeDescription
operation *stringMutation operation: insert (add rows), update (modify rows), delete (remove rows), upsert (insert or update)
table *stringTable name for the operation
conflictColumnsarrayColumns for conflict resolution in upsert (ON CONFLICT)
connectionStringstringPostgreSQL connection string (optional)
dataobjectData object with column-value pairs (required for insert/update/upsert)
returningstringRETURNING clause to get back inserted/updated data
schemastringSchema name (defaults to public)
wherestringWHERE 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

ParameterTypeDescription
sql *stringSQL statement to execute (can be any valid PostgreSQL SQL)
connectionStringstringPostgreSQL connection string (optional)
expectRowsbooleanWhether to expect rows back (false for statements like CREATE, DROP, etc.)
parametersarrayParameter values for prepared statement placeholders ($1, $2, etc.)
timeoutnumberQuery timeout in milliseconds
transactionalbooleanWhether 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

ParameterTypeDescription
operation *stringOperation: get (retrieve comments), set (add/update comment), remove (delete comment), bulk_get (discovery mode)
columnNamestringColumn name (required when objectType is "column")
commentstringComment text (required for set operation)
connectionStringstringPostgreSQL connection string (optional)
filterObjectTypestringFilter by object type in bulk_get operation
includeSystemObjectsbooleanInclude system objects in bulk_get (defaults to false)
objectNamestringName of the object (required for get/set/remove)
objectTypestringType of database object (required for get/set/remove)
schemastringSchema name (defaults to public, required for most object types)

pg_export_table_data

Export table data to JSON or CSV format

ParameterTypeDescription
outputPath *stringabsolute path to save the exported data
tableName *string
connectionStringstring
formatstring
limitinteger
wherestring

pg_import_table_data

Import data from JSON or CSV file into a table

ParameterTypeDescription
inputPath *stringabsolute path to the file to import
tableName *string
connectionStringstring
delimiterstring
formatstring
truncateFirstboolean

pg_copy_between_databases

Copy data between two databases

ParameterTypeDescription
sourceConnectionString *string
tableName *string
targetConnectionString *string
truncateTargetboolean
wherestring

pg_monitor_database

Get real-time monitoring information for a PostgreSQL database

ParameterTypeDescription
alertThresholdsobjectAlert thresholds
connectionStringstring
includeLocksboolean
includeQueriesboolean
includeReplicationboolean
includeTablesboolean