Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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], }
  • 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()]
  • 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"), )
  • 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], }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JaviMaligno/postgres-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server