optimize_tool
Receive tailored optimization suggestions for any tool by leveraging the MCP Self-Learning Server's autonomous pattern recognition and machine learning capabilities to enhance performance.
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:1017-1027 (registration)Registration of the optimize_tool in the MCP tools list, including name, description, and input schema requiring 'toolName' string.{ name: 'optimize_tool', description: 'Get optimization suggestions for a specific tool', inputSchema: { type: 'object', properties: { toolName: { type: 'string' } }, required: ['toolName'] } },
- mcp-self-learning-server.js:1249-1271 (handler)The core handler function for optimize_tool that analyzes learning patterns for the specified tool, collects optimization recommendations, usage stats, and 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) }; }
- Helper method called by the handler to compute aggregated performance metrics (response time, success/error rates) for the tool from stored patterns.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; }
- api/rest-server.js:122-122 (registration)REST API endpoint registration for /optimize which proxies to the MCP server's handleOptimizeTool.this.app.get('/optimize', this.handleOptimizeTool.bind(this));
- api/rest-server.js:303-314 (handler)REST wrapper handler that extracts tool_name from query params and delegates to the core MCP handler.async handleOptimizeTool(req, res) { try { const { tool_name } = req.query; const result = await this.mcpServer.handleOptimizeTool({ tool_name }); res.json(result); } catch (error) { logger.error('Optimize tool failed', { error: error.message }); res.status(500).json({ error: error.message }); } }