Skip to main content
Glama
Lambda Performance MCP Server

Lambda Performance MCP Server

by jghidalgo

Lambda Performance MCP Server (Node.js)

A comprehensive Model Context Protocol (MCP) server for analyzing AWS Lambda performance, tracking cold starts, and providing optimization recommendations. Built with Node.js and the AWS SDK v3.

Features

Performance Analysis

  • Comprehensive Metrics: Duration, memory usage, error rates, invocation counts

  • Cold Start Tracking: Detailed analysis of cold start patterns and frequency

  • Real-time Monitoring: Live performance metrics and alerts

  • Cost Analysis: Detailed cost breakdown and optimization opportunities

Advanced Analytics

  • Percentile Analysis: P50, P90, P95, P99 duration metrics

  • Memory Utilization: Right-sizing recommendations based on actual usage

  • Error Pattern Analysis: Identify and categorize error types

  • Trend Analysis: Performance trends over time

Optimization Recommendations

  • Cold Start Optimization: Provisioned concurrency, package size, initialization

  • Memory Right-sizing: Optimal memory allocation based on usage patterns

  • Cost Optimization: ARM architecture, duration optimization, resource efficiency

  • Performance Tuning: Code optimization, connection pooling, caching strategies

Comparative Analysis

  • Multi-function Comparison: Compare performance across multiple Lambda functions

  • Benchmarking: Identify best and worst performers

  • Resource Utilization: Compare memory, duration, and cost metrics

Related MCP server: Cloud FinOps Analyst MCP Server

Installation

  1. Clone the repository:

git clone <repository-url>
cd lambda-performance-mcp-nodejs
  1. Install dependencies:

npm install
  1. Configure environment:

cp .env.example .env
# Edit .env with your AWS credentials and configuration
  1. Set up AWS credentials:

# Option 1: Environment variables
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
export AWS_REGION=us-east-1

# Option 2: AWS CLI profile
aws configure --profile lambda-analyzer
export AWS_PROFILE=lambda-analyzer

# Option 3: IAM roles (for EC2/Lambda execution)

Required AWS Permissions

The MCP server requires the following AWS permissions:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "lambda:ListFunctions",
        "lambda:GetFunction",
        "lambda:GetFunctionConfiguration",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:GetMetricData",
        "logs:FilterLogEvents",
        "logs:DescribeLogGroups",
        "logs:DescribeLogStreams"
      ],
      "Resource": "*"
    }
  ]
}

Usage

Running the MCP Server

# Start the server
npm start

# Development mode with auto-reload
npm run dev

Available Tools

1. Analyze Lambda Performance

{
  "name": "analyze_lambda_performance",
  "arguments": {
    "functionName": "my-lambda-function",
    "timeRange": "24h",
    "includeDetails": true
  }
}

2. Track Cold Starts

{
  "name": "track_cold_starts",
  "arguments": {
    "functionName": "my-lambda-function",
    "timeRange": "24h"
  }
}

3. Get Optimization Recommendations

{
  "name": "get_optimization_recommendations",
  "arguments": {
    "functionName": "my-lambda-function",
    "analysisType": "all"
  }
}

4. Compare Lambda Performance

{
  "name": "compare_lambda_performance",
  "arguments": {
    "functionNames": ["function-1", "function-2", "function-3"],
    "timeRange": "24h",
    "metrics": ["duration", "cold-starts", "errors", "cost"]
  }
}

5. List Lambda Functions

{
  "name": "list_lambda_functions",
  "arguments": {
    "runtime": "nodejs18.x",
    "includeMetrics": true
  }
}

6. Analyze Memory Utilization

{
  "name": "analyze_memory_utilization",
  "arguments": {
    "functionName": "my-lambda-function",
    "timeRange": "24h"
  }
}

7. Get Cost Analysis

{
  "name": "get_cost_analysis",
  "arguments": {
    "functionName": "my-lambda-function",
    "timeRange": "30d"
  }
}

8. Monitor Real-time Performance

{
  "name": "monitor_real_time_performance",
  "arguments": {
    "functionName": "my-lambda-function",
    "duration": 5
  }
}

Configuration with MCP Clients

To use this MCP server with MCP clients, add it to your MCP configuration:

Workspace Configuration (.mcp/settings/mcp.json)

{
  "mcpServers": {
    "lambda-performance": {
      "command": "node",
      "args": ["path/to/lambda-performance-mcp-nodejs/index.js"],
      "env": {
        "AWS_REGION": "us-east-1",
        "AWS_ACCESS_KEY_ID": "your_access_key",
        "AWS_SECRET_ACCESS_KEY": "your_secret_key"
      },
      "disabled": false,
      "autoApprove": [
        "list_lambda_functions",
        "analyze_lambda_performance",
        "track_cold_starts"
      ]
    }
  }
}

Global Configuration (~/.mcp/settings/mcp.json)

{
  "mcpServers": {
    "lambda-performance": {
      "command": "node",
      "args": ["path/to/lambda-performance-mcp-nodejs/index.js"],
      "env": {
        "AWS_PROFILE": "default"
      },
      "disabled": false
    }
  }
}

Key Features Explained

Cold Start Analysis

  • Pattern Detection: Identifies when and why cold starts occur

  • Duration Analysis: Tracks initialization times and optimization opportunities

  • Trigger Identification: Determines what causes cold starts (idle time, scaling, deployments)

  • Timeline Visualization: Shows cold start frequency over time

Performance Optimization

  • Memory Right-sizing: Analyzes actual memory usage vs. allocated memory

  • Duration Optimization: Identifies performance bottlenecks and optimization opportunities

  • Cost Optimization: Provides recommendations to reduce Lambda costs

  • Architecture Recommendations: Suggests ARM vs x86 based on workload compatibility

Real-time Monitoring

  • Live Metrics: Current invocation rates, duration, and error rates

  • Performance Alerts: Automatic detection of performance issues

  • Activity Tracking: Recent invocation history and patterns

Example Outputs

Performance Analysis

# Lambda Performance Analysis: my-function

## Summary
- **Total Invocations**: 15,432
- **Average Duration**: 245ms
- **Cold Start Rate**: 12.3%
- **Error Rate**: 0.8%
- **Memory Utilization**: 67%

## Performance Metrics
- **P50 Duration**: 180ms
- **P95 Duration**: 450ms
- **P99 Duration**: 890ms
- **Max Duration**: 1,200ms

## Cold Start Analysis
- **Total Cold Starts**: 1,898
- **Average Cold Start Duration**: 1,200ms
- **Cold Start Pattern**: Moderate frequency during low traffic

Optimization Recommendations

# Optimization Recommendations: my-function

## Priority Recommendations
1. **Right-size Memory Allocation** (Impact: High)
   - Current memory is over-provisioned
   - Implementation: Reduce memory from 512MB to 256MB
   - Expected Improvement: Reduce costs by 25%

2. **Optimize Cold Start Performance** (Impact: High)
   - High cold start rate detected
   - Implementation: Implement provisioned concurrency for 2-3 instances
   - Expected Improvement: Reduce cold starts by 85%

Troubleshooting

Common Issues

  1. Permission Errors

    • Ensure AWS credentials have required permissions

    • Check CloudWatch Logs access for cold start analysis

  2. No Data Available

    • Verify function name is correct

    • Check if function has been invoked in the specified time range

    • Ensure CloudWatch logging is enabled

  3. Connection Timeouts

    • Check AWS region configuration

    • Verify network connectivity to AWS services

Debug Mode

# Enable debug logging
export LOG_LEVEL=debug
npm start

Contributing

  1. Fork the repository

  2. Create a feature branch

  3. Make your changes

  4. Add tests if applicable

  5. Submit a pull request

Support

For issues and questions:

  • Check the troubleshooting section

  • Review AWS permissions

  • Verify environment configuration

  • Check CloudWatch Logs for detailed error messages

Available Tools

8 tools
analyze_lambda_performanceC

Analyze Lambda function performance metrics including cold starts, duration, and errors

Inputs: functionName (required), timeRange, includeDetails.

analyze_memory_utilizationC

Analyze memory utilization and provide right-sizing recommendations

Inputs: functionName (required), timeRange.

compare_lambda_performanceB

Compare performance metrics between multiple Lambda functions

Inputs: functionNames (required), timeRange, metrics.

get_cost_analysisC

Analyze Lambda function costs and identify optimization opportunities

Inputs: functionName, timeRange.

get_optimization_recommendationsC

Get performance optimization recommendations for Lambda functions

Inputs: functionName (required), analysisType.

list_lambda_functionsC

List all Lambda functions in the account with basic performance info

Inputs: runtime, includeMetrics.

monitor_real_time_performanceC

Get real-time performance metrics and alerts for Lambda functions

Inputs: functionName (required), duration.

track_cold_startsC

Track and analyze cold start patterns for Lambda functions

Inputs: functionName (required), timeRange.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 8 tools

    Disambiguation4/5

    Most tools have distinct purposes, such as analyze_lambda_performance for general metrics, analyze_memory_utilization for memory-specific analysis, and compare_lambda_performance for comparisons. However, analyze_lambda_performance and monitor_real_time_performance could be confused, as both involve performance metrics, though one is general analysis and the other is real-time monitoring.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern using snake_case, such as analyze_lambda_performance, list_lambda_functions, and track_cold_starts. This uniformity makes the tool set predictable and easy to understand.

    Tool Count5/5

    With 8 tools, the server is well-scoped for Lambda performance analysis, covering key areas like monitoring, cost, optimization, and specific metrics. Each tool serves a clear purpose without being overwhelming or insufficient.

    Completeness4/5

    The tool set covers core aspects of Lambda performance analysis, including listing functions, analyzing metrics, cost, optimization, and cold starts. A minor gap is the lack of tools for configuration updates or direct action implementation, but agents can work around this by using recommendations from existing tools.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Provides a comprehensive suite of 76 tools for AWS cloud resource optimization, cost management, and infrastructure monitoring. It enables users to identify unused resources, analyze cost trends, right-size capacity, and maintain security compliance through natural language.
      76
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables analyzing AWS cloud costs through natural language queries, providing cost summaries, anomaly detection, idle resource identification, rightsizing recommendations, and tagging compliance via Claude.
      10
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables analyzing AWS cloud costs from billing data, identifying waste, and providing mergeable fixes, with findings reconciled to actual invoices and priced at your negotiated rates.
      6
      12 PyPI
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to diagnose and analyze AWS serverless infrastructure through Model Context Protocol, providing access to CloudWatch logs, Lambda functions, DynamoDB tables, IAM policies, and Bedrock-powered incident root-cause analysis.
      -

    Appeared in Searches