Skip to main content
Glama
Cloud-Thinker-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))

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/Cloud-Thinker-AI/postgres-mcp-pro-plus'

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