Skip to content

Commit d5af72c

Browse files
committed
fix(dev): forward custom headers from web UI proxy to local agent
The Agent Inspector web UI proxy (handleInvocations) constructs new headers when proxying to the local Python/TS agent but never reads or forwards req.headers from the incoming request. This causes all x-amzn-bedrock-agentcore-runtime-custom-* headers to be silently dropped. The direct CLI invoke path already does this correctly via ...customHeaders spread — this patch brings the web UI proxy path to parity. Also applies the same fix to handleAguiInvocation which has the same issue. Reproduction: 1. agentcore create --name Test --framework Strands --model-provider Bedrock --protocol HTTP 2. agentcore dev (launches Inspector on 8081, agent on 8082) 3. curl -X POST http://localhost:8081/invocations -H 'X-Agentcore-Local: true' -H 'X-Amzn-Bedrock-AgentCore-Runtime-Custom-MyHeader: test-value' -H 'Content-Type: application/json' -d '{"prompt":"Hello"}' 4. Observe: custom header is NOT received by the Python agent 5. After fix: custom header IS received Tested on CLI v0.25.0, Node.js 23.11.0, macOS ARM64.
1 parent 8fba816 commit d5af72c

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/cli/operations/dev/web-ui/handlers/invocations.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ import { type IncomingMessage, type ServerResponse, request as httpRequest } fro
1111

1212
let a2aRequestId = 1;
1313

14+
/**
15+
* Forward allowlisted custom headers from the incoming request.
16+
* Currently forwards all `x-amzn-bedrock-agentcore-runtime-custom-*` headers
17+
* which are the documented custom header prefix for AgentCore Runtime.
18+
*/
19+
function forwardCustomHeaders(req: IncomingMessage, headers: Record<string, string>): void {
20+
if (req.headers) {
21+
for (const [key, value] of Object.entries(req.headers)) {
22+
if (key.startsWith('x-amzn-bedrock-agentcore-runtime-custom-') && typeof value === 'string') {
23+
headers[key] = value;
24+
}
25+
}
26+
}
27+
}
28+
1429
/**
1530
* POST /invocations — proxy to the selected agent.
1631
* Body must include agentName to route to the correct running agent.
@@ -84,7 +99,7 @@ export async function handleInvocations(
8499

85100
// AGUI agents need RunAgentInput body; SSE response is passed through raw
86101
if (agentProtocol === 'AGUI') {
87-
return handleAguiInvocation(ctx, res, body, agentPort, sessionId, userId, origin);
102+
return handleAguiInvocation(ctx, req, res, body, agentPort, sessionId, userId, origin);
88103
}
89104

90105
return new Promise<void>((resolve, reject) => {
@@ -96,6 +111,8 @@ export async function handleInvocations(
96111
if (userId) {
97112
headers['x-amzn-bedrock-agentcore-runtime-user-id'] = userId;
98113
}
114+
// Forward custom headers from the incoming request
115+
forwardCustomHeaders(req, headers);
99116

100117
const proxyReq = httpRequest(
101118
{
@@ -277,6 +294,7 @@ async function handleA2AInvocation(
277294
*/
278295
async function handleAguiInvocation(
279296
ctx: RouteContext,
297+
req: IncomingMessage,
280298
res: ServerResponse,
281299
rawBody: string,
282300
agentPort: number,
@@ -314,6 +332,8 @@ async function handleAguiInvocation(
314332
if (userId) {
315333
headers['x-amzn-bedrock-agentcore-runtime-user-id'] = userId;
316334
}
335+
// Forward custom headers from the incoming request
336+
forwardCustomHeaders(req, headers);
317337

318338
const proxyReq = httpRequest(
319339
{

0 commit comments

Comments
 (0)