Skip to main content

run_streaming

Function run_streaming 

Source
pub async fn run_streaming(handler: LambdaMcpHandler) -> Result<(), Error>
Expand description

Run the Lambda MCP handler with streaming response support.

This replaces lambda_http::run_with_streaming_response(service_fn(...)) and gracefully handles API Gateway streaming completion invocations that would otherwise cause deserialization errors in the Lambda runtime.

§Problem

When API Gateway uses response-streaming-invocations, it sends a secondary “completion” invocation after the streaming response finishes. This invocation is NOT an API Gateway proxy event — lambda_http cannot deserialize it, causing ERROR logs and CloudWatch Lambda Error metrics for every streaming response.

§Solution

This function uses lambda_runtime::run() directly with serde_json::Value (which always deserializes), then classifies the payload three ways via [classify_runtime_event()]:

  • ApiGatewayEvent — dispatched to the handler normally
  • StreamingCompletion — acknowledged silently (debug log)
  • UnrecognizedEvent — acknowledged with a warn log to surface unexpected payload shapes in CloudWatch without triggering Lambda retries

§Usage

let handler = server.handler().await?;
turul_mcp_aws_lambda::run_streaming(handler).await