list_tables
Retrieve all tables from a PostgreSQL schema to understand database structure. Specify a schema name to view its tables and their types.
Instructions
List all tables in a specific schema.
Args:
schema: Schema name to list tables from (default: public)
Returns:
List of tables with name and type
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | public |
Implementation Reference
- postgres_mcp/server.py:145-163 (handler)MCP tool handler for 'list_tables'. Fetches tables using PostgresClient and formats output using TableSummary models.@mcp.tool() @handle_db_error def list_tables(schema: str = "public") -> dict: """List all tables in a specific schema. Args: schema: Schema name to list tables from (default: public) Returns: List of tables with name and type """ client = get_client() tables = client.list_tables(schema) return { "schema": schema, "tables": [TableSummary.from_row(t).model_dump() for t in tables], }
- postgres_mcp/models.py:34-50 (schema)Pydantic model defining the output schema for table summaries in list_tables response.class TableSummary(BaseModel): """Table info for list responses.""" model_config = {"populate_by_name": True} name: str type: str = "BASE TABLE" schema_name: str = "public" @classmethod def from_row(cls, row: dict) -> "TableSummary": return cls( name=row.get("table_name", ""), type=row.get("table_type", "BASE TABLE"), schema_name=row.get("table_schema", "public"), )
- postgres_mcp/server.py:145-145 (registration)FastMCP decorator registering the list_tables function as an MCP tool.@mcp.tool()
- Core implementation in PostgresClient that queries information_schema.tables to list tables in a schema.def list_tables(self, schema: str = "public") -> list[dict]: """List all tables in a schema. Args: schema: Schema name (default: public) Returns: List of table dicts """ query = """ SELECT table_name, table_type, table_schema FROM information_schema.tables WHERE table_schema = %s ORDER BY table_name """ with self.get_cursor() as cursor: cursor.execute(query, (schema,)) return [dict(row) for row in cursor.fetchall()]