@aws/nx-plugin-mcp 1.0.0-rc.2 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/bin/aws-nx-mcp.js +5919 -4776
  2. package/docs/guides/agentcore-gateway.mdx +240 -0
  3. package/docs/guides/connection/agentcore-gateway-gateway.mdx +154 -0
  4. package/docs/guides/connection/agentcore-gateway-mcp.mdx +134 -0
  5. package/docs/guides/connection/py-agent-a2a.mdx +8 -5
  6. package/docs/guides/connection/py-agent-dynamodb.mdx +116 -0
  7. package/docs/guides/connection/py-agent-gateway.mdx +161 -0
  8. package/docs/guides/connection/py-agent-mcp.mdx +7 -4
  9. package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
  10. package/docs/guides/connection/py-mcp-server-dynamodb.mdx +116 -0
  11. package/docs/guides/connection/react-smithy.mdx +1 -1
  12. package/docs/guides/connection/react-trpc.mdx +1 -1
  13. package/docs/guides/connection/smithy-dynamodb.mdx +68 -0
  14. package/docs/guides/connection/smithy-rdb.mdx +1 -1
  15. package/docs/guides/connection/trpc-dynamodb.mdx +62 -0
  16. package/docs/guides/connection/trpc-rdb.mdx +1 -1
  17. package/docs/guides/connection/ts-agent-a2a.mdx +8 -5
  18. package/docs/guides/connection/ts-agent-dynamodb.mdx +128 -0
  19. package/docs/guides/connection/ts-agent-gateway.mdx +152 -0
  20. package/docs/guides/connection/ts-agent-mcp.mdx +7 -4
  21. package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +125 -0
  22. package/docs/guides/connection.mdx +89 -0
  23. package/docs/guides/docker-bundling.mdx +13 -7
  24. package/docs/guides/fastapi.mdx +213 -3
  25. package/docs/guides/license.mdx +264 -109
  26. package/docs/guides/local-development.mdx +76 -0
  27. package/docs/guides/nx-generator.mdx +5 -0
  28. package/docs/guides/py-agent.mdx +42 -3
  29. package/docs/guides/py-dynamodb.mdx +449 -0
  30. package/docs/guides/py-mcp-server.mdx +5 -1
  31. package/docs/guides/react-website-auth.mdx +15 -0
  32. package/docs/guides/react-website.mdx +12 -4
  33. package/docs/guides/trpc.mdx +8 -8
  34. package/docs/guides/ts-agent.mdx +40 -2
  35. package/docs/guides/ts-dynamodb.mdx +158 -0
  36. package/docs/guides/ts-mcp-server.mdx +5 -1
  37. package/docs/guides/ts-rdb.mdx +58 -10
  38. package/docs/guides/ts-smithy-api.mdx +148 -3
  39. package/docs/guides/typescript-project.mdx +5 -10
  40. package/docs/guides/workspace.mdx +8 -2
  41. package/docs/snippets/api/type-safe-api-integrations.mdx +31 -0
  42. package/docs/snippets/api/waf-configuration.mdx +1 -1
  43. package/docs/snippets/connection/dynamodb-local-development.mdx +7 -0
  44. package/docs/snippets/connection/lambda-dynamodb-access.mdx +80 -0
  45. package/docs/snippets/connection/py-dynamodb-local-development.mdx +7 -0
  46. package/docs/snippets/dynamodb/deploying-table.mdx +171 -0
  47. package/docs/snippets/dynamodb/gsi-config.mdx +38 -0
  48. package/docs/snippets/dynamodb/infrastructure.mdx +33 -0
  49. package/docs/snippets/dynamodb/serve-local-start.mdx +13 -0
  50. package/docs/snippets/dynamodb/serve-local-windows.mdx +15 -0
  51. package/docs/snippets/mcp/config.mdx +1 -1
  52. package/docs/snippets/required-prerequisites.mdx +1 -1
  53. package/generators.json +100 -1
  54. package/package.json +1 -1
  55. package/src/agentcore-gateway/gateway-connection/schema.json +26 -0
  56. package/src/agentcore-gateway/mcp-connection/schema.json +26 -0
  57. package/src/agentcore-gateway/schema.json +65 -0
  58. package/src/license/schema.json +6 -0
  59. package/src/preset/schema.json +5 -0
  60. package/src/py/agent/gateway-connection/schema.json +26 -0
  61. package/src/py/dynamodb/agent-connection/schema.json +22 -0
  62. package/src/py/dynamodb/fast-api-connection/schema.json +18 -0
  63. package/src/py/dynamodb/mcp-server-connection/schema.json +22 -0
  64. package/src/py/dynamodb/schema.json +70 -0
  65. package/src/ts/agent/gateway-connection/schema.json +26 -0
  66. package/src/ts/dynamodb/agent-connection/schema.json +22 -0
  67. package/src/ts/dynamodb/mcp-server-connection/schema.json +22 -0
  68. package/src/ts/dynamodb/schema.json +70 -0
  69. package/src/ts/dynamodb/smithy-connection/schema.json +18 -0
  70. package/src/ts/dynamodb/trpc-connection/schema.json +18 -0
@@ -0,0 +1,240 @@
1
+ ---
2
+ title: AgentCore Gateway
3
+ description: Create an AgentCore Gateway project
4
+ generator: agentcore-gateway
5
+ ---
6
+
7
+ import { FileTree } from '@astrojs/starlight/components';
8
+ import RunGenerator from '@components/run-generator.astro';
9
+ import GeneratorParameters from '@components/generator-parameters.astro';
10
+ import Infrastructure from '@components/infrastructure.astro';
11
+ import Snippet from '@components/snippet.astro';
12
+ import Link from '@components/link.astro';
13
+ import NxCommands from '@components/nx-commands.astro';
14
+ import OptionFilter from '@components/option-filter.astro';
15
+
16
+ Generate an [Amazon Bedrock AgentCore Gateway](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway.html) project. An AgentCore Gateway is a managed entry point that aggregates one or more MCP server targets behind a single MCP endpoint, evaluates every tool call against a [Cedar policy engine](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/policy.html), and signs outbound traffic to MCP servers with IAM SigV4.
17
+
18
+ ## Usage
19
+
20
+ ### Generate an AgentCore Gateway
21
+
22
+ <RunGenerator generator="agentcore-gateway" />
23
+
24
+ ### Options
25
+
26
+ <GeneratorParameters generator="agentcore-gateway" />
27
+
28
+ ## Generator Output
29
+
30
+ The generator creates a new project at `packages/<name>/`, plus a CDK construct or Terraform module for the infrastructure:
31
+
32
+ <FileTree>
33
+ - packages/\<name>/
34
+ - policies/ Cedar policy source files (omitted when `cedarPolicy: false`)
35
+ - permit-all.cedar Default Cedar policy that permits authenticated callers from within the same AWS account
36
+ - README.md Reference for writing Cedar policies
37
+ - serve-local.ts Local gateway aggregating attached MCP servers for local development
38
+ - project.json Adds the \<name>-serve and \<name>-serve-local aggregator targets
39
+ </FileTree>
40
+
41
+ ### Infrastructure
42
+
43
+ Infrastructure is generated when `infra` is `agentcore` (the default). With `infra: none` no infrastructure is generated — re-run the generator with `infra: agentcore` later to add it.
44
+
45
+ <Snippet name="shared-constructs" />
46
+
47
+ <Infrastructure>
48
+ <Fragment slot="cdk">
49
+ <FileTree>
50
+ - packages/common/constructs/src
51
+ - core
52
+ - agentcore-gateway/ Shared gateway construct (readiness probe, Cedar policy loading)
53
+ - app
54
+ - gateways
55
+ - \<name>/
56
+ - \<name>.ts CDK construct for deploying the Gateway
57
+ </FileTree>
58
+ </Fragment>
59
+ <Fragment slot="terraform">
60
+ <FileTree>
61
+ - packages/common/terraform/src
62
+ - app
63
+ - gateways
64
+ - \<name>/
65
+ - \<name>.tf Terraform module for deploying the Gateway
66
+ </FileTree>
67
+ </Fragment>
68
+ </Infrastructure>
69
+
70
+ The generated construct creates the following AWS resources:
71
+
72
+ - An `AgentCore::Gateway` configured for the MCP protocol with `GatewayAuthorizer.usingAwsIam()` (inbound IAM authentication)
73
+ - An `AgentCore::PolicyEngine` running in `ENFORCE` mode, attached to the Gateway (omitted when `cedarPolicy: false`)
74
+ - One `AgentCore::Policy` per `.cedar` file in `policies/`
75
+
76
+ The Gateway URL is automatically registered in the `agentcore.gateways.<ClassName>` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> so agents can discover it at runtime.
77
+
78
+ ## Writing Policies
79
+
80
+ <OptionFilter when={{ cedarPolicy: true }} description="Cedar policies — cedarPolicy: true only">
81
+
82
+ Cedar is the policy language used by AgentCore Gateway to authorize tool calls. Every `tools/list` and `tools/call` request flowing through the Gateway is evaluated against the attached policy set, and the caller must have at least one matching `permit` statement (and no matching `forbid`) for the request to succeed.
83
+
84
+ Refer to the [AWS documentation on AgentCore Gateway policies](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/policy.html) for the full reference, including [common policy patterns](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/policy-common-patterns.html).
85
+
86
+ ### Adding a policy
87
+
88
+ To add a policy, create a new `.cedar` file alongside `permit-all.cedar`. Each `.cedar` file in `policies/` must contain exactly **one** `permit` or `forbid` statement and is deployed as a single `AWS::BedrockAgentCore::Policy` resource. The policy resource's name is derived from the filename: `permit-all.cedar` becomes `PermitAll` (kebab/snake-case is converted to PascalCase). Files containing multiple statements produce `unexpected token 'forbid'` errors at deploy time — split them into separate files.
89
+
90
+ For example, to permit only a specific agent role to invoke a particular tool, create:
91
+
92
+ ```cedar title="packages/<name>/policies/ts-agent-divide.cedar"
93
+ permit (
94
+ principal == AgentCore::IamEntity::"arn:aws:sts::<%= accountId %>:assumed-role/<%= tsAgentRoleName %>",
95
+ action == AgentCore::Action::"ts-mcp___divide",
96
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
97
+ );
98
+ ```
99
+
100
+ Pass the role name in as a template variable (see <a href="#template-variables">Template variables</a> below) rather than hard-coding it. Re-synth or re-plan to deploy the new policy.
101
+
102
+ ### Template variables
103
+
104
+ Policies are [EJS](https://ejs.co/) templates rendered at synth/plan time so they stay portable across accounts and Gateway redeploys:
105
+
106
+ | Variable | Substituted with |
107
+ | -------------------- | --------------------------------------------- |
108
+ | `<%= gatewayArn %>` | The deployed Gateway's ARN |
109
+ | `<%= accountId %>` | The AWS account this Gateway is deployed into |
110
+
111
+ Always reference these variables rather than hard-coding values.
112
+
113
+ #### Adding your own variables
114
+
115
+ Add new variables where the policies are rendered, for example to pass an agent's execution role name to the `ts-agent-divide.cedar` example above:
116
+
117
+ <Infrastructure>
118
+ <Fragment slot="cdk">
119
+ In `packages/common/constructs/src/app/gateways/<name>/<name>.ts`, pass `cedarPolicyVariables` through to the shared construct:
120
+
121
+ ```ts {4-6}
122
+ super(scope, id, {
123
+ cedarPolicyPath: path.join(
124
+ ...
125
+ ),
126
+ cedarPolicyVariables: {
127
+ tsAgentRoleName: cdk.Token.asString(tsAgent.agentCoreRuntime.role.roleName),
128
+ },
129
+ });
130
+ ```
131
+ </Fragment>
132
+ <Fragment slot="terraform">
133
+ In `packages/common/terraform/src/app/gateways/<name>/<name>.tf`, add to the `query` of the `rendered_policies` data source:
134
+
135
+ ```hcl {4}
136
+ query = {
137
+ template = "${local.policies_dir}/${each.value}"
138
+ gatewayArn = aws_bedrockagentcore_gateway.this.gateway_arn
139
+ tsAgentRoleName = var.ts_agent_role_name
140
+ # ...
141
+ }
142
+ ```
143
+ </Fragment>
144
+ </Infrastructure>
145
+
146
+ ### ENFORCE mode and default-deny
147
+
148
+ The `PolicyEngine` runs in `ENFORCE` mode, which means **default-deny** semantics apply: if no `permit` statement matches the (principal, action, resource) tuple, the request is denied. Tool calls that are denied return:
149
+
150
+ ```
151
+ Tool Execution Denied: Tool call not allowed due to policy enforcement
152
+ [No policy applies to the request (denied by default).]
153
+ ```
154
+
155
+ Additionally, the Gateway filters the response of `tools/list` so that callers only see tools they have at least one matching `permit` for: if an agent lacks permission for a given tool, the tool is hidden entirely rather than appearing and failing at call time.
156
+
157
+ ### Default `permit-all.cedar`
158
+
159
+ The generator ships a default policy that permits any IAM caller from the AWS account the Gateway is deployed into:
160
+
161
+ ```cedar title="packages/<name>/policies/permit-all.cedar"
162
+ permit (
163
+ principal is AgentCore::IamEntity,
164
+ action,
165
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
166
+ ) when {
167
+ principal.id like "arn:aws:*::<%= accountId %>:*"
168
+ };
169
+ ```
170
+
171
+ To lock things down further, add narrower policies alongside it. Always retain at least one matching `permit` in the policy set, otherwise default-deny will block every call.
172
+
173
+ ### Policy scope reference
174
+
175
+ For Gateways generated by this plugin, all callers are IAM principals (the Gateway is configured with `GatewayAuthorizer.usingAwsIam()`):
176
+
177
+ ```
178
+ principal is AgentCore::IamEntity
179
+ ```
180
+
181
+ Callers are evaluated as STS assumed-role ARNs with the session name stripped, so a role can be matched exactly — no wildcards needed:
182
+
183
+ ```cedar
184
+ principal == AgentCore::IamEntity::"arn:aws:sts::<%= accountId %>:assumed-role/<%= myAgentRoleName %>"
185
+ ```
186
+
187
+ The same value is available as `principal.id` for `when` clauses. Reserve `like` for genuine patterns, such as the account-wide match in the default `permit-all.cedar`.
188
+
189
+ Tool invocations reach the policy engine as actions with the form:
190
+
191
+ ```
192
+ AgentCore::Action::"<target-name>___<tool-name>"
193
+ ```
194
+
195
+ where `<target-name>` is the Gateway target name (the MCP server's `mcpServerName` by default when using `gateway.addMcpServer(...)`, derived from the MCP project's class name in kebab-case — e.g. `TsMcp` → `ts-mcp`), `<tool-name>` is the MCP tool's name, and the separator is `___` (three underscores). Cedar does not support wildcards on actions — match exact actions, or omit `action ==` to match all actions.
196
+
197
+ The resource is always the Gateway itself:
198
+
199
+ ```cedar
200
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
201
+ ```
202
+
203
+ ### Validation considerations
204
+
205
+ The generated infrastructure creates policies with `IGNORE_ALL_FINDINGS`: AgentCore's Cedar analyzer (`FAIL_ON_ANY_FINDINGS`, the service default) rejects many legitimate policies — for example, a `forbid` disabling a single tool for every caller is rejected as "Overly Restrictive", even when scoped with a `when` clause. Enforcement is unaffected; it is configured by the policy engine's `ENFORCE` mode.
206
+
207
+ One ordering constraint still applies: a policy referencing `AgentCore::Action::"<target>___<tool>"` only validates once the target has registered that tool with the Gateway, which is why the generated infrastructure creates policies after Gateway targets.
208
+
209
+ If a policy fails to deploy, CloudFormation surfaces the rejection as an opaque `Resource stabilization failed` error — run `aws bedrock-agentcore-control list-policies --policy-engine-id <id>` to retrieve the validator's `statusReasons`, which contain the actual reason.
210
+
211
+ ### Example: forbid one tool while keeping a broader permit
212
+
213
+ Pair a narrow `forbid` with a broader `permit` (Cedar evaluates `forbid` over `permit`):
214
+
215
+ ```cedar title="packages/<name>/policies/forbid-divide-for-py-agent.cedar"
216
+ forbid (
217
+ principal == AgentCore::IamEntity::"arn:aws:sts::<%= accountId %>:assumed-role/<%= pyAgentRoleName %>",
218
+ action == AgentCore::Action::"ts-mcp___divide",
219
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
220
+ );
221
+ ```
222
+
223
+ This denies the Python agent role from calling `ts-mcp___divide` while leaving the broader `permit-all.cedar` in place for all other callers.
224
+
225
+ </OptionFilter>
226
+
227
+ ## Local Development
228
+
229
+ The generator adds a `<name>-serve-local` target to the Gateway project, which runs `serve-local.ts`: a local gateway exposing a single MCP endpoint that aggregates every attached MCP server (connected via the <Link path="guides/connection/agentcore-gateway-mcp">`agentcore-gateway#mcp-connection` generator</Link>), with tools prefixed `<target>___<tool>` to match the deployed Gateway. Running it starts the local gateway and all attached MCP servers together.
230
+
231
+ <NxCommands commands={["<name>-serve-local"]} />
232
+
233
+ See the connection guide for the full local development story.
234
+
235
+ ## Next steps
236
+
237
+ - Connect an MCP server: <Link path="guides/connection/agentcore-gateway-mcp">`agentcore-gateway#mcp-connection`</Link>
238
+ - Connect another Gateway: <Link path="guides/connection/agentcore-gateway-gateway">`agentcore-gateway#gateway-connection`</Link>
239
+ - Connect a TypeScript Agent: <Link path="guides/connection/ts-agent-gateway">`ts#agent#gateway-connection`</Link>
240
+ - Connect a Python Agent: <Link path="guides/connection/py-agent-gateway">`py#agent#gateway-connection`</Link>
@@ -0,0 +1,154 @@
1
+ ---
2
+ title: AgentCore Gateway to AgentCore Gateway
3
+ description: Connect an AgentCore Gateway to another AgentCore Gateway
4
+ when:
5
+ sourceType: agentcore-gateway
6
+ targetType: agentcore-gateway
7
+ ---
8
+ import { FileTree } from '@astrojs/starlight/components';
9
+ import Link from '@components/link.astro';
10
+ import RunGenerator from '@components/run-generator.astro';
11
+ import GeneratorParameters from '@components/generator-parameters.astro';
12
+ import NxCommands from '@components/nx-commands.astro';
13
+ import Infrastructure from '@components/infrastructure.astro';
14
+
15
+ The `connection` generator can register an <Link path="guides/agentcore-gateway">AgentCore Gateway</Link> as a target of another AgentCore Gateway. This lets you compose gateways hierarchically — for example a team-level gateway aggregating several domain gateways, each of which fronts its own MCP servers.
16
+
17
+ Once connected, the source Gateway aggregates the target Gateway's tools into its single MCP endpoint. Since the target Gateway already prefixes its tools with its own target names, tools surface through the source Gateway as `<gateway-target-name>___<target-name>___<tool-name>` — each gateway in the chain adds one prefix. Both gateways evaluate their own Cedar policies: the source Gateway authorizes the caller for the prefixed action, then the target Gateway authorizes the source Gateway's execution role for the inner action.
18
+
19
+ ## Prerequisites
20
+
21
+ Before using this generator, ensure you have:
22
+
23
+ 1. Two <Link path="guides/agentcore-gateway">`agentcore-gateway`</Link> projects
24
+
25
+ Both gateways must have `protocol: mcp`, and the target gateway must have `auth: iam` — the source gateway invokes the target signing with its own execution role, so only the target's inbound auth needs to be IAM. The generator validates this, and also rejects connections that would create a cycle between gateways, which would otherwise recurse infinitely on `tools/list`.
26
+
27
+ ## Usage
28
+
29
+ ### Run the Generator
30
+
31
+ <RunGenerator generator="connection" />
32
+
33
+ Select the aggregating Gateway project as the source and the Gateway to be aggregated as the target.
34
+
35
+ ### Options
36
+
37
+ <GeneratorParameters generator="connection" />
38
+
39
+ ## Generator Output
40
+
41
+ The generator wires existing projects together rather than emitting new source files. The following files are modified:
42
+
43
+ <FileTree>
44
+
45
+ - packages/\<source-gateway>
46
+ - project.json `<source-gateway>-serve-local` gains a dependency on the target gateway's `<target-gateway>-serve-local`
47
+ - serve-local.ts `ATTACHED_MCP_SERVERS` updated so the local gateway aggregates the target gateway
48
+
49
+ </FileTree>
50
+
51
+ The source Gateway project's `<source-gateway>-serve-local` target gains a dependency on the target Gateway's `<target-gateway>-serve-local` target, so running the source Gateway locally also starts the target gateway (and, transitively, every MCP server attached to it). The target gateway is also registered in the source Gateway project's `serve-local.ts` so the local gateway aggregates its tools.
52
+
53
+ ## Adding the gateway target to your stack
54
+
55
+ The generator **cannot** automatically wire the gateway target into your infrastructure because it doesn't know which stack or module instantiates the Gateways. Add a single call to `gateway.addGateway(targetGateway)` yourself.
56
+
57
+ <Infrastructure>
58
+ <Fragment slot="cdk">
59
+ In the stack where you instantiate the Gateways, register the target gateway as a target of the source gateway:
60
+
61
+ ```ts title="packages/infra/src/stacks/application-stack.ts" {5-6}
62
+ const innerGateway = new InnerGateway(this, 'InnerGateway');
63
+ const outerGateway = new OuterGateway(this, 'OuterGateway');
64
+
65
+ // Register the inner gateway as a target of the outer gateway. The target
66
+ // name defaults to the inner gateway's `gatewayName` (its class name in
67
+ // kebab-case, e.g. `InnerGateway` -> `inner-gateway`).
68
+ outerGateway.addGateway(innerGateway);
69
+ ```
70
+
71
+ The Gateway target name (the target gateway's `gatewayName` by default) prefixes Cedar action names on the source gateway — the action format is ``AgentCore::Action::"<gatewayTargetName>___<targetName>___<toolName>"``. See the <Link path="guides/agentcore-gateway">Writing Policies section</Link>. Keep the target name short and stable; changing it later invalidates any Cedar policies that reference the old name.
72
+
73
+ To override the default target name, pass `gatewayTargetName`:
74
+
75
+ ```ts
76
+ outerGateway.addGateway(innerGateway, { gatewayTargetName: 'inner' });
77
+ ```
78
+
79
+ The construct grants the source gateway's execution role `bedrock-agentcore:InvokeGateway` access to the target gateway, and configures the target with `iamCredentialProvider.service = 'bedrock-agentcore'` so the source gateway signs outbound calls using its own execution role. The target is created after the target gateway and all of its own targets, since AgentCore fetches the target's tools during creation.
80
+ </Fragment>
81
+ <Fragment slot="terraform">
82
+ In the Terraform file where you instantiate the Gateways, wire the gateway target in:
83
+
84
+ ```hcl title="packages/infra/src/main.tf" {2-5,11-15,18-36}
85
+ module "inner_gateway" {
86
+ source = "../../common/terraform/src/app/gateways/inner-gateway"
87
+
88
+ # Target ids of the inner gateway's own targets (e.g. its MCP servers), so
89
+ # its gateway_url is not consumed until it serves their tools.
90
+ tool_dependencies = [aws_bedrockagentcore_gateway_target.my_mcp_server.target_id]
91
+ }
92
+
93
+ module "outer_gateway" {
94
+ source = "../../common/terraform/src/app/gateways/outer-gateway"
95
+ policy_dependencies = [aws_bedrockagentcore_gateway_target.inner_gateway.target_id]
96
+
97
+ additional_iam_policy_statements = [
98
+ {
99
+ Effect = "Allow"
100
+ Action = ["bedrock-agentcore:InvokeGateway"]
101
+ Resource = [module.inner_gateway.gateway_arn]
102
+ }
103
+ ]
104
+ }
105
+
106
+ # Register the inner gateway as a target of the outer gateway
107
+ resource "aws_bedrockagentcore_gateway_target" "inner_gateway" {
108
+ gateway_identifier = module.outer_gateway.gateway_id
109
+ name = "inner-gateway"
110
+
111
+ target_configuration {
112
+ mcp {
113
+ mcp_server {
114
+ endpoint = module.inner_gateway.gateway_url
115
+ }
116
+ }
117
+ }
118
+
119
+ credential_provider_configuration {
120
+ gateway_iam_role {
121
+ service = "bedrock-agentcore"
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ The target `name` (`inner-gateway` above) prefixes Cedar action names on the outer gateway — see the <Link path="guides/agentcore-gateway">Writing Policies section</Link>. The `additional_iam_policy_statements` entry grants the outer gateway's execution role invoke access to the inner gateway, which is required both to fetch the inner gateway's tools at target creation time and to route calls at runtime. `policy_dependencies` ensures Cedar policies referencing this target's actions are created after the target has registered them.
128
+
129
+ :::note[Target ordering]
130
+ AgentCore fetches the inner gateway's tools when the `aws_bedrockagentcore_gateway_target` is created, so the inner gateway must already be serving them. Set the inner gateway's `tool_dependencies` to its own targets' ids: its `gateway_url` then flows through a readiness probe that polls `tools/list` until those tools are served, so the outer gateway's target waits for the inner gateway to be ready.
131
+ :::
132
+ </Fragment>
133
+ </Infrastructure>
134
+
135
+ ## Cedar policies across chained gateways
136
+
137
+ Each gateway in the chain evaluates its own policy set:
138
+
139
+ 1. The **source gateway** evaluates the original caller (e.g. an agent's execution role) against the prefixed action, e.g. `AgentCore::Action::"inner-gateway___my-mcp___add"`.
140
+ 2. The **target gateway** evaluates the source gateway's execution role against the inner action, e.g. `AgentCore::Action::"my-mcp___add"`.
141
+
142
+ This means a tool call through a gateway chain must be permitted at every hop. The default `permit-all.cedar` permits any caller in the same AWS account, which includes the source gateway's role; if you write narrower policies on the target gateway, remember that the principal it sees is the *source gateway's* role, not the original caller.
143
+
144
+ ## Local Development
145
+
146
+ Running the source Gateway locally with:
147
+
148
+ <NxCommands commands={["<source-gateway-name>-serve-local"]} />
149
+
150
+ starts the local source gateway, the local target gateway, and every MCP server attached to either, each on its assigned local port. Tool names are prefixed at each hop exactly as deployed (`<gateway-target-name>___<target-name>___<tool-name>`), so agent prompts and Cedar action names remain consistent across local and deployed runs.
151
+
152
+ :::caution[Local fidelity]
153
+ Local development uses **local stand-in gateways** — lightweight MCP aggregators started by each Gateway project, not the AgentCore Gateway service. As a consequence, **Cedar policies are not evaluated locally** at either hop. To exercise Cedar policies, run the agent's `serve` target instead (see the <Link path="guides/connection/ts-agent-gateway">TypeScript</Link> / <Link path="guides/connection/py-agent-gateway">Python</Link> agent-connection guides) so the locally-running agent calls the deployed Gateway.
154
+ :::
@@ -0,0 +1,134 @@
1
+ ---
2
+ title: AgentCore Gateway to MCP Server
3
+ description: Connect an AgentCore Gateway to an MCP server
4
+ when:
5
+ sourceType: agentcore-gateway
6
+ targetType:
7
+ - ts#mcp-server
8
+ - py#mcp-server
9
+ ---
10
+ import { FileTree } from '@astrojs/starlight/components';
11
+ import Link from '@components/link.astro';
12
+ import RunGenerator from '@components/run-generator.astro';
13
+ import GeneratorParameters from '@components/generator-parameters.astro';
14
+ import NxCommands from '@components/nx-commands.astro';
15
+ import Infrastructure from '@components/infrastructure.astro';
16
+
17
+ The `connection` generator can register an MCP server (either <Link path="guides/ts-mcp-server">TypeScript</Link> or <Link path="guides/py-mcp-server">Python</Link>) as a target of an <Link path="guides/agentcore-gateway">AgentCore Gateway</Link>.
18
+
19
+ Once connected, the Gateway aggregates the MCP server's tools into its single MCP endpoint, evaluates calls against its Cedar policy engine, and signs outbound traffic to the MCP server with IAM SigV4.
20
+
21
+ ## Prerequisites
22
+
23
+ Before using this generator, ensure you have:
24
+
25
+ 1. A <Link path="guides/agentcore-gateway">`agentcore-gateway`</Link> project
26
+ 2. An MCP server component (<Link path="guides/ts-mcp-server">`ts#mcp-server`</Link> or <Link path="guides/py-mcp-server">`py#mcp-server`</Link>) created with `infra: agentcore` and `auth: iam`
27
+
28
+ The Gateway must have `protocol: mcp` and the MCP server must have `auth: iam` — the generator validates both. Non-IAM MCP servers cannot be attached because the Gateway signs outbound traffic with SigV4.
29
+
30
+ ## Usage
31
+
32
+ ### Run the Generator
33
+
34
+ <RunGenerator generator="connection" />
35
+
36
+ Select the Gateway project as the source and the MCP server project as the target. If the MCP server project contains multiple components, specify `targetComponent` to disambiguate.
37
+
38
+ ### Options
39
+
40
+ <GeneratorParameters generator="connection" />
41
+
42
+ ## Generator Output
43
+
44
+ The generator wires existing projects together rather than emitting new source files. The following files are modified:
45
+
46
+ <FileTree>
47
+
48
+ - packages/\<gateway>
49
+ - project.json `<gateway>-serve-local` gains a dependency on the MCP server's `<mcp>-serve-local`
50
+ - serve-local.ts `ATTACHED_MCP_SERVERS` updated so the local gateway aggregates the MCP server
51
+
52
+ </FileTree>
53
+
54
+ The Gateway project's `<gateway>-serve-local` target gains a dependency on the MCP server's `<mcp>-serve-local` target, so running the Gateway locally also starts the MCP server. The MCP server is also registered in the Gateway project's `serve-local.ts` so the local gateway aggregates its tools.
55
+
56
+ ## Adding the MCP server target to your stack
57
+
58
+ The generator **cannot** automatically wire the MCP server target into your infrastructure because it doesn't know which stack or module instantiates the Gateway. Add a single call to `gateway.addMcpServer(server)` yourself.
59
+
60
+ <Infrastructure>
61
+ <Fragment slot="cdk">
62
+ In the stack where you instantiate the Gateway, register the MCP server as a target:
63
+
64
+ ```ts title="packages/infra/src/stacks/application-stack.ts" {5-6}
65
+ const myMcpServer = new MyMcpServer(this, 'MyMcpServer');
66
+ const myGateway = new MyGateway(this, 'MyGateway');
67
+
68
+ // Register the MCP server as a target of the Gateway. The target name
69
+ // defaults to the MCP server's `mcpServerName` (its class name in
70
+ // kebab-case, e.g. `MyMcpServer` -> `my-mcp-server`).
71
+ myGateway.addMcpServer(myMcpServer);
72
+ ```
73
+
74
+ The Gateway target name (the MCP server's `mcpServerName` by default) is used as the prefix for Cedar action names — the action format is ``AgentCore::Action::"<targetName>___<toolName>"``. See the <Link path="guides/agentcore-gateway">Writing Policies section</Link>. Keep the target name short and stable; changing it later invalidates any Cedar policies that reference the old name.
75
+
76
+ To override the default target name, pass `gatewayTargetName`:
77
+
78
+ ```ts
79
+ myGateway.addMcpServer(myMcpServer, { gatewayTargetName: 'my-mcp' });
80
+ ```
81
+
82
+ The construct configures the target with `iamCredentialProvider.service = 'bedrock-agentcore'` so the Gateway signs outbound calls using its own execution role.
83
+ </Fragment>
84
+ <Fragment slot="terraform">
85
+ In the Terraform file where you instantiate the Gateway, wire the MCP server target in:
86
+
87
+ ```hcl title="packages/infra/src/main.tf" {7,11-27}
88
+ module "my_mcp_server" {
89
+ source = "../../common/terraform/src/app/mcp-servers/my-mcp-server"
90
+ }
91
+
92
+ module "my_gateway" {
93
+ source = "../../common/terraform/src/app/gateways/my-gateway"
94
+ policy_dependencies = [aws_bedrockagentcore_gateway_target.my_mcp_server.target_id]
95
+ }
96
+
97
+ # Register the MCP server as a target of the Gateway
98
+ resource "aws_bedrockagentcore_gateway_target" "my_mcp_server" {
99
+ gateway_identifier = module.my_gateway.gateway_id
100
+ name = "my-mcp-server"
101
+
102
+ target_configuration {
103
+ mcp {
104
+ mcp_server {
105
+ endpoint = "https://bedrock-agentcore.${local.aws_region}.amazonaws.com/runtimes/${urlencode(module.my_mcp_server.agent_core_runtime_arn)}/invocations?qualifier=DEFAULT"
106
+ }
107
+ }
108
+ }
109
+
110
+ credential_provider_configuration {
111
+ gateway_iam_role {
112
+ service = "bedrock-agentcore"
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ The target `name` (`my-mcp-server` above) is used as the prefix for Cedar action names — see the <Link path="guides/agentcore-gateway">Writing Policies section</Link>. `policy_dependencies` ensures Cedar policies referencing this target's actions are created after the target has registered them.
119
+ </Fragment>
120
+ </Infrastructure>
121
+
122
+ ## Local Development
123
+
124
+ Running the Gateway locally with:
125
+
126
+ <NxCommands commands={["<gateway-name>-serve-local"]} />
127
+
128
+ starts a local gateway plus every attached MCP server on its assigned local port. The local gateway exposes a single MCP endpoint that aggregates the attached servers' tools. Agents connected to the Gateway via the <Link path="guides/connection/ts-agent-gateway">TypeScript</Link> or <Link path="guides/connection/py-agent-gateway">Python</Link> gateway-connection generators point at it when running with `SERVE_LOCAL=true`.
129
+
130
+ :::caution[Local fidelity]
131
+ Local development uses a **local stand-in gateway** — a lightweight MCP aggregator started by the Gateway project, not the AgentCore Gateway service. As a consequence, **Cedar policies are not evaluated locally**. Every agent sees every tool on every attached MCP server. To exercise Cedar policies, run the agent's `serve` target instead (see the <Link path="guides/connection/ts-agent-gateway">TypeScript</Link> / <Link path="guides/connection/py-agent-gateway">Python</Link> agent-connection guides) so the locally-running agent calls the deployed Gateway.
132
+
133
+ Tool names are still prefixed locally as `<target-name>___<tool-name>` to match the deployed Gateway's namespacing, so an agent's system prompt and the Cedar action names you reference remain consistent across local and deployed runs.
134
+ :::
@@ -48,9 +48,12 @@ The generator creates a shared `agent_connection` Python project at `packages/co
48
48
  - \<scope>\_agent\_connection
49
49
  - \_\_init\_\_.py Re-exports per-connection clients
50
50
  - core
51
- - agentcore\_a2a\_client.py Core AgentCore A2A client with SigV4 authentication
51
+ - agentcore\_endpoints.py Framework-agnostic ARN/URL resolution
52
+ - agentcore\_a2a\_client\_config.py Framework-agnostic A2A client config (signed `ClientConfig`)
53
+ - agentcore\_a2a\_client\_strands.py Strands A2A client wrapping the config
54
+ - auth/ Framework-agnostic SigV4 / session-forwarding `httpx.Auth`
52
55
  - app
53
- - \<target\_agent\_name>\_client.py Per-connection client for each A2A agent
56
+ - \<target\_agent\_name>\_client\_strands.py Per-connection Strands client for each A2A agent
54
57
 
55
58
  </FileTree>
56
59
 
@@ -67,11 +70,11 @@ The generator transforms your agent's `agent.py` to wrap the remote A2A agent as
67
70
  from contextlib import contextmanager
68
71
  from strands import Agent, tool
69
72
 
70
- from my_scope_agent_connection import RemoteAgentClient
73
+ from my_scope_agent_connection import RemoteAgentClientStrands
71
74
 
72
75
  @contextmanager
73
76
  def get_agent(session_id: str):
74
- remote_agent = RemoteAgentClient.create(session_id=session_id)
77
+ remote_agent = RemoteAgentClientStrands.create(session_id=session_id)
75
78
 
76
79
  @tool
77
80
  def ask_remote_agent(prompt: str) -> str:
@@ -86,7 +89,7 @@ def get_agent(session_id: str):
86
89
 
87
90
  The `session_id` parameter is plumbed through from the caller, ensuring consistency for [Bedrock AgentCore Observability](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability.html).
88
91
 
89
- Under the hood, `RemoteAgentClient.create(session_id=...)` returns a Strands `A2AAgent` configured with an `httpx.AsyncClient` that signs requests with SigV4 when deployed to AWS, and a plain `http://localhost:<port>/` endpoint when `SERVE_LOCAL=true`.
92
+ Under the hood, `RemoteAgentClientStrands.create(session_id=...)` returns a Strands `A2AAgent` configured with an `httpx.AsyncClient` that signs requests with SigV4 when deployed to AWS, and a plain `http://localhost:<port>/` endpoint when `SERVE_LOCAL=true`.
90
93
 
91
94
  ## Infrastructure
92
95