analyze_query
Analyzes SQL query performance using profiles by processing query ID and SQL. Part of the StarRocks MCP Server, enabling efficient query optimization and database exploration.
Instructions
Analyze query via profile
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | Query SQL | |
| uuid | Yes | Query ID, a string composed of 32 hexadecimal digits formatted as 8-4-4-4-12 |
Implementation Reference
- The handler function for the analyze_query tool, including registration via @mcp.tool decorator and input schema via Annotated parameters. It executes ANALYZE PROFILE for a given query UUID or EXPLAIN ANALYZE for SQL, returning the result as a string.@mcp.tool(description="Analyze a query and get analyze result using query profile" + description_suffix) def analyze_query( uuid: Annotated[ str|None, Field(description="Query ID, a string composed of 32 hexadecimal digits formatted as 8-4-4-4-12")]=None, sql: Annotated[str|None, Field(description="Query SQL")]=None, db: Annotated[str|None, Field(description="database")] = None ) -> str: if uuid: logger.info(f"Analyzing query profile for UUID: {uuid}") return db_client.execute(f"ANALYZE PROFILE FROM '{uuid}'", db=db).to_string() elif sql: logger.info(f"Analyzing query: {sql[:100]}{'...' if len(sql) > 100 else ''}") return db_client.execute(f"EXPLAIN ANALYZE {sql}", db=db).to_string() else: logger.warning("Analyze query called without valid UUID or SQL") return f"Failed to analyze query, the reasons maybe: 1.query id is not standard uuid format; 2.the SQL statement have spelling error."
- src/mcp_server_starrocks/server.py:219-219 (registration)Registration of the analyze_query tool using the @mcp.tool decorator.@mcp.tool(description="Analyze a query and get analyze result using query profile" + description_suffix)
- Input schema definition for the analyze_query tool using Pydantic Annotated fields for uuid, sql, and db parameters.uuid: Annotated[ str|None, Field(description="Query ID, a string composed of 32 hexadecimal digits formatted as 8-4-4-4-12")]=None, sql: Annotated[str|None, Field(description="Query SQL")]=None, db: Annotated[str|None, Field(description="database")] = None