Skip to main content
Glama

describe_view

Retrieve the SQL definition and column structure of PostgreSQL views to understand database schema and query logic.

Instructions

Get the definition and columns of a view.

Args:
    view_name: Name of the view
    schema: Schema name (default: public)
    
Returns:
    View definition SQL and column list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
view_nameYes
schemaNopublic

Implementation Reference

  • Core handler function that executes the SQL queries to fetch view definition from information_schema.views and column details from information_schema.columns.
    def describe_view(self, view_name: str, schema: str = "public") -> dict[str, Any]:
        """Get view definition and columns.
        
        Args:
            view_name: View name
            schema: Schema name
            
        Returns:
            Dict with view definition and columns
        """
        result = {
            "name": view_name,
            "schema": schema,
            "definition": "",
            "columns": [],
        }
        
        with self.get_cursor() as cursor:
            # Get view definition
            cursor.execute("""
                SELECT view_definition
                FROM information_schema.views
                WHERE table_schema = %s AND table_name = %s
            """, (schema, view_name))
            row = cursor.fetchone()
            if row:
                result["definition"] = row["view_definition"]
            
            # Get columns
            cursor.execute("""
                SELECT 
                    column_name,
                    data_type,
                    is_nullable
                FROM information_schema.columns 
                WHERE table_schema = %s AND table_name = %s
                ORDER BY ordinal_position
            """, (schema, view_name))
            result["columns"] = [dict(row) for row in cursor.fetchall()]
        
        return result
  • MCP tool registration using @mcp.tool() decorator. This is the entry point for the tool, which delegates to the PostgresClient instance and adds error handling and not-found response.
    @mcp.tool()
    @handle_db_error
    def describe_view(view_name: str, schema: str = "public") -> dict:
        """Get the definition and columns of a view.
        
        Args:
            view_name: Name of the view
            schema: Schema name (default: public)
            
        Returns:
            View definition SQL and column list
        """
        client = get_client()
        result = client.describe_view(view_name, schema)
        
        if not result["definition"]:
            return not_found_response("View", f"{schema}.{view_name}")
        
        return result
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses this is a read operation ('Get') and specifies the return format ('View definition SQL and column list'), which is good behavioral context. However, it doesn't mention potential errors (e.g., if view doesn't exist), permissions needed, or whether this is a lightweight vs. expensive operation.

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 perfectly structured and concise: a clear purpose statement followed by organized Args and Returns sections. Every sentence earns its place, with no wasted words, and information is front-loaded appropriately.

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?

For a 2-parameter read tool with no annotations and no output schema, the description provides good coverage: clear purpose, parameter explanations, and return format. It's mostly complete but could benefit from mentioning error conditions or performance characteristics given the database 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 description adds meaningful context beyond the 0% schema coverage. It explains that 'view_name' is the 'Name of the view' and 'schema' is 'Schema name (default: public)', providing essential semantic understanding that the bare schema lacks. The only gap is not explaining format expectations for these parameters.

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 tool's purpose with specific verbs ('Get the definition and columns') and resource ('of a view'), distinguishing it from siblings like describe_table (for tables) and list_views (which lists views without details). It precisely communicates what information will be retrieved.

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

Usage Guidelines4/5

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

The description implies usage context by specifying it's for retrieving view metadata, but doesn't explicitly state when to use this vs. alternatives like describe_table or list_views. It provides clear context about what the tool does but lacks explicit comparison or exclusion guidance.

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