Skip to main content
Glama
jghidalgo

Lambda Performance MCP Server

by jghidalgo

get_cost_analysis

Analyze AWS Lambda function costs to identify optimization opportunities and reduce expenses by examining performance data across specified time ranges.

Instructions

Analyze Lambda function costs and identify optimization opportunities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
functionNameNoName of the Lambda function (optional for account-wide analysis)
timeRangeNoTime range for cost analysis (default: 30d)

Implementation Reference

  • Primary handler function for 'get_cost_analysis' tool. Parses input arguments, delegates cost analysis to LambdaAnalyzer, and formats the markdown response.
    async getCostAnalysis(args) { const { functionName, timeRange = '30d' } = args; const costAnalysis = await this.lambdaAnalyzer.analyzeCosts( functionName, timeRange ); return { content: [ { type: 'text', text: `# Cost Analysis${functionName ? `: ${functionName}` : ' (Account-wide)'}\n\n` + `## Cost Breakdown\n` + `- **Total Cost**: $${costAnalysis.total}\n` + `- **Compute Cost**: $${costAnalysis.compute} (${costAnalysis.computePercent}%)\n` + `- **Request Cost**: $${costAnalysis.requests} (${costAnalysis.requestsPercent}%)\n` + `- **Data Transfer**: $${costAnalysis.dataTransfer}\n\n` + `## Usage Statistics\n` + `- **Total Invocations**: ${costAnalysis.invocations.toLocaleString()}\n` + `- **Total Duration**: ${costAnalysis.totalDuration}ms\n` + `- **Average Duration**: ${costAnalysis.avgDuration}ms\n\n` + `## Cost Optimization Opportunities\n` + `${costAnalysis.optimizations.map(opt => `- **${opt.type}**: ${opt.description} (Potential savings: $${opt.savings})` ).join('\n')}\n\n` + `## Trends\n` + `- **Daily Average**: $${costAnalysis.dailyAverage}\n` + `- **Trend**: ${costAnalysis.trend}\n` + `- **Peak Day**: ${costAnalysis.peakDay} ($${costAnalysis.peakCost})` } ] }; }
  • index.js:166-183 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and input schema for get_cost_analysis.
    { name: 'get_cost_analysis', description: 'Analyze Lambda function costs and identify optimization opportunities', inputSchema: { type: 'object', properties: { functionName: { type: 'string', description: 'Name of the Lambda function (optional for account-wide analysis)' }, timeRange: { type: 'string', enum: ['24h', '7d', '30d'], description: 'Time range for cost analysis (default: 30d)' } } } },
  • Switch case dispatcher in CallToolRequestHandler that invokes the getCostAnalysis handler.
    case 'get_cost_analysis': return await this.getCostAnalysis(args);
  • Core helper method in LambdaAnalyzer class that orchestrates cost analysis by calling specific function or account-wide cost analyzers.
    async analyzeCosts(functionName, timeRange) { const timeRangeMs = this.parseTimeRange(timeRange); const endTime = new Date(); const startTime = new Date(endTime.getTime() - timeRangeMs); if (functionName) { return await this.analyzeFunctionCosts(functionName, startTime, endTime, timeRange); } else { return await this.analyzeAccountCosts(startTime, endTime, timeRange); } }
  • Implementation of function-specific cost analysis (placeholder data). Called by analyzeCosts when functionName is provided.
    async analyzeFunctionCosts(functionName, startTime, endTime, timeRange) { // Placeholder implementation return { total: 12.45, compute: 10.20, requests: 2.25, dataTransfer: 0.00, computePercent: 82, requestsPercent: 18, invocations: 150000, totalDuration: 45000000, avgDuration: 300, optimizations: [ { type: 'Memory optimization', description: 'Reduce memory allocation', savings: 2.50 }, { type: 'Duration optimization', description: 'Optimize code performance', savings: 1.80 } ], dailyAverage: 0.41, trend: 'Stable', peakDay: '2024-01-15', peakCost: 0.89 };

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