Skip to main content
Glama

list_indexes

Retrieve all indexes for a PostgreSQL table to analyze structure, optimize queries, and manage database performance.

Instructions

List all indexes for a table.

Args:
    table_name: Name of the table
    schema: Schema name (default: public)
    
Returns:
    List of indexes with name, columns, type, and size

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
schemaNopublic

Implementation Reference

  • MCP tool handler for 'list_indexes'. Decorated with @mcp.tool() for automatic registration. Calls PostgresClient.list_indexes and formats the response dictionary with index details including name, uniqueness, type, size, and definition.
    @mcp.tool()
    @handle_db_error
    def list_indexes(table_name: str, schema: str = "public") -> dict:
        """List all indexes for a table.
        
        Args:
            table_name: Name of the table
            schema: Schema name (default: public)
            
        Returns:
            List of indexes with name, columns, type, and size
        """
        client = get_client()
        indexes = client.list_indexes(table_name, schema)
        
        return {
            "table_name": table_name,
            "schema": schema,
            "indexes": [
                {
                    "name": idx["index_name"],
                    "is_unique": idx.get("is_unique", False),
                    "is_primary": idx.get("is_primary", False),
                    "type": idx.get("index_type", "btree"),
                    "size": format_bytes(idx.get("size_bytes")),
                    "definition": idx.get("definition", ""),
                }
                for idx in indexes
            ],
        }
  • Core implementation in PostgresClient class. Executes a SQL query joining pg_class, pg_index, pg_namespace, and pg_am to retrieve index details like name, uniqueness, primary status, type, definition, and size for the specified table and schema.
    def list_indexes(self, table_name: str, schema: str = "public") -> list[dict]:
        """List indexes for a table.
        
        Args:
            table_name: Table name
            schema: Schema name
            
        Returns:
            List of index dicts
        """
        query = """
            SELECT 
                i.relname AS index_name,
                t.relname AS table_name,
                ix.indisunique AS is_unique,
                ix.indisprimary AS is_primary,
                am.amname AS index_type,
                pg_get_indexdef(ix.indexrelid) AS definition,
                pg_relation_size(i.oid) AS size_bytes
            FROM pg_class t
            JOIN pg_index ix ON t.oid = ix.indrelid
            JOIN pg_class i ON i.oid = ix.indexrelid
            JOIN pg_namespace n ON n.oid = t.relnamespace
            JOIN pg_am am ON am.oid = i.relam
            WHERE n.nspname = %s
                AND t.relname = %s
            ORDER BY i.relname
        """
        with self.get_cursor() as cursor:
            cursor.execute(query, (schema, table_name))
            return [dict(row) for row in cursor.fetchall()]
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states this is a list operation, implying read-only behavior, but doesn't specify if it requires database permissions, how it handles non-existent tables, or if there are rate limits. The description adds minimal behavioral context beyond the basic action, leaving gaps for a tool with no annotation coverage.

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 well-structured. It starts with a clear purpose statement, followed by organized sections for 'Args' and 'Returns', making it easy to scan. Every sentence adds value without redundancy, and the information is front-loaded for quick understanding.

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 moderate complexity (2 parameters, no annotations, no output schema), the description is adequate but has gaps. It explains parameters and return values, but lacks behavioral details like error handling or performance implications. Without annotations or output schema, it should do more to cover usage context, but it meets a minimum viable level for a read-only list tool.

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 significant value beyond the input schema, which has 0% schema description coverage. It explains that 'table_name' is the 'Name of the table' and 'schema' is the 'Schema name (default: public)', clarifying parameter meanings that aren't in the schema. However, it doesn't detail constraints like valid schema names or table naming conventions, slightly limiting its completeness.

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 tool's purpose with a specific verb ('List') and resource ('indexes for a table'), making it easy to understand what it does. It distinguishes from siblings like 'list_tables' or 'list_constraints' by focusing specifically on indexes. However, it doesn't explicitly differentiate from all siblings (e.g., 'describe_table' might also provide index information), keeping it from a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose 'list_indexes' over 'describe_table' (which might include index details) or 'list_constraints' (which might overlap with unique indexes). There's no context about prerequisites, such as needing table existence or specific permissions.

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