Skip to main content

run_streaming_with

Function run_streaming_with 

Source
pub async fn run_streaming_with<F, Fut>(dispatch: F) -> Result<(), Error>
where F: Fn(Request) -> Fut + Clone + Send + 'static, Fut: Future<Output = Result<Response<UnsyncBoxBody<Bytes, Error>>, Error>> + Send,
Expand description

Run a custom dispatch function with streaming response support.

Like run_streaming(), but accepts a custom dispatch closure instead of a LambdaMcpHandler. Use this when you need pre-dispatch logic (e.g., .well-known routing) that runs before the MCP handler.

The dispatch closure is called once per API Gateway invocation. Streaming completion invocations and unrecognized payloads are acknowledged automatically without invoking the closure.

§Usage

async fn lambda_handler(request: Request) -> Result<Response, Error> {
    // pre-dispatch logic here (e.g., .well-known short-circuit)
    let handler = HANDLER.get_or_try_init(|| async { ... }).await?;
    handler.handle_streaming(request).await
}

turul_mcp_aws_lambda::run_streaming_with(lambda_handler).await