Skip to main content
Glama
egarcia74

Warp SQL Server MCP

by egarcia74

explain_query

Analyze SQL query performance by generating execution plans to identify optimization opportunities and understand query behavior.

Instructions

Get the execution plan for a SQL query to analyze performance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to analyze
databaseNoOptional: Database name to use for this query
include_actual_planNoInclude actual execution statistics (optional, defaults to false)

Implementation Reference

  • Main handler function for 'explain_query' tool. Generates SQL Server execution plans using SHOWPLAN_ALL or fallback SHOWPLAN_TEXT without executing the actual query. Includes performance monitoring and error handling.
    async explainQuery(query, database = null) {
      try {
        const pool = await this.getConnection();
        const request = pool.request();
    
        // Switch database if specified
        if (database) {
          await request.query(`USE [${database}]`);
        }
    
        // Execute the SET SHOWPLAN_ALL ON in a separate batch
        await request.query('SET SHOWPLAN_ALL ON');
    
        // Execute the query to get the execution plan
        const result = await request.query(query);
    
        // Turn off SHOWPLAN_ALL
        await request.query('SET SHOWPLAN_ALL OFF');
    
        // Track performance
        if (this.performanceMonitor) {
          this.performanceMonitor.recordQuery({
            tool: 'explain_query',
            query,
            executionTime: 0, // SHOWPLAN doesn't actually execute
            success: true,
            database,
            timestamp: new Date()
          });
        }
    
        return this.formatResults(result);
      } catch {
        // If SHOWPLAN_ALL doesn't work, try with estimated execution plan
        try {
          const pool = await this.getConnection();
          const request = pool.request();
    
          // Switch database if specified
          if (database) {
            await request.query(`USE [${database}]`);
          }
    
          // Try SET SHOWPLAN_TEXT instead
          await request.query('SET SHOWPLAN_TEXT ON');
          const result = await request.query(query);
          await request.query('SET SHOWPLAN_TEXT OFF');
    
          // Track performance
          if (this.performanceMonitor) {
            this.performanceMonitor.recordQuery({
              tool: 'explain_query',
              query,
              executionTime: 0, // SHOWPLAN doesn't actually execute
              success: true,
              database,
              timestamp: new Date()
            });
          }
    
          return this.formatResults(result);
        } catch (innerError) {
          // Track failed query
          if (this.performanceMonitor) {
            this.performanceMonitor.recordQuery({
              tool: 'explain_query',
              query,
              executionTime: 0,
              success: false,
              error: innerError.message,
              database,
              timestamp: new Date()
            });
          }
    
          // Re-throw the error so it can be handled by the caller
          throw innerError;
        }
      }
    }
  • Input schema definition for the 'explain_query' tool, defining parameters: query (required string), database (optional string), include_actual_plan (optional boolean).
    name: 'explain_query',
    description: 'Get the execution plan for a SQL query to analyze performance',
    inputSchema: {
      type: 'object',
      properties: {
        query: { type: 'string', description: 'The SQL query to analyze' },
        database: { type: 'string', description: 'Optional: Database name to use for this query' },
        include_actual_plan: {
          type: 'boolean',
          description: 'Include actual execution statistics (optional, defaults to false)'
        }
      },
      required: ['query']
    }
  • index.js:308-311 (registration)
    MCP tool dispatch registration in the main server switch statement. Calls DatabaseToolsHandler.explainQuery with parsed arguments.
    case 'explain_query':
      return {
        content: await this.databaseTools.explainQuery(args.query, args.database)
      };
  • index.js:241-242 (registration)
    Registers the tool list handler which includes 'explain_query' from tool-registry.js via getAllTools().
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: getAllTools()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'analyze performance' but doesn't specify whether this is a read-only operation, if it requires specific permissions, what the output format is (e.g., text, JSON), or any rate limits. For a tool with no annotations, this leaves significant gaps in understanding its behavior and constraints.

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: 'Get the execution plan for a SQL query to analyze performance.' It is front-loaded with the core purpose, avoids redundancy, and every word contributes meaning without waste. This makes it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of SQL query analysis and the lack of annotations and output schema, the description is incomplete. It doesn't explain what an 'execution plan' entails (e.g., visual vs. textual), performance metrics included, or error handling. For a tool with no structured output and behavioral gaps, more detail is needed to fully inform usage.

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 100% description coverage, clearly documenting all three parameters. The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't explain query syntax requirements or database context implications). With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 tool's purpose: 'Get the execution plan for a SQL query to analyze performance.' It specifies the action ('Get') and resource ('execution plan'), and distinguishes it from siblings like 'execute_query' or 'get_query_performance' by focusing on plan analysis rather than execution or metrics. However, it doesn't explicitly differentiate from 'analyze_query_performance' or 'detect_query_bottlenecks', which might have overlapping purposes.

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 valid SQL query), exclusions (e.g., not for actual query execution), or comparisons to siblings like 'analyze_query_performance' or 'get_optimization_insights'. Without such context, users must infer usage from the purpose 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/egarcia74/warp-sql-server-mcp'

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