Class QueryAnalysisTool

java.lang.Object
org.gridgain.internal.mcp.tools.QueryAnalysisTool

public class QueryAnalysisTool extends Object
MCP tool for analyzing SQL query execution plans.

This tool generates execution plans for SQL queries using the EXPLAIN statement, helping users understand query performance characteristics without actually executing the query.

Features

  • Generates execution plans showing operations, row estimates, and distribution strategies
  • Shows join strategies, index usage, predicates, and projections
  • Safe analysis - EXPLAIN does not execute the actual query

Usage Example


 {
   "query": "SELECT o.order_id, c.name FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'PENDING'"
 }
 
  • Constructor Details

    • QueryAnalysisTool

      public QueryAnalysisTool()
  • Method Details

    • handleGetQueryExecutionPlan

      public static reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> handleGetQueryExecutionPlan(io.modelcontextprotocol.server.McpAsyncServerExchange exchange, Map<String,Object> arguments)
      Handles execution of the get_query_execution_plan tool.
      Parameters:
      exchange - MCP server exchange
      arguments - tool arguments containing the SQL query
      Returns:
      reactive MCP tool result with execution plan
    • getExecutionPlan

      public static McpResponse getExecutionPlan(String query, String explainType)
      Generates an execution plan for the provided SQL query.

      This method:

      1. Validates the query to reject data-modifying operations
      2. Executes EXPLAIN <query> to generate the plan
      3. Formats the plan output for readability
      Parameters:
      query - SQL query to analyze
      explainType - PLAN or MAPPING
      Returns:
      MCP response containing the formatted execution plan or error