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],
        }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool lists schemas and describes the return format (name and owner), which adds useful context beyond basic functionality. However, it lacks details on permissions, rate limits, or error handling, leaving gaps for a tool with no annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by a concise explanation of returns. Every sentence earns its place by providing essential information without redundancy, making it highly efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is complete enough for a read-only listing operation. It covers purpose and return format adequately. However, it could improve by addressing potential limitations or linking to sibling tools for broader context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description does not add parameter details, which is appropriate, but it compensates by explaining the return values, enhancing understanding of the tool's output semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('List all schemas') and resource ('in the PostgreSQL database'), distinguishing it from sibling tools like list_tables or list_views by focusing on schemas. It provides a precise verb+resource combination that leaves no ambiguity about its function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for retrieving schema-level information but does not explicitly state when to use this tool versus alternatives like get_database_info (which might include schema details) or other list_* tools. No guidance is provided on exclusions or prerequisites, leaving usage context inferred rather than stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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