Skip to main content
Glama
jghidalgo

Lambda Performance MCP Server

by jghidalgo

analyze_memory_utilization

Monitor AWS Lambda function memory usage over specified time ranges, identify inefficiencies, and generate right-sizing recommendations to optimize performance and reduce costs.

Instructions

Analyze memory utilization and provide right-sizing recommendations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
functionNameYesName of the Lambda function
timeRangeNoTime range for memory analysis (default: 24h)

Implementation Reference

  • Core handler function implementing the memory utilization analysis logic for Lambda functions, including metrics calculation and recommendations.
    async analyzeMemoryUtilization(functionName, timeRange) { const timeRangeMs = this.parseTimeRange(timeRange); const endTime = new Date(); const startTime = new Date(endTime.getTime() - timeRangeMs); // Get function configuration const config = await this.getFunctionConfig(functionName); const allocatedMemory = config.MemorySize; // Get memory usage from logs const memoryUsage = await this.getMemoryUsageFromLogs(functionName, startTime, endTime); const avgUsed = memoryUsage.reduce((sum, usage) => sum + usage, 0) / memoryUsage.length || 0; const peakUsed = Math.max(...memoryUsage, 0); const minUsed = Math.min(...memoryUsage, allocatedMemory); const utilizationPercent = Math.round((avgUsed / allocatedMemory) * 100); // Generate recommendation const recommendation = this.generateMemoryRecommendation( allocatedMemory, avgUsed, peakUsed, utilizationPercent ); return { allocated: allocatedMemory, avgUsed: Math.round(avgUsed), peakUsed: Math.round(peakUsed), minUsed: Math.round(minUsed), utilizationPercent, recommended: recommendation.memory, reasoning: recommendation.reasoning, performanceImpact: recommendation.performanceImpact, costImpact: recommendation.costImpact, patterns: this.analyzeMemoryPatterns(memoryUsage) }; }
  • Input schema and tool definition for the analyze_memory_utilization tool.
    name: 'analyze_memory_utilization', description: 'Analyze memory utilization and provide right-sizing recommendations', inputSchema: { type: 'object', properties: { functionName: { type: 'string', description: 'Name of the Lambda function' }, timeRange: { type: 'string', enum: ['1h', '6h', '24h', '7d'], description: 'Time range for memory analysis (default: 24h)' } }, required: ['functionName'] }
  • index.js:226-227 (registration)
    Registration of the tool in the MCP server dispatch switch statement.
    case 'analyze_memory_utilization': return await this.analyzeMemoryUtilization(args);
  • MCP server handler wrapper that calls the analyzer and formats the response.
    async analyzeMemoryUtilization(args) { const { functionName, timeRange = '24h' } = args; const memoryAnalysis = await this.lambdaAnalyzer.analyzeMemoryUtilization( functionName, timeRange ); return { content: [ { type: 'text', text: `# Memory Utilization Analysis: ${functionName}\n\n` + `## Current Configuration\n` + `- **Allocated Memory**: ${memoryAnalysis.allocated}MB\n` + `- **Average Used**: ${memoryAnalysis.avgUsed}MB (${memoryAnalysis.utilizationPercent}%)\n` + `- **Peak Usage**: ${memoryAnalysis.peakUsed}MB\n` + `- **Minimum Usage**: ${memoryAnalysis.minUsed}MB\n\n` + `## Right-sizing Recommendation\n` + `- **Recommended Memory**: ${memoryAnalysis.recommended}MB\n` + `- **Reasoning**: ${memoryAnalysis.reasoning}\n` + `- **Expected Performance Impact**: ${memoryAnalysis.performanceImpact}\n` + `- **Cost Impact**: ${memoryAnalysis.costImpact}\n\n` + `## Memory Usage Patterns\n` + `${memoryAnalysis.patterns.map(pattern => `- ${pattern}`).join('\n')}` } ] }; }
  • Helper function that generates memory right-sizing recommendations based on utilization metrics.
    generateMemoryRecommendation(allocated, avgUsed, peakUsed, utilizationPercent) { let recommendedMemory = allocated; let reasoning = ''; let performanceImpact = 'No change expected'; let costImpact = 'No change'; if (utilizationPercent < 50) { // Over-provisioned recommendedMemory = Math.max(128, Math.ceil(peakUsed * 1.2 / 64) * 64); reasoning = 'Memory is over-provisioned. Reducing memory will lower costs.'; costImpact = `Reduce costs by ~${Math.round((1 - recommendedMemory/allocated) * 100)}%`; performanceImpact = 'Minimal performance impact expected'; } else if (utilizationPercent > 85) { // Under-provisioned recommendedMemory = Math.ceil(peakUsed * 1.3 / 64) * 64; reasoning = 'Memory utilization is high. Increasing memory may improve performance.'; costImpact = `Increase costs by ~${Math.round((recommendedMemory/allocated - 1) * 100)}%`; performanceImpact = 'Improved performance and reduced duration expected'; } else { reasoning = 'Memory allocation appears optimal for current usage patterns.'; } return { memory: recommendedMemory, reasoning, performanceImpact, costImpact }; }

Other Tools

Related 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/jghidalgo/lambda-performance-mcp-nodejs'

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