Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f925a51
feat(box): Let a boxed agent use the MCP tools of the other gateways …
Nov 20, 2026
6c7a1d6
fix(box): Accept a China host in the gateway host and URL inputs
Nov 21, 2026
ea30c9a
test(box): Resolve a gateway name with "-" and upper case with the bo…
Nov 21, 2026
67110ba
fix(box): Give each gateway of the project its own Box gateway target…
Nov 21, 2026
6573b87
fix(box): Write a gateway target only when the CDK library of the pro…
Nov 21, 2026
ca324ac
fix(remove): Remove the Box gateway target of a gateway with the gateway
Nov 21, 2026
dc64c5b
fix(box): Read a project whose build-owned gateway target names a gat…
Nov 21, 2026
7755174
fix(box): Stop build when two gateways of the project get one target …
Nov 21, 2026
8922466
fix(box): Add the server of a gateway named constructor to the Runtim…
Nov 21, 2026
89f4333
fix(box): Give the CUSTOM_JWT gateway notice once, at add gateway, an…
Nov 21, 2026
6827831
fix(box): Ask the CDK library about a whole gateway target, as its sc…
Nov 21, 2026
d4faa0a
fix(schema): Skip the passthrough.gateway check only for an egress- t…
Nov 21, 2026
f628172
fix(box): Say why build could not check the CDK library for passthrou…
Nov 21, 2026
354eeea
fix(box): Give the CUSTOM_JWT gateway notice also when add runtime ad…
Nov 21, 2026
ffe7eec
docs(box): Name the check parameter and add runtime in the comments o…
Nov 21, 2026
ebeed83
fix(box): Write no signing region for a gateway target, as the L3 sig…
Nov 23, 2026
58a1168
fix(box): Stop build when a host takes again a target that a new gate…
Nov 23, 2026
6deafe3
fix(box): Stop build for a gateway with the name of a server that the…
Nov 23, 2026
3a2c576
fix(box): Stop build, and write nothing, when it cannot check the CDK…
Nov 23, 2026
cccb0ec
perf(box): Load only dist/schema of the CDK library, and do the check…
Nov 23, 2026
92a6db7
fix(remove): Remove only a target that build owns when the gateway th…
Nov 23, 2026
db61a73
test(schema): Give the runtime of the Box-project fixture platformVer…
vvargu Nov 24, 2026
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
25 changes: 22 additions & 3 deletions docs/box-local-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ profile that names a pack `box/<name>` fails: box refuses it and names the `@box
`mcp:call`. A host the gateway already has a target for keeps that target. Build owns only the
targets whose name starts with `egress-`: it adds them, changes them, and removes one when no host
needs it. It never changes another target.
- **The other gateways of the project.** A runtime without a box gets each gateway without
`boundRuntime` in `AGENTCORE_GATEWAY_<NAME>_URL`. For a box runtime, each of these gateways gets
the target `egress-gateway-<name>` on `<runtime>-box-egress`, with `passthrough.gateway` set to
the gateway's name. The L3 sets the target's endpoint to that gateway's URL, gives the Box
gateway's role `bedrock-agentcore:InvokeGateway` on that gateway only, and sets
`AGENTCORE_GATEWAY_<NAME>_URL` and `_HOST` on the runtime. A `PRIVATE_VPC` runtime gets none of
them. A `CUSTOM_JWT` gateway gets no target, and `agentcore add gateway`, and `agentcore add runtime` for a
box runtime, give one notice for it. You write nothing for them. A profile
entry that signs for a gateway host with `aws://` stops build. Build writes these targets only when
the `@aws/agentcore-cdk` in `agentcore/cdk` accepts `passthrough.gateway`: it asks that library
with `node`. When the library refuses the field, build writes none of them, removes the ones it
wrote before, and gives one warning. When build cannot do the check (no `node_modules`, no `node`,
a check that takes more than 60 seconds, or one that fails), it stops and writes nothing.
- **Outbound auth.** An `aws://` secret signs with the gateway's role, an `env://` secret sends an
API key from AgentCore Identity, and an entry with no secret sends no credential.
- **Failures.** A profile Box refuses stops build and deploy with box's own error. A wildcard host,
Expand Down Expand Up @@ -249,13 +262,18 @@ profile that names a pack `box/<name>` fails: box refuses it and names the `@box
the Runtime's Python, in every table: the agent, each stdio `[mcp.<name>]` server, each
`[tool.<name>]`;
- the `@box/agentcore` packs, the project name, and the build region come in, and each CloudWatch
target signs with the execution role.
target signs with the execution role;
- with `instrumentation.enableOtel` on, which is the default for a box template too, a command of
the Python of the venv starts with `opentelemetry-instrument`. On CodeZip, the Python of the
Runtime runs the script in the zip, `<code>/bin/opentelemetry-instrument`. The `@box/agentcore`
pack gives the agent the ADOT variables and the `OTEL_RESOURCE_ATTRIBUTES` that the Runtime
sets. When your `[agent.env]` sets one of these variables, box uses your value. The pack sets no
`OTEL_EXPORTER_OTLP_*` variable, because box sets each one.
`OTEL_EXPORTER_OTLP_*` variable, because box sets each one;
- each other gateway of the project gets `[mcp.<gateway>]`, to the host that `@box/agentcore`
reads from `AGENTCORE_GATEWAY_<NAME>_HOST`, through its `egress-gateway-<name>` target. The agent
gets `AGENTCORE_GATEWAY_<NAME>_URL`, so the code that calls the gateway without a box works in
the box. Box permits each tool of the server, and a forbid rule of your policy still applies.
A server of your profile with the name of a gateway stops build.

**The default log target.** With no `cloudwatch_logs` target, the Runtime profile gets
`[telemetry.agentcore]`: box sends its deny, permit, and trace records to the log group of the
Expand Down Expand Up @@ -293,7 +311,8 @@ profile that names a pack `box/<name>` fails: box refuses it and names the `@box

- **No-auth targets need a newer L3.** A passthrough target with no outbound auth synthesizes only
with an `@aws/agentcore-cdk` that accepts it. Until that release is pinned, use a local L3 build,
as in step 5.
as in step 5. A target with `passthrough.gateway` also needs an L3 that
accepts that field.

## 5. Point the generated CDK app at the local L3 tarball

Expand Down
94 changes: 94 additions & 0 deletions src/core/project/backends/cdk/compatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join } from "node:path";
import { tmpdir } from "node:os";
import {
assertCdkLocalContainerSupport,
cdkAcceptsPassthroughGateway,
cdkCompatibilityWarning,
MINIMUM_COMPATIBLE_CDK_VERSION,
} from "./compatibility";
Expand Down Expand Up @@ -101,3 +102,96 @@ describe("cdkCompatibilityWarning", () => {
expect(await cdkCompatibilityWarning(directory)).toBeUndefined();
});
});

describe("cdkAcceptsPassthroughGateway", () => {
/** A CDK app whose @aws/agentcore-cdk has the module text `index`. */
async function cdkDirectoryWithIndex(index: string | undefined): Promise<string> {
const directory = await mkdtemp(join(tmpdir(), "agentcore-cdk-passthrough-gateway-"));
tempDirectories.push(directory);
if (index === undefined) return directory;
const packageDirectory = join(directory, "node_modules", "@aws", "agentcore-cdk");
await mkdir(packageDirectory, { recursive: true });
await writeFile(
join(packageDirectory, "package.json"),
JSON.stringify({ name: "@aws/agentcore-cdk", version: "1.1.0", main: "index.js" }),
);
await writeFile(join(packageDirectory, "index.js"), index);
return directory;
}
/** A library that exports `AgentCoreGatewayTargetSchema` as `schema`, a JS text. */
const exporting = (schema: string) => `exports.AgentCoreGatewayTargetSchema = ${schema};\n`;
/** As each @aws/agentcore-cdk parses the passthrough of a target: with `gateway`, or `endpoint` only. */
const WITH_GATEWAY = exporting(
"{ safeParse: (target) => ({ success: typeof target.passthrough.gateway === 'string' }) }",
);
const ENDPOINT_ONLY = exporting(
"{ safeParse: (target) => ({ success: typeof target.passthrough.endpoint === 'string' }) }",
);
const withNode = test.skipIf(!Bun.which("node"));

withNode("accepts when the installed library accepts passthrough.gateway", async () => {
expect(await cdkAcceptsPassthroughGateway(await cdkDirectoryWithIndex(WITH_GATEWAY))).toEqual({
accepts: true,
});
});

withNode.each([
["requires passthrough.endpoint", ENDPOINT_ONLY],
["has no AgentCoreGatewayTargetSchema", "exports.Other = 1;\n"],
])("refuses when the installed library %s", async (_, index) => {
expect(await cdkAcceptsPassthroughGateway(await cdkDirectoryWithIndex(index))).toEqual({
accepts: false,
reason: "refuses",
});
});

withNode("loads only dist/schema of the library, and not the constructs", async () => {
const directory = await mkdtemp(join(tmpdir(), "agentcore-cdk-passthrough-gateway-"));
tempDirectories.push(directory);
const packageDirectory = join(directory, "node_modules", "@aws", "agentcore-cdk");
await mkdir(join(packageDirectory, "dist", "schema"), { recursive: true });
await writeFile(
join(packageDirectory, "package.json"),
JSON.stringify({ name: "@aws/agentcore-cdk", version: "1.1.0", main: "./dist/index.js" }),
);
// The entry of the package loads the constructs, which a check does not need.
await writeFile(
join(packageDirectory, "dist", "index.js"),
'throw new Error("the check loaded the constructs");\n',
);
await writeFile(join(packageDirectory, "dist", "schema", "index.js"), WITH_GATEWAY);

expect(await cdkAcceptsPassthroughGateway(directory)).toEqual({ accepts: true });
});

withNode("says that the library is not installed", async () => {
expect(await cdkAcceptsPassthroughGateway(await cdkDirectoryWithIndex(undefined))).toEqual({
accepts: false,
reason: "not-installed",
});
});

withNode("says that the check failed, with the error of the library", async () => {
const directory = await cdkDirectoryWithIndex('throw new Error("the library is broken");\n');
expect(await cdkAcceptsPassthroughGateway(directory)).toEqual({
accepts: false,
reason: "failed",
detail: "the library is broken",
});
});

withNode("says that the check took too long", async () => {
const directory = await cdkDirectoryWithIndex("while (true) {}\n");
expect(await cdkAcceptsPassthroughGateway(directory, { timeoutMs: 500 })).toEqual({
accepts: false,
reason: "timed-out",
});
});

test("says that build cannot run node", async () => {
const directory = await cdkDirectoryWithIndex(WITH_GATEWAY);
expect(
await cdkAcceptsPassthroughGateway(directory, { node: "/nonexistent/agentcore-test/node" }),
).toEqual({ accepts: false, reason: "no-node" });
});
});
78 changes: 78 additions & 0 deletions src/core/project/backends/cdk/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { execFile } from "node:child_process";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
import semver from "semver";
import { createRequire } from "node:module";
import { ProjectStateError } from "../../../../errors";
Expand Down Expand Up @@ -62,3 +64,79 @@ export async function cdkCompatibilityWarning(cdkDirectory: string): Promise<str
`Update the CDK dependency, then rebuild or redeploy.`
);
}

/**
* The script that asks the @aws/agentcore-cdk that the CDK app loads whether its schema takes a
* passthrough target with `gateway` in place of `endpoint`, as build writes it. It parses a whole
* target, because the library gives `gateway` a passthrough schema of its own. It loads
* `dist/schema` of the package by path, and not its constructs, which are slow to load; a package
* with no `dist/schema` is loaded whole. It prints `accepts`, `refuses`, `not-installed`, or
* `failed` and the error.
*/
const PASSTHROUGH_GATEWAY_CHECK = `
const path = require("node:path");
let library;
try {
const entry = require.resolve("@aws/agentcore-cdk");
try {
library = require(path.join(path.dirname(entry), "schema"));
} catch (error) {
if (!error || error.code !== "MODULE_NOT_FOUND") throw error;
library = require(entry);
}
} catch (error) {
const missing = error && error.code === "MODULE_NOT_FOUND" && /@aws\\/agentcore-cdk/.test(String(error.message));
process.stdout.write(missing ? "not-installed" : "failed " + (error && error.message));
process.exit(0);
}
const schema = library.AgentCoreGatewayTargetSchema;
const accepts =
schema !== undefined &&
schema.safeParse({
name: "egress-gateway-check",
targetType: "passthrough",
passthrough: { gateway: "check", protocolType: "CUSTOM" },
outboundAuth: { type: "GATEWAY_IAM_ROLE", service: "bedrock-agentcore" },
}).success === true;
process.stdout.write(accepts ? "accepts" : "refuses");
`;

/** The answer of {@link cdkAcceptsPassthroughGateway}, with the reason when it is not `accepts`. */
export type PassthroughGatewayCheck =
| { readonly accepts: true }
| {
readonly accepts: false;
readonly reason: "refuses" | "not-installed" | "no-node" | "timed-out" | "failed";
readonly detail?: string;
};

/**
* Asks the @aws/agentcore-cdk of the CDK app in `cdkDirectory` whether it accepts
* `passthrough.gateway`. Node runs the check in that folder, so it loads the same library as synth.
* Each answer other than `accepts` says why: the library refuses the field, is not installed, the
* check took more than `timeoutMs`, `node` is not there, or the check failed.
*/
export async function cdkAcceptsPassthroughGateway(
cdkDirectory: string,
options: { readonly node?: string; readonly timeoutMs?: number } = {},
): Promise<PassthroughGatewayCheck> {
let stdout: string;
try {
({ stdout } = await promisify(execFile)(
options.node ?? "node",
["-e", PASSTHROUGH_GATEWAY_CHECK],
{ cwd: cdkDirectory, timeout: options.timeoutMs ?? 60_000 },
));
} catch (error) {
const failure = error as NodeJS.ErrnoException & { killed?: boolean; stderr?: string };
if (failure.code === "ENOENT") return { accepts: false, reason: "no-node" };
if (failure.killed) return { accepts: false, reason: "timed-out" };
const detail = (failure.stderr ?? failure.message).trim().split("\n")[0];
return { accepts: false, reason: "failed", ...(detail && { detail }) };
}
const answer = stdout.trim();
if (answer === "accepts") return { accepts: true };
if (answer === "refuses" || answer === "not-installed") return { accepts: false, reason: answer };
const detail = answer.replace(/^failed\s*/, "");
return { accepts: false, reason: "failed", ...(detail && { detail }) };
}
2 changes: 1 addition & 1 deletion src/core/project/boxMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function boxGatewayFor(spec: ProjectSpec, runtime: ProjectRuntime): AgentCoreGat
*/
function servesTarget(targets: readonly AgentCoreGatewayTarget[], wanted: AgentCoreGatewayTarget) {
const endpoint = (target: AgentCoreGatewayTarget) =>
target.passthrough && new URL(target.passthrough.endpoint).host;
target.passthrough?.endpoint && new URL(target.passthrough.endpoint).host;
return targets.some(
(target) => target.name === wanted.name || endpoint(target) === endpoint(wanted),
);
Expand Down
24 changes: 19 additions & 5 deletions src/core/project/boxNetwork/egress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { BOX_EGRESS_TARGET_PREFIX } from "../../../projectSchemas/project";
import type { BoxEgressAuth } from "./network";
import type { FailureCode } from "./types";

Expand Down Expand Up @@ -132,6 +133,12 @@ const AWS_ENDPOINTS = [
api: "lambda-url",
service: "lambda",
},
{
pattern:
/^[a-z0-9][a-z0-9-]*\.gateway\.bedrock-agentcore\.([a-z0-9-]+)\.amazonaws\.com(?:\.cn)?$/,
api: "gateway",
service: "bedrock-agentcore",
},
] as const;

/** The API of an AWS endpoint that the gateway signs for. */
Expand All @@ -154,11 +161,7 @@ export function signingService(host: string): { service: string; region: string
return endpoint && { service: endpoint.service, region: endpoint.region };
}

/**
* The start of the name of each target that build adds to a Box gateway. Build manages every
* target whose name has it, and no other.
*/
export const BOX_EGRESS_TARGET_PREFIX = "egress-";
export { BOX_EGRESS_TARGET_PREFIX };

/**
* The gateway target name build gives `name`: {@link BOX_EGRESS_TARGET_PREFIX}, then the letters
Expand Down Expand Up @@ -191,6 +194,17 @@ export function outboundAuthFor(
if (!secret) return { ok: true, auth: { kind: "none" } };
const [scheme, value = ""] = secret.ref.split("://", 2);
if (scheme === "aws") {
if (awsEndpoint(host)?.api === "gateway") {
return {
ok: false,
code: "UNSIGNABLE_HOST",
reason:
`signs requests to ${host}, the host of an AgentCore gateway, with ${secret.ref}. ` +
"Build signs only for the gateways of this project, and it adds the route to each of " +
"them on AgentCore Runtime itself, as [mcp.<gateway name>], with the host that the " +
"deploy gives the gateway. Remove this entry. To call a gateway, add it to this project.",
};
}
const signing = signingService(host);
if (!signing) {
return {
Expand Down
Loading
Loading