list_schemas
Retrieve all schemas from a PostgreSQL database to view their names and owners for database exploration and management.
Instructions
List all schemas in the PostgreSQL database.
Returns:
List of schemas with name and owner
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- postgres_mcp/server.py:126-140 (handler)MCP tool handler for 'list_schemas': calls PostgresClient.list_schemas() and formats output using SchemaSummary models.@mcp.tool() @handle_db_error def list_schemas() -> dict: """List all schemas in the PostgreSQL database. Returns: List of schemas with name and owner """ client = get_client() schemas = client.list_schemas() return { "schemas": [SchemaSummary.from_row(s).model_dump() for s in schemas], }
- postgres_mcp/postgres_client.py:183-200 (handler)Core handler logic in PostgresClient: executes SQL query to fetch schemas from information_schema.schemata, excluding system schemas.def list_schemas(self) -> list[dict]: """List all schemas in the database. Returns: List of schema dicts with name and owner """ query = """ SELECT schema_name, schema_owner FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_toast') ORDER BY schema_name """ with self.get_cursor() as cursor: cursor.execute(query) return [dict(row) for row in cursor.fetchall()]
- postgres_mcp/models.py:17-29 (schema)Pydantic model defining the output schema for schemas list, with from_row method to convert database rows.class SchemaSummary(BaseModel): """Schema info for list responses.""" name: str owner: Optional[str] = None @classmethod def from_row(cls, row: dict) -> "SchemaSummary": return cls( name=row.get("schema_name", ""), owner=row.get("schema_owner"), )
- postgres_mcp/server.py:126-140 (registration)Registration of the 'list_schemas' tool via FastMCP @mcp.tool() decorator.@mcp.tool() @handle_db_error def list_schemas() -> dict: """List all schemas in the PostgreSQL database. Returns: List of schemas with name and owner """ client = get_client() schemas = client.list_schemas() return { "schemas": [SchemaSummary.from_row(s).model_dump() for s in schemas], }