Skip to main content
Glama

invoke_lambda_function_impl

Invoke an AWS Lambda function with a JSON payload, enabling integration with private resources, real-time data, and custom computation through the MCP2Lambda server.

Instructions

Tool that invokes an AWS Lambda function with a JSON payload. Before using this tool, list the functions available to you.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
function_nameYes
parametersYes

Implementation Reference

  • main.py:94-120 (handler)
    Core implementation of the invoke_lambda_function_impl tool. Validates the function name, invokes the AWS Lambda function via boto3, handles errors, reads the payload, and formats the response using format_lambda_response.
    def invoke_lambda_function_impl(function_name: str, parameters: dict, ctx: Context) -> str: """Tool that invokes an AWS Lambda function with a JSON payload. Before using this tool, list the functions available to you.""" if not validate_function_name(function_name): return f"Function {function_name} is not valid" ctx.info(f"Invoking {function_name} with parameters: {parameters}") response = lambda_client.invoke( FunctionName=function_name, InvocationType="RequestResponse", Payload=json.dumps(parameters), ) ctx.info(f"Function {function_name} returned with status code: {response['StatusCode']}") if "FunctionError" in response: error_message = f"Function {function_name} returned with error: {response['FunctionError']}" ctx.error(error_message) return error_message payload = response["Payload"].read() # Format the response payload return format_lambda_response(function_name, payload)
  • main.py:126-126 (registration)
    Registers the invoke_lambda_function_impl function as an MCP tool using the mcp.tool() decorator in the generic tools strategy.
    mcp.tool()(invoke_lambda_function_impl)
  • main.py:182-182 (registration)
    Fallback registration of the invoke_lambda_function_impl function as an MCP tool in case dynamic registration fails.
    mcp.tool()(invoke_lambda_function_impl)
  • main.py:56-65 (helper)
    Helper function used by invoke_lambda_function_impl to format the Lambda response payload, preferring JSON if possible.
    def format_lambda_response(function_name: str, payload: bytes) -> str: """Format the Lambda function response payload.""" try: # Try to parse the payload as JSON payload_json = json.loads(payload) return f"Function {function_name} returned: {json.dumps(payload_json, indent=2)}" except (json.JSONDecodeError, UnicodeDecodeError): # Return raw payload if not JSON return f"Function {function_name} returned payload: {payload}"
  • main.py:35-37 (helper)
    Helper function used by invoke_lambda_function_impl to validate if the Lambda function name matches the prefix or is in the allowed list.
    def validate_function_name(function_name: str) -> bool: """Validate that the function name is valid and can be called.""" return function_name.startswith(FUNCTION_PREFIX) or function_name in FUNCTION_LIST

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/danilop/MCP2Lambda'

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