invoke_lambda_function_impl
Execute AWS Lambda functions with JSON payloads to access private resources, real-time data, or custom computations 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
| Name | Required | Description | Default |
|---|---|---|---|
| function_name | Yes | ||
| parameters | Yes |
Implementation Reference
- main.py:94-120 (handler)The core handler function for the 'invoke_lambda_function_impl' tool. Validates the function name, invokes the AWS Lambda function using boto3, handles errors, and formats the response payload.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)Registration of the invoke_lambda_function_impl 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 tool using the mcp.tool() decorator when dynamic registration fails.mcp.tool()(invoke_lambda_function_impl)
- main.py:35-38 (helper)Helper function used by the handler to validate Lambda function names based on prefix or explicit 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
- main.py:56-65 (helper)Helper function used by the handler to format the Lambda response, preferring JSON pretty-printing.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}"