Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/assets/templates/runtime-docs/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Add `bedrock-agentcore[a2a] ~= 1.24.0` (the version line with `serve_a2a`) and
`agentcore dev` sets `A2A_PORT` when it needs a local port other than the
deployed service-contract default of 9000; `serve_a2a` reads it automatically.

AgentCore forwards only allowlisted request headers to your server, so the CLI
puts the A2A protocol headers (`A2A-Version` and `A2A-Extensions`) in this
runtime's `requestHeaderAllowlist` in `agentcore.json`. Keep them there, or your
server never receives them.

Full contract: https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-a2a-protocol-contract.html
{{/if}}
{{#if (eq protocol "AGUI")}}
Expand Down
5 changes: 5 additions & 0 deletions src/assets/templates/runtime-docs/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ dev), takes JSON-RPC 2.0 messages (such as `message/send`) on `POST /`,
publishes its agent card at `GET /.well-known/agent-card.json`, and answers
health checks on `GET /ping`.

AgentCore forwards only allowlisted request headers to your server, so the CLI
puts the A2A protocol headers (`A2A-Version` and `A2A-Extensions`) in this
runtime's `requestHeaderAllowlist` in `agentcore.json`. Keep them there, or your
server never receives them.

Full contract: https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-a2a-protocol-contract.html
{{/if}}
{{#if (eq protocol "AGUI")}}
Expand Down
4 changes: 4 additions & 0 deletions src/core/project/__snapshots__/manager.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ exports[`FsProjectManager.create snapshots the Strands A2A project manifest and
"modelProvider": "Bedrock",
"name": "a2a_python_strands",
"protocol": "A2A",
"requestHeaderAllowlist": [
"A2A-Version",
"A2A-Extensions",
],
"runtimeVersion": "PYTHON_3_14",
},
],
Expand Down
1 change: 1 addition & 0 deletions src/core/project/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3372,6 +3372,7 @@ describe("docs-only runtimes", () => {
runtimeVersion: "PYTHON_3_14",
entrypoint: "main.py",
protocol: "A2A",
requestHeaderAllowlist: ["A2A-Version", "A2A-Extensions"],
},
]);
expect((await readdir(join(project.rootPath, "app", "search"))).sort()).toEqual([
Expand Down
16 changes: 16 additions & 0 deletions src/core/project/templates/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ describe("runtime templates", () => {
expect(await Bun.file(join(appDir, ".dockerignore")).exists()).toBe(isContainer);
});

// AgentCore Runtime forwards only allowlisted request headers, so an A2A runtime must allow the
// A2A protocol headers; the other protocols leave the allowlist as the user set it.
test.each<[RuntimeTemplateShortcutName, Partial<RuntimeInput>, string[] | undefined]>([
["a2a-python-strands", {}, ["A2A-Version", "A2A-Extensions"]],
[
"a2a-python-strands",
{ requestHeaderAllowlist: ["X-Custom-Header"] },
["X-Custom-Header", "A2A-Version", "A2A-Extensions"],
],
["agent-python-strands", {}, undefined],
["mcp-python-fastmcp", { requestHeaderAllowlist: ["X-Custom-Header"] }, ["X-Custom-Header"]],
])("%s writes the request header allowlist %p", async (template, infra, expected) => {
const { runtime } = await addTemplate("my_agent", template, { infra });
expect(runtime.requestHeaderAllowlist).toEqual(expected);
});

// Build starts the agent in a box under opentelemetry-instrument, so a box template keeps OTEL on
// as every other template does, and writes no instrumentation.
test.each<RuntimeTemplateShortcutName>([
Expand Down
17 changes: 15 additions & 2 deletions src/core/project/templates/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { FsTreeNode } from "./fsTree";
import type { AssetSource } from "../source";
import type { RuntimeResourceConfig } from "../../../handlers/project/add/runtime/types";
import { DEFAULT_MODEL_IDS, type ProjectRuntime } from "../../../projectSchemas/runtime";
import {
DEFAULT_MODEL_IDS,
withProtocolRequestHeaders,
type ProjectRuntime,
} from "../../../projectSchemas/runtime";
import { mergeSpecEntries } from "./spec";
import type { SpecEntries, TemplateRenderer, TemplateResolver } from "./types";
import type {
Expand Down Expand Up @@ -527,7 +531,16 @@ const getTemplateResolvers = (assetSource: AssetSource, templateRenderer: Templa
tree,
spec: mergeSpecEntries([
{
runtimes: [{ ...buildRuntimeSpec(input), protocol: "A2A" as const }],
runtimes: [
{
...buildRuntimeSpec(input),
protocol: "A2A" as const,
requestHeaderAllowlist: withProtocolRequestHeaders(
"A2A",
input.requestHeaderAllowlist,
),
},
],
...(memory && { memories: [memory] }),
},
modelScaffold.spec,
Expand Down
8 changes: 5 additions & 3 deletions src/core/project/templates/runtimeDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FsTreeNode } from "./fsTree";
import type { AssetSource } from "../source";
import type { TemplateRenderer } from "./types";
import type { RuntimeDocsConfig } from "../../../handlers/project/add/runtime/types";
import type { ProjectRuntime } from "../../../projectSchemas/runtime";
import { withProtocolRequestHeaders, type ProjectRuntime } from "../../../projectSchemas/runtime";
import {
NodeRuntimeSchema,
PythonRuntimeSchema,
Expand Down Expand Up @@ -136,6 +136,8 @@ export async function runtimeDocsTree(
*/
export function buildDocsRuntimeSpec(input: RuntimeDocsConfig): ProjectRuntime {
const { name, language, ...infra } = input;
const protocol = infra.protocol ?? "HTTP";
const requestHeaderAllowlist = withProtocolRequestHeaders(protocol, infra.requestHeaderAllowlist);
return {
name,
codeLocation: `app/${name}` as ProjectRuntime["codeLocation"],
Expand All @@ -153,7 +155,7 @@ export function buildDocsRuntimeSpec(input: RuntimeDocsConfig): ProjectRuntime {
customDockerBuildArgs: input.customDockerBuildArgs,
}),
entrypoint: docsRuntimeEntrypoint(language),
protocol: infra.protocol ?? "HTTP",
protocol,
...(infra.description && { description: infra.description }),
...(infra.executionRoleArn && { executionRoleArn: infra.executionRoleArn }),
...(infra.additionalPolicies?.length && { additionalPolicies: infra.additionalPolicies }),
Expand All @@ -165,7 +167,7 @@ export function buildDocsRuntimeSpec(input: RuntimeDocsConfig): ProjectRuntime {
...(infra.authorizerConfiguration && {
authorizerConfiguration: infra.authorizerConfiguration,
}),
...(infra.requestHeaderAllowlist && { requestHeaderAllowlist: infra.requestHeaderAllowlist }),
...(requestHeaderAllowlist && { requestHeaderAllowlist }),
...(infra.lifecycleConfiguration && { lifecycleConfiguration: infra.lifecycleConfiguration }),
...(infra.resourceConfigurations && { resourceConfigurations: infra.resourceConfigurations }),
...(infra.hooksConfiguration && { hooksConfiguration: infra.hooksConfiguration }),
Expand Down
45 changes: 44 additions & 1 deletion src/handlers/project/add/runtime/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,12 @@ describe("project add runtime", () => {
[
"typescript A2A",
["--language", "typescript", "--protocol", "A2A"],
{ entrypoint: "main.js", protocol: "A2A", runtimeVersion: "NODE_22" },
{
entrypoint: "main.js",
protocol: "A2A",
runtimeVersion: "NODE_22",
requestHeaderAllowlist: ["A2A-Version", "A2A-Extensions"],
},
/agent-card\.json/,
[/runtime-http-/, /runtime-mcp-/, /runtime-agui-/],
],
Expand Down Expand Up @@ -574,6 +579,44 @@ describe("project add runtime", () => {
},
);

test("an A2A runtime adds the A2A protocol headers to the headers it allows", async () => {
const { projectRoot, cleanup } = await initProject();
cleanups.push(cleanup);
await run([
"add",
"runtime",
"--name",
"a2a_agent",
"--language",
"python",
"--protocol",
"A2A",
"--request-header-allowlist",
"X-Custom-Header",
]);
await run([
"add",
"runtime",
"--name",
"mcp_agent",
"--language",
"python",
"--protocol",
"MCP",
"--request-header-allowlist",
"X-Custom-Header",
]);

expect((await runtimeOf(projectRoot, "a2a_agent"))?.requestHeaderAllowlist).toEqual([
"X-Custom-Header",
"A2A-Version",
"A2A-Extensions",
]);
expect((await runtimeOf(projectRoot, "mcp_agent"))?.requestHeaderAllowlist).toEqual([
"X-Custom-Header",
]);
});

test("warns when --hooks-configuration has no warmup hook in camelCase, and still adds it", async () => {
const { projectRoot, cleanup } = await initProject();
cleanups.push(cleanup);
Expand Down
21 changes: 21 additions & 0 deletions src/projectSchemas/runtime.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { describe, expect, it } from "bun:test";
import {
A2A_REQUEST_HEADERS,
ProjectRuntimeSchema,
LifecycleConfigurationSchema,
checkAllowlistHeader,
isReservedBuildArgKey,
isValidDockerfilePath,
withProtocolRequestHeaders,
} from "./runtime";
const codeZipAgent = {
name: "agent",
Expand Down Expand Up @@ -49,6 +51,25 @@ describe("runtime custom validation", () => {
expect(checkAllowlistHeader("x-amzn-trace-id")).not.toBeNull();
expect(checkAllowlistHeader("X-Amzn-Bedrock-AgentCore-Runtime-Custom-Tenant")).toBeNull();
});
it("allowlists the A2A protocol headers for A2A runtimes only", () => {
expect(withProtocolRequestHeaders("A2A", undefined)).toEqual(["A2A-Version", "A2A-Extensions"]);
expect(withProtocolRequestHeaders("A2A", ["X-Tenant"])).toEqual([
"X-Tenant",
"A2A-Version",
"A2A-Extensions",
]);
// Headers the user already allowlisted are kept as written, not added twice.
expect(withProtocolRequestHeaders("A2A", ["a2a-version", "X-Tenant"])).toEqual([
"a2a-version",
"X-Tenant",
"A2A-Extensions",
]);
for (const protocol of ["HTTP", "MCP", "AGUI", undefined] as const) {
expect(withProtocolRequestHeaders(protocol, undefined)).toBeUndefined();
expect(withProtocolRequestHeaders(protocol, ["X-Tenant"])).toEqual(["X-Tenant"]);
}
for (const header of A2A_REQUEST_HEADERS) expect(checkAllowlistHeader(header)).toBeNull();
});
it("requires lifecycle idle timeout not to exceed maximum lifetime", () => {
expect(
LifecycleConfigurationSchema.safeParse({
Expand Down
23 changes: 23 additions & 0 deletions src/projectSchemas/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NetworkModeSchema,
type PlatformVersion,
PlatformVersionSchema,
type ProtocolMode,
ProtocolModeSchema,
RuntimeVersionSchema as RuntimeVersionSchemaFromConstants,
SECURITY_GROUP_ID_PATTERN,
Expand Down Expand Up @@ -145,6 +146,28 @@ export const RequestHeaderAllowlistSchema = z
}),
)
.max(MAX_HEADER_ALLOWLIST_SIZE, `Maximum ${MAX_HEADER_ALLOWLIST_SIZE} headers allowed`);

/** The request headers the A2A protocol defines: the protocol version and its extensions. */
export const A2A_REQUEST_HEADERS = ["A2A-Version", "A2A-Extensions"] as const;

/**
* AgentCore Runtime forwards only allowlisted request headers to the container,
* so an A2A runtime needs the A2A protocol headers in its allowlist to receive
* them. Returns the allowlist with them added (matched case-insensitively, after
* the headers the user set); other protocols keep theirs as is.
*/
export function withProtocolRequestHeaders(
protocol: ProtocolMode | undefined,
allowlist: string[] | undefined,
): string[] | undefined {
if (protocol !== "A2A") return allowlist;
const headers = allowlist ?? [];
const present = new Set(headers.map((header) => header.toLowerCase()));
return [
...headers,
...A2A_REQUEST_HEADERS.filter((header) => !present.has(header.toLowerCase())),
];
}
export const SessionStorageSchema = z.object({
mountPath: z
.string()
Expand Down
Loading