Skip to main content
Glama
avantifellows

Avanti Fellows PostgreSQL MCP Server

Official

describe_table

Retrieve detailed PostgreSQL table schema information including column names, data types, nullability, defaults, primary keys, and foreign keys to understand database structure before querying.

Instructions

Get detailed schema information for a table.

Returns column names, types, nullability, and defaults.
Use this to understand table structure before querying.

Args:
    table_name: Name of the table
    schema_name: Schema name (default: public)

Returns:
    JSON with columns, primary keys, and foreign keys

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
schema_nameNopublic

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the describe_table tool. It fetches column information, primary keys, and foreign keys from PostgreSQL system catalogs and returns a JSON description of the table schema.
    @mcp.tool()
    async def describe_table(table_name: str, schema_name: str = "public") -> str:
        """Get detailed schema information for a table.
    
        Returns column names, types, nullability, and defaults.
        Use this to understand table structure before querying.
    
        Args:
            table_name: Name of the table
            schema_name: Schema name (default: public)
    
        Returns:
            JSON with columns, primary keys, and foreign keys
        """
        columns_sql = """
            SELECT
                column_name,
                data_type,
                is_nullable,
                column_default,
                character_maximum_length
            FROM information_schema.columns
            WHERE table_schema = $1 AND table_name = $2
            ORDER BY ordinal_position
        """
    
        pk_sql = """
            SELECT a.attname as column_name
            FROM pg_index i
            JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
            JOIN pg_class c ON c.oid = i.indrelid
            JOIN pg_namespace n ON n.oid = c.relnamespace
            WHERE i.indisprimary
            AND n.nspname = $1
            AND c.relname = $2
        """
    
        fk_sql = """
            SELECT
                kcu.column_name,
                ccu.table_schema AS foreign_schema,
                ccu.table_name AS foreign_table,
                ccu.column_name AS foreign_column
            FROM information_schema.table_constraints AS tc
            JOIN information_schema.key_column_usage AS kcu
                ON tc.constraint_name = kcu.constraint_name
                AND tc.table_schema = kcu.table_schema
            JOIN information_schema.constraint_column_usage AS ccu
                ON ccu.constraint_name = tc.constraint_name
            WHERE tc.constraint_type = 'FOREIGN KEY'
            AND tc.table_schema = $1
            AND tc.table_name = $2
        """
    
        try:
            async with get_connection() as conn:
                columns = await conn.fetch(columns_sql, schema_name, table_name)
                pks = await conn.fetch(pk_sql, schema_name, table_name)
                fks = await conn.fetch(fk_sql, schema_name, table_name)
    
                result = {
                    "table": f"{schema_name}.{table_name}",
                    "columns": [dict(row) for row in columns],
                    "primary_keys": [row["column_name"] for row in pks],
                    "foreign_keys": [dict(row) for row in fks],
                }
                return json.dumps(result, indent=2, default=str)
        except Exception as e:
            return json.dumps({"error": str(e)})
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 that this is a read operation (implied by 'Get') and describes the return format (JSON with columns, primary keys, foreign keys), which is helpful. However, it doesn't mention potential errors (e.g., if table doesn't exist), permissions needed, or rate limits, leaving some behavioral aspects unclear.

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: a clear purpose statement, usage guidance, and well-organized parameter/return sections. Every sentence earns its place, with no redundant information. The bullet-point style for Args and Returns enhances readability without wasting space.

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 moderate complexity (2 parameters, read-only operation) and the presence of an output schema (which handles return value documentation), the description is nearly complete. It covers purpose, usage, parameters, and return format adequately. The only minor gap is lack of error case documentation, but the output schema reduces the need for extensive return value explanation.

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 schema description coverage is 0%, so the description must compensate. It provides meaningful context for both parameters: table_name is clearly explained as 'Name of the table', and schema_name gets additional context with 'Schema name (default: public)', which clarifies its optional nature and typical value. This adds significant value beyond the bare schema.

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 ('Get detailed schema information') and resource ('for a table'), distinguishing it from siblings like list_tables (which lists tables) or query (which executes queries). It explicitly mentions what information is returned (column names, types, nullability, defaults), making the purpose unambiguous.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('Use this to understand table structure before querying'), which clearly differentiates it from query (for actual data retrieval) and sample_data (for data preview). It implicitly suggests alternatives like list_tables for table enumeration, making usage context clear.

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/avantifellows/mcp-postgres'

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