Skip to main content
Glama
Raistlin82

SAP OData to MCP Server

by Raistlin82

Query Performance Optimizer

query-performance-optimizer

Analyze SAP OData query execution patterns to identify bottlenecks and recommend performance improvements. Optimizes query speed, bandwidth usage, and caching strategies based on execution statistics.

Instructions

Optimize SAP OData query performance by analyzing execution patterns and suggesting improvements. Automatically identifies bottlenecks and recommends index strategies.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesOriginal OData query URL to optimize
entityTypeYesTarget entity type
executionStatsNoQuery execution statistics
optimizationGoalsNoPrimary optimization objectives

Implementation Reference

  • Core handler implementation of the 'query-performance-optimizer' tool. Includes name, description, inputSchema for validation, execute method for optimization logic using AI, and helper methods for analyzing improvements and estimating gains.
    export class QueryPerformanceOptimizerTool implements Tool {
      [key: string]: unknown;
      name = 'query-performance-optimizer';
      description =
        'Analyze and optimize SAP OData queries for better performance using AI recommendations.';
    
      inputSchema = {
        type: 'object' as const,
        properties: {
          query: {
            type: 'string' as const,
            description: 'Original OData query URL to optimize',
          },
          entityType: {
            type: 'string' as const,
            description: 'Target entity type',
          },
          executionStats: {
            type: 'object' as const,
            properties: {
              executionTime: { type: 'number' as const },
              recordCount: { type: 'number' as const },
              dataSize: { type: 'number' as const },
            },
          },
          optimizationGoals: {
            type: 'array' as const,
            items: {
              type: 'string' as const,
              enum: ['speed', 'bandwidth', 'accuracy', 'caching'] as const,
            },
            description: 'Primary optimization objectives',
          },
        },
        required: ['query', 'entityType'],
      };
    
      async execute(params: any): Promise<any> {
        try {
          logger.info('Optimizing query performance', {
            originalQuery: params.query,
            entityType: params.entityType,
            goals: params.optimizationGoals,
          });
    
          // Create mock entity for optimization
          const tool = new NaturalQueryBuilderTool();
          const mockEntityType = tool.createMockEntityType(params.entityType);
    
          const optimizationResult = await aiIntegration.optimizeQuery(
            `Optimize this query for performance: ${params.query}`,
            mockEntityType,
            { optimizationGoals: params.optimizationGoals }
          );
    
          const improvements = this.analyzeImprovements(params.query, optimizationResult.url);
          const performanceGain = this.estimatePerformanceGain(improvements);
    
          return {
            success: true,
            originalQuery: params.query,
            optimizedQuery: optimizationResult.url,
            improvements,
            performanceGain,
            explanation: optimizationResult.explanation,
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : 'Unknown error';
          logger.error('Query optimization failed', { error: errorMessage });
    
          return {
            success: false,
            originalQuery: params.query,
            error: errorMessage,
          };
        }
      }
    
      private analyzeImprovements(original: string, optimized: string): string[] {
        const improvements: string[] = [];
    
        if (optimized.includes('$select') && !original.includes('$select')) {
          improvements.push('Added field selection to reduce data transfer');
        }
    
        if (optimized.includes('$top') && !original.includes('$top')) {
          improvements.push('Added result limit to improve response time');
        }
    
        if (improvements.length === 0) {
          improvements.push('Query structure optimized for better SAP backend processing');
        }
    
        return improvements;
      }
    
      private estimatePerformanceGain(improvements: string[]): string {
        const totalGain = Math.min(improvements.length * 15, 80);
        return `Estimated ${totalGain}% performance improvement`;
      }
    }
  • The tool is instantiated and added to the aiEnhancedTools export array, serving as the registry for AI-enhanced tools.
    export const aiEnhancedTools = [
      new NaturalQueryBuilderTool(),
      new SmartDataAnalysisTool(),
      new QueryPerformanceOptimizerTool(),
      new BusinessProcessInsightsTool(),
    ];
  • Input schema definition for the tool, specifying parameters like query, entityType (required), executionStats, and optimizationGoals.
    inputSchema = {
      type: 'object' as const,
      properties: {
        query: {
          type: 'string' as const,
          description: 'Original OData query URL to optimize',
        },
        entityType: {
          type: 'string' as const,
          description: 'Target entity type',
        },
        executionStats: {
          type: 'object' as const,
          properties: {
            executionTime: { type: 'number' as const },
            recordCount: { type: 'number' as const },
            dataSize: { type: 'number' as const },
          },
        },
        optimizationGoals: {
          type: 'array' as const,
          items: {
            type: 'string' as const,
            enum: ['speed', 'bandwidth', 'accuracy', 'caching'] as const,
          },
          description: 'Primary optimization objectives',
        },
      },
      required: ['query', 'entityType'],
    };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions analysis and suggestion functions but doesn't clarify whether this is a read-only diagnostic tool or if it can implement changes, what permissions are required, whether it modifies data or systems, or what the output format looks like. For a tool with 'optimize' in its name and no annotations, this is a significant gap in transparency.

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 perfectly concise with two sentences that each earn their place. The first sentence establishes the core function, and the second adds valuable detail about automation and specific recommendation types. No wasted words, and the information is front-loaded effectively.

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 complexity (performance optimization with 4 parameters including nested objects), no annotations, and no output schema, the description is moderately complete. It explains what the tool does but lacks details about behavioral aspects, output format, and implementation constraints. For a tool that could potentially have significant system impact, more contextual information would be beneficial.

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?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description doesn't add any parameter-specific details beyond what's in the schema (like explaining how 'optimizationGoals' affect the analysis or what 'executionStats' should contain). The baseline of 3 is appropriate when the schema does the heavy lifting for parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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 with specific verbs ('optimize', 'analyzing', 'suggesting', 'identifies', 'recommends') and resources ('SAP OData query performance', 'execution patterns', 'improvements', 'bottlenecks', 'index strategies'). It distinguishes itself from siblings like 'sap-smart-query' or 'execute-entity-operation' by focusing on performance optimization rather than query execution or building.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context (when dealing with SAP OData query performance issues) but doesn't explicitly state when to use this tool versus alternatives like 'sap-smart-query' for query construction or 'smart-data-analysis' for general analysis. No exclusions or prerequisites are mentioned, leaving some ambiguity about appropriate use cases.

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/Raistlin82/btp-sap-odata-to-mcp-server-optimized'

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