Skip to main content
Glama
rickyb30

DataPilot MCP Server

by rickyb30

suggest_query_optimizations

Analyze SQL queries to provide AI-powered optimization suggestions for improved database performance and efficiency.

Instructions

Get AI-powered suggestions for optimizing a SQL query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'suggest_query_optimizations'. It handles context logging, retrieves the OpenAI client, calls the optimization method, and returns the suggestions.
    @mcp.tool()
    async def suggest_query_optimizations(query: str, ctx: Context) -> str:
        """Get AI-powered suggestions for optimizing a SQL query"""
        await ctx.info(f"Analyzing query for optimization: {query[:100]}...")
        
        try:
            openai = await get_openai_client()
            optimizations = await openai.suggest_optimizations(query)
            await ctx.info("Generated optimization suggestions")
            return optimizations
            
        except Exception as e:
            logger.error(f"Error suggesting optimizations: {str(e)}")
            await ctx.error(f"Failed to suggest optimizations: {str(e)}")
            raise
  • The supporting method in OpenAIClient class that implements the core AI logic for query optimization using a tailored prompt and OpenAI chat completions.
    async def suggest_optimizations(self, query: str) -> str:
        """Suggest optimizations for a SQL query"""
        
        system_prompt = """
        You are a Snowflake SQL performance expert. Analyze the provided query and suggest optimizations.
        
        Consider:
        - Index usage and clustering keys
        - JOIN optimization
        - WHERE clause efficiency
        - Warehouse sizing recommendations
        - Query structure improvements
        - Snowflake-specific optimizations (clustering, materialized views, etc.)
        
        Provide specific, actionable recommendations.
        """
        
        user_prompt = f"""
        SQL Query to optimize:
        {query}
        
        Please provide optimization suggestions.
        """
        
        try:
            response = await self.client.chat.completions.create(
                model=self.model,
                messages=[
                    {"role": "system", "content": system_prompt},
                    {"role": "user", "content": user_prompt}
                ],
                temperature=0.2,
                max_tokens=800
            )
            
            optimization_suggestions = response.choices[0].message.content.strip()
            logger.info("Generated optimization suggestions")
            return optimization_suggestions
            
        except Exception as e:
            logger.error(f"Error generating optimizations: {str(e)}")
            raise Exception(f"Failed to generate optimization suggestions: {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 states the tool provides 'AI-powered suggestions' but doesn't elaborate on what that entails—e.g., whether it modifies the query, returns textual advice, requires specific permissions, has rate limits, or handles errors. For a tool that likely involves computational analysis, this minimal description leaves critical behavioral traits unspecified.

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 ('Get AI-powered suggestions for optimizing a SQL query') with zero wasted words. It avoids redundancy and is appropriately sized for a straightforward tool, making it easy for an agent to parse quickly.

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 (AI-powered optimization), lack of annotations, and an output schema (which should cover return values), the description is minimally adequate. It states what the tool does but omits usage guidelines, behavioral details, and parameter nuances. The presence of an output schema lifts some burden, but for a tool with potential behavioral implications, more context would improve completeness.

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?

The input schema has 1 parameter with 0% description coverage, so the schema provides no semantic context. The description mentions 'optimizing a SQL query', which implies the 'query' parameter should be a SQL string, adding some meaning beyond the schema's bare 'string' type. However, it doesn't detail constraints (e.g., query length, supported SQL dialects) or examples, resulting in a baseline score given the single parameter.

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 action ('Get AI-powered suggestions') and the resource ('optimizing a SQL query'), making the purpose immediately understandable. It distinguishes itself from siblings like 'execute_sql' or 'explain_query' by focusing on optimization suggestions rather than execution or analysis. However, it doesn't explicitly contrast with all potential alternatives like 'analyze_query_results' or 'generate_table_insights', 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 prerequisites (e.g., needing a query to optimize), exclusions (e.g., not for non-SQL queries), or comparisons to siblings like 'explain_query' (which might analyze performance) or 'natural_language_to_sql' (which generates queries). This lack of contextual direction leaves the agent to infer usage from the tool name alone.

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/rickyb30/datapilot-mcp-server'

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