Skip to content

Add structured error logging to Lambda MCP server functions #2

Description

@longwind48

Problem

All Lambda MCP server functions use generic exception handling that returns plain error strings without context:

except Exception as e:
    return {"error": str(e)}

This makes debugging difficult in production — no stack traces, no request context, and no error classification in CloudWatch Logs.

Affected files:

  • src/lambda/mcp_servers/cost_explorer/lambda_function.py
  • src/lambda/mcp_servers/athena/lambda_function.py
  • src/lambda/mcp_servers/cur_analyst/lambda_function.py

Expected Behavior

Each Lambda handler should log structured errors with:

  • Handler/tool name that failed
  • Input parameters (sanitized)
  • Full stack trace via exc_info=True
  • Use Python's logging module configured at module level

Example

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

def some_handler(event):
    tool_name = event.get("tool_name", "unknown")
    try:
        # ... handler logic
    except Exception as e:
        logger.error("Error in handler %s", tool_name, exc_info=True)
        return {"error": str(e)}

Scope

  • Add logging import and logger setup to each affected Lambda
  • Wrap existing except blocks with structured logging
  • Do not change the return format — keep {"error": str(e)} for backward compatibility

Metadata

Metadata

Assignees

No one assigned

    Labels

    claudeTrigger Claude Code to work on this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions