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
| Name | Required | Description | Default |
|---|---|---|---|
| toolName | Yes |
Implementation Reference
- mcp-self-learning-server.js:1249-1271 (handler)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'] }
- mcp-self-learning-server.js:1017-1027 (registration)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; }
- mcp-self-learning-server.js:1090-1092 (registration)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;