Skip to main content
Glama
nolleh
by nolleh

get_table_structure

Retrieve table structure details including columns, data types, and constraints from Vertica databases for schema analysis and query planning.

Instructions

Get the structure of a table including columns, data types, and constraints.

Args:
    ctx: FastMCP context for progress reporting and logging
    table_name: Name of the table to inspect
    schema: Schema name (default: public)

Returns:
    Table structure information as a string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
schemaNopublic

Implementation Reference

  • The main handler function for the 'get_table_structure' tool. It is decorated with @mcp.tool(), which serves as both the implementation and registration with the FastMCP server. The function connects to Vertica, queries v_catalog.columns for column info and v_catalog.constraint_columns for constraints, then formats and returns the table structure as a string.
    @mcp.tool()
    async def get_table_structure(
        ctx: Context,
        table_name: str,
        schema: str = "public"
    ) -> str:
        """Get the structure of a table including columns, data types, and constraints.
    
        Args:
            ctx: FastMCP context for progress reporting and logging
            table_name: Name of the table to inspect
            schema: Schema name (default: public)
    
        Returns:
            Table structure information as a string
        """
        await ctx.info(f"Getting structure for table: {schema}.{table_name}")
    
        # Get or create connection manager
        manager = await get_or_create_manager(ctx)
        if not manager:
            return "Error: Failed to initialize database connection. Check configuration."
    
        query = """
        SELECT
            column_name,
            data_type,
            character_maximum_length,
            numeric_precision,
            numeric_scale,
            is_nullable,
            column_default
        FROM v_catalog.columns
        WHERE table_schema = %s
        AND table_name = %s
        ORDER BY ordinal_position;
        """
    
        conn = None
        cursor = None
        try:
            conn = manager.get_connection()
            cursor = conn.cursor()
            cursor.execute(query, (schema, table_name))
            columns = cursor.fetchall()
    
            if not columns:
                return f"No table found: {schema}.{table_name}"
    
            # Get constraints
            cursor.execute("""
                SELECT
                    constraint_name,
                    constraint_type,
                    column_name
                FROM v_catalog.constraint_columns
                WHERE table_schema = %s
                AND table_name = %s;
            """, (schema, table_name))
            constraints = cursor.fetchall()
    
            # Format the output
            result = f"Table Structure for {schema}.{table_name}:\n\n"
            result += "Columns:\n"
            for col in columns:
                result += f"- {col[0]}: {col[1]}"
                if col[2]:  # character_maximum_length
                    result += f"({col[2]})"
                elif col[3]:  # numeric_precision
                    result += f"({col[3]},{col[4]})"
                result += f" {'NULL' if col[5] == 'YES' else 'NOT NULL'}"
                if col[6]:  # column_default
                    result += f" DEFAULT {col[6]}"
                result += "\n"
    
            if constraints:
                result += "\nConstraints:\n"
                for const in constraints:
                    result += f"- {const[0]} ({const[1]}): {const[2]}\n"
    
            return result
    
        except Exception as e:
            error_msg = f"Error getting table structure: {str(e)}"
            await ctx.error(error_msg)
            return error_msg
        finally:
            if cursor:
                cursor.close()
            if conn:
                manager.release_connection(conn)
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 mentions a 'ctx' parameter for 'progress reporting and logging' which hints at potential async/long-running behavior, but doesn't clarify permissions needed, rate limits, error conditions, or what 'structure information as a string' entails. For a read operation with zero annotation coverage, this leaves significant gaps.

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

Conciseness4/5

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

The description is well-structured with clear sections for purpose, arguments, and returns. It's appropriately sized with no redundant information, though the 'ctx' parameter explanation could be more concise as it's somewhat technical without added user value.

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 2 parameters with 0% schema coverage and no output schema, the description does a fair job explaining inputs and the return type. However, it lacks details on the output format (e.g., JSON, table), error handling, or examples, which would be helpful for a tool with no structured output schema.

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?

Schema description coverage is 0%, so the description must compensate. It explains both parameters: 'table_name' as 'Name of the table to inspect' and 'schema' as 'Schema name (default: public)', adding clear meaning beyond the bare schema. However, it doesn't detail format constraints or examples 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 specific action ('Get the structure of a table') and the resources involved ('columns, data types, and constraints'). It distinguishes itself from sibling tools like list_indexes or list_views by focusing on table metadata rather than indexes or views.

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 inspecting table metadata but provides no explicit guidance on when to use this tool versus alternatives like list_views or execute_query. There's no mention of prerequisites, exclusions, or specific scenarios where this tool is preferred.

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/nolleh/mcp-vertica'

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