PostgreSQL MCP Server
Python MCP server for PostgreSQL database inspection and querying
Versions
0.1.1latestTools 10
list_tables Returns a list of all table names in the public schema. Filters out system tables and returns only user-created tables. Returns: List[str]: List of table names in the public schema
describe_table Queries information_schema.columns to return column details for a table. Args: table_name (str): The name of the table to describe Returns: List[Dict[str, Any]]: List of column dictionaries with name, type, and nullability
execute_read_query Executes read-only SQL queries (SELECT, etc). Safe to auto-approve. Uses READ ONLY transaction mode to ensure no data modification can occur. Automatically rolls back any transaction to prevent accidental commits. Args: query (str): The SQL query to execute Returns: List[Dict[str, Any]]: Query results as a list of dictionaries, or a string with error hints Raises: ValueError: If query attempts to modify data
execute_write_query Executes data modification queries (INSERT, UPDATE, DELETE, DROP). Requires manual approval. Executes the query and explicitly commits the transaction. This tool should be used for any SQL statements that modify data or database structure. Args: query (str): The SQL query to execute Returns: str: A success message with the number of rows affected (if applicable)
explain_query Prepends EXPLAIN to the query to return the execution plan without running it. Args: query (str): The SQL query to explain Returns: List[Dict[str, Any]]: The EXPLAIN plan results
get_database_summary Returns a comprehensive summary of the database. Returns: Dict[str, Any]: Dictionary containing database name, PostgreSQL version, and table count
get_relationships Queries information_schema to find Foreign Keys pointing TO and FROM this table. Args: table_name (str): The name of the table to analyze for relationships Returns: List[Dict[str, Any]]: List of foreign key relationships including: - relationship_type: 'incoming' or 'outgoing' - foreign_table_name: The other table involved in the relationship - constraint_name: Name of the foreign key constraint - column_name: The column in this table - foreign_column_name: The column in the referenced table
analyze_indexes Returns all indexes, their columns, and sizes for the specified table. Uses pg_size_pretty to display human-readable sizes. Args: table_name (str): The name of the table to analyze indexes for Returns: List[Dict[str, Any]]: List of indexes with: - index_name: Name of the index - columns: List of column names in the index - is_unique: Whether the index enforces uniqueness - is_primary: Whether this is a primary key index - index_type: Type of index (btree, hash, etc.) - size: Human-readable size of the index
preview_table Returns the first 10 rows of a table (LIMIT 10). Useful for quickly inspecting table data without running full queries. Args: table_name (str): The name of the table to preview Returns: List[Dict[str, Any]]: List of up to 10 rows as dictionaries
search_sql_definitions Searches information_schema.routines or pg_proc for code containing the search_term. Finds functions, procedures, and other database objects that contain the search term in their definitions or bodies. Args: search_term (str): The term to search for in SQL definitions Returns: List[Dict[str, Any]]: List of matching routines with: - routine_name: Name of the function/procedure - routine_type: Type of routine (FUNCTION, PROCEDURE, etc.) - schema_name: Schema containing the routine - definition: The routine definition (truncated if too long)
Permissions 2
filesystem low env_vars low