Skip to main content
Glama

explain_query

Convert SQL queries into plain English explanations to understand their purpose and functionality with clarity.

Instructions

Explain what a SQL query does in plain English

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The MCP tool handler for 'explain_query'. Initializes OpenAI client and delegates to its explain_query method to generate plain English explanation of SQL query.
    @mcp.tool() async def explain_query(query: str, ctx: Context) -> str: """Explain what a SQL query does in plain English""" await ctx.info(f"Explaining query: {query[:100]}...") try: openai = await get_openai_client() explanation = await openai.explain_query(query) await ctx.info("Generated query explanation") return explanation except Exception as e: logger.error(f"Error explaining query: {str(e)}") await ctx.error(f"Failed to explain query: {str(e)}") raise
  • Core helper method in OpenAIClient that implements query explanation using tailored OpenAI chat prompts and API call.
    async def explain_query(self, query: str) -> str: """Explain what a SQL query does in plain English""" system_prompt = """ You are a SQL educator. Explain the provided SQL query in plain English. Your explanation should: - Describe what the query does step by step - Explain complex operations in simple terms - Mention any important performance considerations - Be accessible to both technical and non-technical users Use clear, friendly language. """ user_prompt = f""" SQL Query to explain: {query} Please explain what this query does. """ try: response = await self.client.chat.completions.create( model=self.model, messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt} ], temperature=0.3, max_tokens=600 ) explanation = response.choices[0].message.content.strip() logger.info("Generated query explanation") return explanation except Exception as e: logger.error(f"Error explaining query: {str(e)}") raise Exception(f"Failed to explain query: {str(e)}")

Other Tools

Related 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