Skip to main content
Glama
cloudthinker-ai

Postgres MCP Pro Plus

analyze_query_indexes

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

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 primary handler function for the 'analyze_query_indexes' tool. It is registered via the @mcp.tool decorator, defines the input schema using Pydantic Fields, validates input length, selects the analysis method (DTA or LLM), instantiates the appropriate optimizer and presentation tool, calls analyze_queries on it, and formats the response.
    @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))
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 the limit of 'up to 10' queries, which is useful, but fails to describe other key behaviors: it doesn't specify what the recommendations include (e.g., index types, columns), whether analysis is read-only or has side effects, performance implications, or output format. For a tool with no annotations, this leaves significant gaps in understanding its 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 a single, efficient sentence that front-loads the core purpose without unnecessary words. It directly states what the tool does and includes a key constraint ('up to 10'), making it easy to parse. Every part of the sentence earns its place, with no redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (analyzing queries for index optimization) and lack of annotations and output schema, the description is insufficiently complete. It doesn't explain what the recommendations entail, how they're presented, or any behavioral nuances like error handling or performance limits. For a tool with no structured output and no annotations, more detail is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning beyond implying the 'queries' parameter handles up to 10 items. It doesn't explain why 'max_index_size_mb' or 'method' matter, or how they affect recommendations. Given the high schema coverage, a baseline score of 3 is appropriate, as the description doesn't compensate but doesn't detract either.

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: 'Analyze a list of (up to 10) SQL queries and recommend optimal indexes.' It specifies the verb ('analyze'), resource ('SQL queries'), and outcome ('recommend optimal indexes'), making it easy to understand. However, it doesn't explicitly differentiate from siblings like 'analyze_workload_indexes' or 'explain_query', which prevents 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 siblings like 'analyze_workload_indexes' for broader analysis or 'explain_query' for single-query optimization, nor does it specify prerequisites or exclusions. This lack of context leaves the agent guessing about appropriate usage scenarios.

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/cloudthinker-ai/postgres-mcp-pro-plus'

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