AWS bedrock-agentcore documentation change
Summary
Added documentation for response interceptors with streaming enabled, including input/output payload structures and invocation logic.
Security assessment
The change documents new streaming behavior without indicating any security vulnerability fix. It focuses on functional implementation details like payload structure and invocation patterns.
Diff
diff --git a/bedrock-agentcore/latest/devguide/gateway-interceptors-types.md b/bedrock-agentcore/latest/devguide/gateway-interceptors-types.md index bfcd4d907..84d278d77 100644 --- a//bedrock-agentcore/latest/devguide/gateway-interceptors-types.md +++ b//bedrock-agentcore/latest/devguide/gateway-interceptors-types.md @@ -7 +7 @@ -Request interceptorsResponse interceptors +Request interceptorsResponse interceptorsResponse interceptors with streaming enabled @@ -166,0 +167,120 @@ Important notes about response interceptor output: * The `interceptorOutputVersi +## Response interceptors with streaming enabled + +###### Note + +If response streaming is enabled on your gateway, your response interceptor Lambda function must check the `isStreamingResponse` field in `gatewayResponse` to distinguish between streaming and non-streaming responses. For streaming responses, handle multiple invocations per request — one per eligible event — and note that only the first invocation can override `headers` and `statusCode`. + +When [response streaming](./gateway-mcp-streaming.html) is enabled on your gateway, the response interceptor behavior changes. The interceptor is invoked multiple times during a streaming response — once per eligible event — instead of once with the complete response. + +### When the response interceptor is invoked + +The response interceptor is invoked for events that contain a JSON-RPC `id` field: + + * **First event** — The first JSON-RPC response or server-initiated request on the stream (e.g., the tool result, or an `elicitation/create` / `sampling/createMessage` request). + + * **Subsequent events** — Any additional JSON-RPC responses or server-initiated requests (e.g., the final tool result after an elicitation is fulfilled). + + + + +The response interceptor is **not** invoked for: + + * `notifications/progress` — Progress updates are forwarded directly to the client. + + * `notifications/message` — Log messages are forwarded directly to the client. + + * Pings — Keep-alive signals are forwarded directly to the client. + + + + +### Streaming response interceptor input payload + +The input payload includes a new `isStreamingResponse` field set to `true`. The `gatewayResponse.body` field contains the current event body. + +**First event** — The interceptor receives `headers`, `statusCode`, and `body`: + + + { + "interceptorInputVersion": "1.0", + "mcp": { + "rawGatewayRequest": { + "body": "<raw_request_body>" + }, + "gatewayRequest" : { + "path": "/mcp", + "httpMethod": "POST", + "body": { + "jsonrpc": "2.0", + "id": 1, + "method": "tools/call", + "params": { + "name": "myTool", + "arguments": {} + } + } + }, + "gatewayResponse" : { + "statusCode": 200, + "headers": { + "Mcp-Session-Id": "<session_id>" + }, + "isStreamingResponse": true, + "body": { + "jsonrpc": "2.0", + "id": "elicit-1", + "method": "elicitation/create", + "params": { + "message": "Confirm this action?", + "requestedSchema": {} + } + } + } + } + } + +**Subsequent events** — The interceptor receives only `body` (headers and status code have already been sent to the client): + + + { + "interceptorInputVersion": "1.0", + "mcp": { + "rawGatewayRequest": { + "body": "<raw_request_body>" + }, + "gatewayRequest" : { + "path": "/mcp", + "httpMethod": "POST", + "body": { + "jsonrpc": "2.0", + "id": 1, + "method": "tools/call", + "params": { + "name": "myTool", + "arguments": {} + } + } + }, + "gatewayResponse" : { + "isStreamingResponse": true, + "body": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "content": [{"type": "text", "text": "Tool result"}] + } + } + } + } + } + +### Streaming response interceptor output payload + +What the interceptor can override depends on whether it is the first or a subsequent event: + +Event | Can override | Ignored if returned +---|---|--- +First event | `headers`, `statusCode`, `body` | N/A +Subsequent events | `body` only | `headers`, `statusCode` (already sent to client) +Non-streaming (unchanged) | `headers`, `statusCode`, `body` | N/A +