Skip to main content
Glama

list_views

Retrieve all view names from a PostgreSQL schema to analyze database structure and understand available data perspectives.

Instructions

List all views in a schema.

Args:
    schema: Schema name (default: public)
    
Returns:
    List of views with name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNopublic

Implementation Reference

  • MCP tool handler for 'list_views'. Registered via @mcp.tool() decorator. Executes the tool logic by calling PostgresClient.list_views() and formatting the response using ViewSummary models.
    @mcp.tool()
    @handle_db_error
    def list_views(schema: str = "public") -> dict:
        """List all views in a schema.
        
        Args:
            schema: Schema name (default: public)
            
        Returns:
            List of views with name
        """
        client = get_client()
        views = client.list_views(schema)
        
        return {
            "schema": schema,
            "views": [ViewSummary.from_row(v).model_dump() for v in views],
        }
  • The @mcp.tool() decorator registers the list_views function as an MCP tool.
    @mcp.tool()
  • Pydantic BaseModel defining the output schema for view summaries. Used to serialize raw database rows into structured responses.
    class ViewSummary(BaseModel):
        """View info for list responses."""
        
        name: str
        schema_name: str = "public"
        
        @classmethod
        def from_row(cls, row: dict) -> "ViewSummary":
            return cls(
                name=row.get("table_name", ""),
                schema_name=row.get("table_schema", "public"),
            )
  • Core helper method in PostgresClient that executes the SQL query to retrieve views from information_schema.views.
    def list_views(self, schema: str = "public") -> list[dict]:
        """List views in a schema.
        
        Args:
            schema: Schema name
            
        Returns:
            List of view dicts
        """
        query = """
            SELECT table_name, table_schema
            FROM information_schema.views 
            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()]
Behavior2/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 action ('List all views') and return format ('List of views with name'), but lacks details on permissions, pagination, error handling, or whether it's read-only. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 appropriately sized and front-loaded, with the core purpose stated first followed by structured Args and Returns sections. Every sentence earns its place without redundancy, making it efficient and easy to parse.

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no output schema, no annotations), the description is somewhat complete but has gaps. It covers the purpose and return format, yet lacks usage guidelines and detailed behavioral context. For a simple list tool, it's adequate but not fully comprehensive.

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

Parameters3/5

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

The description adds minimal semantics beyond the input schema, which has 0% description coverage. It explains the 'schema' parameter as 'Schema name (default: public)', matching the schema's default but not providing additional context like valid values or examples. With one parameter and low schema coverage, it partially compensates but remains basic.

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

Purpose4/5

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

The description clearly states the verb ('List') and resource ('views in a schema'), making the purpose specific and understandable. It distinguishes from siblings like list_tables or list_functions by focusing on views, though it doesn't explicitly contrast them. The description avoids tautology by not just restating the tool name.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. While it implicitly targets views, it doesn't mention when to choose list_views over other list_* tools or how it relates to describe_view. There's no context on prerequisites or exclusions, leaving usage unclear.

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