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
      };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions analyzing costs and identifying optimization opportunities, but doesn't describe what the analysis returns (e.g., cost breakdowns, savings estimates), whether it requires specific permissions, or any rate limits. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core functionality, making it easy to understand at a glance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of cost analysis and optimization identification, the description is insufficient. With no annotations and no output schema, it doesn't explain what the analysis returns or any behavioral constraints. The description should provide more context about the tool's output and usage patterns to be complete for this type of analytical tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 100% description coverage, so parameters are well-documented in the structured fields. The description adds no additional parameter semantics beyond what's in the schema, but since schema coverage is high, the baseline score of 3 is appropriate as the description doesn't need to compensate for gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as analyzing Lambda function costs and identifying optimization opportunities, which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'get_optimization_recommendations' or 'analyze_lambda_performance' that might overlap in optimization analysis.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'get_optimization_recommendations' and 'analyze_lambda_performance' that might handle similar optimization tasks, there's no indication of when this cost-focused tool is preferred or what distinguishes it from other analysis tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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