Skip to main content
Glama

analyze_query_indexes

Analyze SQL queries to recommend optimal indexes for improved PostgreSQL database performance and query efficiency.

Instructions

Analyze a list of (up to 10) SQL queries and recommend optimal indexes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queriesYesList of Query strings to analyze
max_index_size_mbNoMax index size in MB
methodNoMethod to use for analysisdta

Implementation Reference

  • The analyze_query_indexes tool handler is implemented in src/postgres_mcp/server.py. It registers as an MCP tool, validates the input queries, and utilizes either DatabaseTuningAdvisor or LLMOptimizerTool to generate index recommendations.
    @mcp.tool(description="Analyze a list of (up to 10) SQL queries and recommend optimal indexes")
    @validate_call
    async def analyze_query_indexes(
        queries: list[str] = Field(description="List of Query strings to analyze"),
        max_index_size_mb: int = Field(description="Max index size in MB", default=10000),
        method: Literal["dta", "llm"] = Field(description="Method to use for analysis", default="dta"),
    ) -> ResponseType:
        """Analyze a list of SQL queries and recommend optimal indexes."""
        if len(queries) == 0:
            return format_error_response("Please provide a non-empty list of queries to analyze.")
        if len(queries) > MAX_NUM_INDEX_TUNING_QUERIES:
            return format_error_response(f"Please provide a list of up to {MAX_NUM_INDEX_TUNING_QUERIES} queries to analyze.")
    
        try:
            sql_driver = await get_sql_driver()
            if method == "dta":
                index_tuning = DatabaseTuningAdvisor(sql_driver)
            else:
                index_tuning = LLMOptimizerTool(sql_driver)
            dta_tool = TextPresentation(sql_driver, index_tuning)
            result = await dta_tool.analyze_queries(queries=queries, max_index_size_mb=max_index_size_mb)
            return format_text_response(result)
        except Exception as e:
            logger.error(f"Error analyzing queries: {e}")
            return format_error_response(str(e))
Behavior3/5

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

With no annotations provided, the description must carry full behavioral disclosure. It successfully discloses the input cardinality limit (10 queries), but fails to describe the output format, computational cost implications, or whether this is a safe read-only operation versus potentially expensive.

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?

Perfectly concise single sentence with zero waste. The parenthetical '(up to 10)' efficiently packs a critical constraint without verbosity. Information density is high and front-loaded.

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?

For a 3-parameter tool with no output schema, the description is adequate but incomplete. It omits what the analysis returns (DDL recommendations? Score ratings? Impact estimates?) and doesn't explain the behavioral difference between 'dta' and 'llm' methods defined in the enum.

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 coverage is 100%, establishing a baseline of 3. The description adds valuable semantic context that '(up to 10)' queries are accepted, which is cardinality information not present in the schema's 'List of Query strings' description. This meaningfully constrains user expectations beyond the raw schema.

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 provides a specific verb ('Analyze') and resource ('SQL queries'/'indexes') and includes the critical constraint '(up to 10)' which implicitly distinguishes this from the sibling analyze_workload_indexes. However, it doesn't explicitly reference sibling alternatives to make the distinction crystal clear.

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 'up to 10' limit implies this is for targeted analysis rather than bulk workload assessment, suggesting when to prefer analyze_workload_indexes instead. However, it lacks explicit 'when to use/when not to use' guidance or named alternatives.

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/moecodeshere/mcptrial'

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