Skip to main content
Glama
saralegui-solutions

MCP Self-Learning Server

optimize_tool

Generate optimization suggestions for MCP tools by analyzing usage patterns and performance data to enhance functionality and efficiency.

Instructions

Get optimization suggestions for a specific tool

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toolNameYes

Implementation Reference

  • Main handler function for 'optimize_tool'. Analyzes learning patterns related to the specified tool, gathers optimization recommendations, usage statistics, and generates a performance profile.
    async handleOptimizeTool(args) {
      const { toolName } = args;
      const recommendations = [];
      
      // Find patterns related to this tool
      for (const [key, pattern] of this.learningEngine.patterns) {
        if (pattern.features?.toolSequence?.includes(toolName)) {
          const optimizations = this.learningEngine.identifyOptimizations(pattern);
          recommendations.push(...optimizations);
        }
      }
      
      // Get usage statistics
      const usage = this.learningEngine.metrics.toolUsageFrequency.get(toolName) || 0;
      
      return {
        success: true,
        tool: toolName,
        usage,
        recommendations: [...new Set(recommendations)], // Deduplicate
        performanceProfile: this.generatePerformanceProfile(toolName)
      };
    }
  • Input schema definition for the optimize_tool, requiring a 'toolName' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        toolName: { type: 'string' }
      },
      required: ['toolName']
    }
  • Tool registration object for 'optimize_tool' passed to MCP server.setTools(), including name, description, and input schema.
    {
      name: 'optimize_tool',
      description: 'Get optimization suggestions for a specific tool',
      inputSchema: {
        type: 'object',
        properties: {
          toolName: { type: 'string' }
        },
        required: ['toolName']
      }
    },
  • Helper method used by the handler to generate a performance profile for the specified tool based on aggregated pattern data.
    generatePerformanceProfile(toolName) {
      const profile = {
        averageResponseTime: 0,
        successRate: 0,
        errorRate: 0,
        peakUsageTime: null
      };
      
      // Calculate from patterns
      let totalTime = 0;
      let successCount = 0;
      let errorCount = 0;
      let count = 0;
      
      for (const pattern of this.learningEngine.patterns.values()) {
        if (pattern.features?.toolSequence?.includes(toolName)) {
          if (pattern.features.performanceMetrics) {
            totalTime += pattern.features.performanceMetrics.responseTime;
            count++;
          }
          
          pattern.outcomes?.forEach(outcome => {
            if (outcome.success) successCount++;
            else errorCount++;
          });
        }
      }
      
      if (count > 0) {
        profile.averageResponseTime = totalTime / count;
        const total = successCount + errorCount;
        if (total > 0) {
          profile.successRate = successCount / total;
          profile.errorRate = errorCount / total;
        }
      }
      
      return profile;
    }
  • Dispatch case in the MCP CallToolRequestHandler switch statement that routes 'optimize_tool' calls to the handler function.
    case 'optimize_tool':
      result = await this.handleOptimizeTool(args);
      break;

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/saralegui-solutions/mcp-self-learning-server'

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