@aws/nx-plugin-mcp 1.0.0-rc.7 → 1.0.0-rc.71

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 (195) hide show
  1. package/bin/aws-nx-mcp.js +12317 -10933
  2. package/docs/get_started/building-with-ai.mdx +116 -0
  3. package/docs/get_started/concepts.mdx +67 -0
  4. package/docs/get_started/existing-project.mdx +180 -0
  5. package/docs/get_started/graph-builder.mdx +39 -0
  6. package/docs/get_started/quick-start.mdx +277 -0
  7. package/docs/get_started/tutorials/contribute-generator.mdx +408 -0
  8. package/docs/get_started/tutorials/dungeon-game/1.mdx +1301 -0
  9. package/docs/get_started/tutorials/dungeon-game/2.mdx +237 -0
  10. package/docs/get_started/tutorials/dungeon-game/3.mdx +76 -0
  11. package/docs/get_started/tutorials/dungeon-game/4.mdx +164 -0
  12. package/docs/get_started/tutorials/dungeon-game/overview.mdx +145 -0
  13. package/docs/get_started/tutorials/dungeon-game/wrap-up.mdx +41 -0
  14. package/docs/get_started/tutorials/existing-project.mdx +4 -0
  15. package/docs/get_started/upgrading.mdx +147 -0
  16. package/docs/guides/agentcore-gateway.mdx +490 -0
  17. package/docs/guides/agentcore-harness.mdx +275 -0
  18. package/docs/guides/astro-docs.mdx +8 -0
  19. package/docs/guides/connection/agentcore-gateway-agent.mdx +222 -0
  20. package/docs/guides/connection/agentcore-gateway-gateway.mdx +154 -0
  21. package/docs/guides/connection/agentcore-gateway-mcp.mdx +134 -0
  22. package/docs/guides/connection/py-agent-a2a.mdx +48 -16
  23. package/docs/guides/connection/py-agent-dynamodb.mdx +116 -0
  24. package/docs/guides/connection/py-agent-gateway.mdx +178 -0
  25. package/docs/guides/connection/py-agent-mcp.mdx +43 -14
  26. package/docs/guides/connection/py-agent-rdb.mdx +178 -0
  27. package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
  28. package/docs/guides/connection/py-fast-api-rdb.mdx +184 -0
  29. package/docs/guides/connection/py-mcp-server-dynamodb.mdx +116 -0
  30. package/docs/guides/connection/py-mcp-server-rdb.mdx +187 -0
  31. package/docs/guides/connection/react-agentcore-gateway.mdx +112 -0
  32. package/docs/guides/connection/react-agui.mdx +13 -13
  33. package/docs/guides/connection/react-fastapi.mdx +38 -2
  34. package/docs/guides/connection/react-py-agent.mdx +9 -15
  35. package/docs/guides/connection/react-smithy.mdx +3 -3
  36. package/docs/guides/connection/react-trpc.mdx +1 -1
  37. package/docs/guides/connection/react-ts-agent.mdx +8 -8
  38. package/docs/guides/connection/smithy-dynamodb.mdx +5 -5
  39. package/docs/guides/connection/smithy-rdb.mdx +9 -9
  40. package/docs/guides/connection/trpc-dynamodb.mdx +5 -5
  41. package/docs/guides/connection/trpc-rdb.mdx +6 -6
  42. package/docs/guides/connection/ts-agent-a2a.mdx +14 -11
  43. package/docs/guides/connection/ts-agent-dynamodb.mdx +5 -5
  44. package/docs/guides/connection/ts-agent-gateway.mdx +143 -0
  45. package/docs/guides/connection/ts-agent-mcp.mdx +12 -9
  46. package/docs/guides/connection/ts-agent-rdb.mdx +70 -25
  47. package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +5 -5
  48. package/docs/guides/connection/ts-mcp-server-rdb.mdx +68 -18
  49. package/docs/guides/connection.mdx +122 -5
  50. package/docs/guides/docker-bundling.mdx +69 -12
  51. package/docs/guides/fastapi.mdx +249 -9
  52. package/docs/guides/local-development.mdx +87 -0
  53. package/docs/guides/nx-generator.mdx +4 -3
  54. package/docs/guides/nx-migration.mdx +165 -0
  55. package/docs/guides/py-agent.mdx +264 -49
  56. package/docs/guides/py-dynamodb.mdx +476 -0
  57. package/docs/guides/py-mcp-server.mdx +61 -2
  58. package/docs/guides/py-rdb.mdx +265 -0
  59. package/docs/guides/python-lambda-function.mdx +1 -1
  60. package/docs/guides/react-website-auth.mdx +65 -4
  61. package/docs/guides/react-website.mdx +149 -30
  62. package/docs/guides/runtime-config.mdx +1 -1
  63. package/docs/guides/security.mdx +75 -0
  64. package/docs/guides/smithy-project.mdx +167 -0
  65. package/docs/guides/terraform-project.mdx +2 -2
  66. package/docs/guides/trpc.mdx +53 -16
  67. package/docs/guides/ts-agent.mdx +183 -10
  68. package/docs/guides/ts-dcr-proxy.mdx +569 -0
  69. package/docs/guides/ts-dynamodb.mdx +66 -242
  70. package/docs/guides/ts-lambda-function.mdx +1 -1
  71. package/docs/guides/ts-mcp-server.mdx +109 -29
  72. package/docs/guides/ts-nx-plugin.mdx +3 -3
  73. package/docs/guides/ts-rdb.mdx +113 -467
  74. package/docs/guides/ts-smithy-api.mdx +258 -18
  75. package/docs/guides/typescript-infrastructure.mdx +46 -24
  76. package/docs/guides/typescript-project.mdx +134 -27
  77. package/docs/guides/workspace.mdx +10 -3
  78. package/docs/snippets/agent/architecture.mdx +1 -1
  79. package/docs/snippets/agent/bedrock-deployment.mdx +9 -5
  80. package/docs/snippets/agent/runtime-arn.mdx +23 -2
  81. package/docs/snippets/agent/securing-your-agent.mdx +39 -0
  82. package/docs/snippets/api/access-logging.mdx +33 -0
  83. package/docs/snippets/api/cors-configuration-cdk-note.mdx +1 -1
  84. package/docs/snippets/api/cors-configuration-terraform-note.mdx +1 -1
  85. package/docs/snippets/api/type-safe-api-integrations.mdx +33 -2
  86. package/docs/snippets/api/waf-configuration.mdx +3 -3
  87. package/docs/snippets/connection/a2a-infrastructure.mdx +1 -1
  88. package/docs/snippets/connection/dynamodb-local-development.mdx +2 -2
  89. package/docs/snippets/connection/lambda-dynamodb-access.mdx +1 -1
  90. package/docs/snippets/connection/py-dynamodb-local-development.mdx +7 -0
  91. package/docs/snippets/connection/py-lambda-rdb-ssl-requirements.mdx +7 -0
  92. package/docs/snippets/connection/rdb-api-infrastructure.mdx +51 -19
  93. package/docs/snippets/dynamodb/deploying-table.mdx +166 -0
  94. package/docs/snippets/dynamodb/gsi-config.mdx +38 -0
  95. package/docs/snippets/dynamodb/infrastructure.mdx +33 -0
  96. package/docs/snippets/dynamodb/local-dev-start.mdx +13 -0
  97. package/docs/snippets/dynamodb/local-dev-windows.mdx +15 -0
  98. package/docs/snippets/lambda-function/deploying-your-function.mdx +3 -3
  99. package/docs/snippets/mcp/architecture.mdx +1 -1
  100. package/docs/snippets/mcp/bedrock-deployment.mdx +9 -5
  101. package/docs/snippets/mcp/config.mdx +3 -2
  102. package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +7 -5
  103. package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +29 -10
  104. package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +4 -4
  105. package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +5 -111
  106. package/docs/snippets/prerequisites.mdx +1 -4
  107. package/docs/snippets/rdb/architecture.mdx +38 -0
  108. package/docs/snippets/rdb/cluster-instances.mdx +31 -0
  109. package/docs/snippets/rdb/deletion-protection.mdx +34 -0
  110. package/docs/snippets/rdb/deploying.mdx +187 -0
  111. package/docs/snippets/rdb/encryption-key-rotation.mdx +30 -0
  112. package/docs/snippets/rdb/engine-version.mdx +63 -0
  113. package/docs/snippets/rdb/infrastructure.mdx +35 -0
  114. package/docs/snippets/rdb/logging-mysql.mdx +5 -0
  115. package/docs/snippets/rdb/logging-postgres.mdx +5 -0
  116. package/docs/snippets/rdb/performance-insights.mdx +34 -0
  117. package/docs/snippets/rdb/rds-proxy.mdx +50 -0
  118. package/docs/snippets/rdb/removal-policy.mdx +57 -0
  119. package/docs/snippets/rdb/serverless-capacity.mdx +32 -0
  120. package/docs/snippets/recommended-prerequisites.mdx +10 -0
  121. package/docs/snippets/required-prerequisites.mdx +1 -4
  122. package/docs/snippets/runtime-config-app-id-note.mdx +8 -0
  123. package/docs/snippets/shared-constructs.mdx +1 -1
  124. package/docs/snippets/trivy-image-scan.mdx +37 -0
  125. package/generators.json +152 -10
  126. package/package.json +1 -1
  127. package/src/agentcore-gateway/agent-connection/schema.json +31 -0
  128. package/src/agentcore-gateway/gateway-connection/schema.json +31 -0
  129. package/src/agentcore-gateway/mcp-connection/schema.json +31 -0
  130. package/src/agentcore-gateway/react-connection/schema.json +31 -0
  131. package/src/agentcore-gateway/schema.json +72 -0
  132. package/src/agentcore-harness/schema.json +53 -0
  133. package/src/connection/schema.json +5 -0
  134. package/src/infra/app/schema.json +5 -0
  135. package/src/init/schema.json +35 -0
  136. package/src/internal/test-matrix/schema.json +21 -0
  137. package/src/license/schema.json +5 -0
  138. package/src/preset/schema.json +16 -5
  139. package/src/py/agent/a2a-connection/schema.json +5 -0
  140. package/src/py/agent/gateway-connection/schema.json +31 -0
  141. package/src/py/agent/mcp-connection/schema.json +5 -0
  142. package/src/py/agent/react-connection/schema.json +5 -0
  143. package/src/py/agent/schema.json +15 -1
  144. package/src/py/api/schema.json +5 -0
  145. package/src/py/dynamodb/agent-connection/schema.json +27 -0
  146. package/src/py/dynamodb/fast-api-connection/schema.json +23 -0
  147. package/src/py/dynamodb/mcp-server-connection/schema.json +27 -0
  148. package/src/py/dynamodb/schema.json +76 -0
  149. package/src/py/fast-api/react/schema.json +5 -0
  150. package/src/py/fast-api/schema.json +6 -0
  151. package/src/py/lambda-function/schema.json +5 -0
  152. package/src/py/mcp-server/schema.json +6 -0
  153. package/src/py/project/schema.json +5 -0
  154. package/src/py/rdb/agent-connection/schema.json +27 -0
  155. package/src/py/rdb/fast-api-connection/schema.json +23 -0
  156. package/src/py/rdb/mcp-server-connection/schema.json +27 -0
  157. package/src/py/rdb/schema.json +78 -0
  158. package/src/smithy/project/schema.json +28 -1
  159. package/src/smithy/react-connection/schema.json +5 -0
  160. package/src/smithy/ts/api/schema.json +6 -0
  161. package/src/terraform/project/schema.json +5 -0
  162. package/src/trpc/backend/schema.json +6 -0
  163. package/src/trpc/react/schema.json +5 -0
  164. package/src/ts/agent/a2a-connection/schema.json +5 -0
  165. package/src/ts/agent/gateway-connection/schema.json +31 -0
  166. package/src/ts/agent/mcp-connection/schema.json +5 -0
  167. package/src/ts/agent/react-connection/schema.json +5 -0
  168. package/src/ts/agent/schema.json +14 -0
  169. package/src/ts/api/schema.json +5 -0
  170. package/src/ts/astro-docs/schema.json +3 -3
  171. package/src/ts/dcr-proxy/schema.json +44 -0
  172. package/src/ts/docs/schema.json +3 -3
  173. package/src/ts/dynamodb/agent-connection/schema.json +5 -0
  174. package/src/ts/dynamodb/mcp-server-connection/schema.json +5 -0
  175. package/src/ts/dynamodb/schema.json +26 -2
  176. package/src/ts/dynamodb/smithy-connection/schema.json +5 -0
  177. package/src/ts/dynamodb/trpc-connection/schema.json +5 -0
  178. package/src/ts/lambda-function/schema.json +5 -0
  179. package/src/ts/lib/schema.json +5 -0
  180. package/src/ts/mcp-server/schema.json +6 -0
  181. package/src/ts/nx-generator/schema.json +5 -0
  182. package/src/ts/nx-migration/schema.json +63 -0
  183. package/src/ts/nx-plugin/schema.json +5 -0
  184. package/src/ts/rdb/agent-connection/schema.json +5 -0
  185. package/src/ts/rdb/mcp-server-connection/schema.json +5 -0
  186. package/src/ts/rdb/schema.json +7 -1
  187. package/src/ts/rdb/smithy-connection/schema.json +5 -0
  188. package/src/ts/rdb/trpc-connection/schema.json +5 -0
  189. package/src/ts/react-website/app/schema.json +12 -6
  190. package/src/ts/react-website/cognito-auth/schema.json +5 -0
  191. package/src/ts/react-website/runtime-config/schema.json +5 -0
  192. package/src/ts/website/app/schema.json +11 -6
  193. package/src/ts/website/auth/schema.json +5 -0
  194. /package/docs/snippets/connection/{lambda-rdb-ssl-requirements.mdx → ts-lambda-rdb-ssl-requirements.mdx} +0 -0
  195. /package/docs/snippets/connection/{mcp-server-rdb-ssl-requirements.mdx → ts-mcp-server-rdb-ssl-requirements.mdx} +0 -0
@@ -0,0 +1,490 @@
1
+ ---
2
+ title: AgentCore Gateway
3
+ description: Create an AgentCore Gateway project
4
+ generator: agentcore-gateway
5
+ ---
6
+
7
+ import { FileTree, CardGrid } from '@astrojs/starlight/components';
8
+ import Astro from '@astrojs/react';
9
+ import ConnectionCard from '@components/connection-card.astro';
10
+ import RunGenerator from '@components/run-generator.astro';
11
+ import GeneratorParameters from '@components/generator-parameters.astro';
12
+ import Infrastructure from '@components/infrastructure.astro';
13
+ import Snippet from '@components/snippet.astro';
14
+ import Link from '@components/link.astro';
15
+ import NxCommands from '@components/nx-commands.astro';
16
+ import OptionFilter from '@components/option-filter.astro';
17
+
18
+ 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 in front of your MCP servers or agents, authenticating inbound requests (IAM or Cognito) and signing outbound traffic to its targets with IAM SigV4.
19
+
20
+ The `protocol` option selects what the Gateway fronts:
21
+
22
+ - **`mcp`** (default) — aggregates one or more MCP server targets behind a single MCP endpoint, and evaluates every tool call against a [Cedar policy engine](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/policy.html).
23
+ - **`http`** — proxies requests directly to [AgentCore Runtime targets](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-target-http-runtime.html) (your agents) via path-based routing (`/<targetName>/invocations`), without aggregation or protocol translation. Use this to front agents with a single governed endpoint — for example so a website can reach agents that are deployed inside a VPC through the Gateway.
24
+
25
+ ## Usage
26
+
27
+ ### Generate an AgentCore Gateway
28
+
29
+ <RunGenerator generator="agentcore-gateway" />
30
+
31
+ ### Options
32
+
33
+ <GeneratorParameters generator="agentcore-gateway" />
34
+
35
+ ## Generator Output
36
+
37
+ The generator creates a new project at `packages/<name>/`, plus a CDK construct or Terraform module for the infrastructure:
38
+
39
+ <FileTree>
40
+ - packages/\<name>/
41
+ - policies/ Cedar policy source files (`mcp` protocol only; omitted when `cedarPolicy: false`)
42
+ - permit-all.cedar Default Cedar policy that permits authenticated callers
43
+ - README.md Reference for writing Cedar policies
44
+ - local-dev.ts Local gateway for local development — aggregates attached MCP servers (`mcp`) or proxies attached agents (`http`)
45
+ - project.json Adds the `serve` and `dev` targets
46
+ </FileTree>
47
+
48
+ ### Infrastructure
49
+
50
+ 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.
51
+
52
+ <Snippet name="shared-constructs" />
53
+
54
+ <Infrastructure>
55
+ <Fragment slot="cdk">
56
+ <FileTree>
57
+ - packages/common/constructs/src
58
+ - core
59
+ - agentcore-gateway/ Shared gateway construct (readiness probe, Cedar policy loading)
60
+ - app
61
+ - gateways
62
+ - \<name>/
63
+ - \<name>.ts CDK construct for deploying the Gateway
64
+ </FileTree>
65
+ </Fragment>
66
+ <Fragment slot="terraform">
67
+ <FileTree>
68
+ - packages/common/terraform/src
69
+ - app
70
+ - gateways
71
+ - \<name>/
72
+ - \<name>.tf Terraform module for deploying the Gateway
73
+ </FileTree>
74
+ </Fragment>
75
+ </Infrastructure>
76
+
77
+ The generated construct creates the following AWS resources:
78
+
79
+ - An `AgentCore::Gateway` with inbound IAM authentication (default) or Cognito JWT authentication (see <a href="#authentication">Authentication</a>). An `mcp` gateway is configured for the MCP protocol; an `http` gateway has no protocol type, which AgentCore requires for its runtime targets
80
+ - An `AgentCore::PolicyEngine` running in `ENFORCE` mode, attached to the Gateway (`mcp` gateways only; omitted when `cedarPolicy: false`)
81
+ - One `AgentCore::Policy` per `.cedar` file in `policies/` (`mcp` gateways only)
82
+ - An AWS WAFv2 Web ACL associated with the Gateway, with request logging to CloudWatch (enabled by default — see <a href="#aws-waf">AWS WAF</a>)
83
+
84
+ 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.
85
+
86
+ #### Architecture
87
+
88
+ The deployed Gateway has the following architecture, with an [AWS WAFv2](https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html) Web ACL in front of the Gateway, which routes on to its downstream MCP server targets:
89
+
90
+ ```d2 inline=true
91
+ direction: right
92
+
93
+ client: Client {
94
+ shape: image
95
+ icon: /nx-plugin-for-aws/icons/aws/client.svg
96
+ }
97
+
98
+ waf: WAF {
99
+ shape: image
100
+ icon: /nx-plugin-for-aws/icons/aws/waf.svg
101
+ }
102
+
103
+ gateway: AgentCore Gateway\n(MCP, IAM or Cognito auth) {
104
+ shape: image
105
+ icon: /nx-plugin-for-aws/icons/aws/bedrock-agentcore-gateway.svg
106
+ }
107
+
108
+ targets: Downstream MCP Servers\n(Gateway targets) {
109
+ shape: rectangle
110
+ }
111
+
112
+ client -> waf
113
+ waf -> gateway
114
+ gateway -> targets
115
+ ```
116
+
117
+ ## Authentication
118
+
119
+ The `auth` option configures how the Gateway authenticates inbound requests. Choose between `iam` (default) and `cognito`.
120
+
121
+ ### IAM
122
+
123
+ By default, the Gateway is configured with `GatewayAuthorizer.usingAwsIam()`. Callers sign requests with SigV4, and the caller's IAM identity is available to Cedar policies as an `AgentCore::IamEntity` principal. This is the recommended option when your callers are agents or services running in AWS — for example an <Link path="/guides/ts-agent">agent</Link> connected via the <Link path="guides/connection/ts-agent-gateway">agent to Gateway connection generator</Link>, which signs its calls with its own execution role.
124
+
125
+ ### Cognito
126
+
127
+ When you select `cognito`, the Gateway is configured with a Custom JWT authorizer pointing at a Cognito user pool. Callers authenticate by presenting a JWT bearer token, and the token's `sub` claim is available to Cedar policies as an `AgentCore::OAuthUser` principal. Use this when your callers authenticate through Cognito — for example a website or a coding agent connecting via the <Link path="guides/ts-dcr-proxy">`ts#dcr-proxy` generator</Link>.
128
+
129
+ The generated infrastructure consumes an existing Cognito user pool and client — it does not create them. You can generate a `UserIdentity` using the <Link path="/guides/react-website-auth">`ts#website#auth` generator</Link>, or provide your own.
130
+
131
+ <Infrastructure>
132
+ <Fragment slot="cdk">
133
+ The generated construct requires an `identity` prop supplying the user pool and client:
134
+
135
+ ```ts {7,9-11} title="packages/infra/src/stacks/application-stack.ts"
136
+ import { MyGateway, UserIdentity } from ':my-scope/common-constructs';
137
+
138
+ export class ApplicationStack extends Stack {
139
+ constructor(scope: Construct, id: string, props?: StackProps) {
140
+ super(scope, id, props);
141
+
142
+ const identity = new UserIdentity(this, 'Identity');
143
+
144
+ new MyGateway(this, 'MyGateway', {
145
+ identity,
146
+ });
147
+ }
148
+ }
149
+ ```
150
+ </Fragment>
151
+ <Fragment slot="terraform">
152
+ The generated module requires `user_pool_id` and `user_pool_client_ids` variables:
153
+
154
+ ```hcl {7-8} title="packages/infra/src/main.tf"
155
+ module "user_identity" {
156
+ source = "../../common/terraform/src/core/user-identity"
157
+ }
158
+
159
+ module "my_gateway" {
160
+ source = "../../common/terraform/src/app/gateways/my-gateway"
161
+ user_pool_id = module.user_identity.user_pool_id
162
+ user_pool_client_ids = [module.user_identity.user_pool_client_id]
163
+ }
164
+ ```
165
+ </Fragment>
166
+ </Infrastructure>
167
+
168
+ :::note[Custom OIDC providers]
169
+ To authenticate with a non-Cognito OIDC provider, modify the generated Gateway construct or Terraform module directly — swap the authorizer's discovery URL and allowed clients for your provider's. Agent to Gateway connection generators only support `IAM`-authenticated gateways, since agents sign their calls with SigV4.
170
+ :::
171
+
172
+ ## Writing Policies
173
+
174
+ <OptionFilter when={{ cedarPolicy: true }} description="Cedar policies — cedarPolicy: true only">
175
+
176
+ 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.
177
+
178
+ 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).
179
+
180
+ ### Adding a policy
181
+
182
+ 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.
183
+
184
+ For example, to permit only a specific agent role to invoke a particular tool, create:
185
+
186
+ ```cedar title="packages/<name>/policies/ts-agent-divide.cedar"
187
+ permit (
188
+ principal == AgentCore::IamEntity::"arn:aws:sts::<%= accountId %>:assumed-role/<%= tsAgentRoleName %>",
189
+ action == AgentCore::Action::"ts-mcp___divide",
190
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
191
+ );
192
+ ```
193
+
194
+ 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.
195
+
196
+ ### Template variables
197
+
198
+ Policies are [EJS](https://ejs.co/) templates rendered at synth/plan time so they stay portable across accounts and Gateway redeploys:
199
+
200
+ | Variable | Substituted with |
201
+ | -------------------- | --------------------------------------------- |
202
+ | `<%= gatewayArn %>` | The deployed Gateway's ARN |
203
+ | `<%= accountId %>` | The AWS account this Gateway is deployed into |
204
+
205
+ Always reference these variables rather than hard-coding values.
206
+
207
+ #### Adding your own variables
208
+
209
+ 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:
210
+
211
+ <Infrastructure>
212
+ <Fragment slot="cdk">
213
+ In `packages/common/constructs/src/app/gateways/<name>/<name>.ts`, pass `cedarPolicyVariables` through to the shared construct:
214
+
215
+ ```ts {5-6}
216
+ super(scope, id, {
217
+ cedarPolicyPath: path.join(
218
+ ...
219
+ ),
220
+ cedarPolicyVariables: {
221
+ tsAgentRoleName: cdk.Token.asString(tsAgent.agentCoreRuntime.role.roleName),
222
+ },
223
+ });
224
+ ```
225
+ </Fragment>
226
+ <Fragment slot="terraform">
227
+ In `packages/common/terraform/src/app/gateways/<name>/<name>.tf`, add to the `query` of the `rendered_policies` data source:
228
+
229
+ ```hcl {4}
230
+ query = {
231
+ template = "${local.policies_dir}/${each.value}"
232
+ gatewayArn = aws_bedrockagentcore_gateway.this.gateway_arn
233
+ tsAgentRoleName = var.ts_agent_role_name
234
+ # ...
235
+ }
236
+ ```
237
+ </Fragment>
238
+ </Infrastructure>
239
+
240
+ ### ENFORCE mode and default-deny
241
+
242
+ 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:
243
+
244
+ ```
245
+ Tool Execution Denied: Tool call not allowed due to policy enforcement
246
+ [No policy applies to the request (denied by default).]
247
+ ```
248
+
249
+ 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.
250
+
251
+ ### Default `permit-all.cedar`
252
+
253
+ The generator ships a default policy scoped to the Gateway's authentication type.
254
+
255
+ For an **IAM** Gateway, it permits any IAM caller from the AWS account the Gateway is deployed into:
256
+
257
+ ```cedar title="packages/<name>/policies/permit-all.cedar"
258
+ permit (
259
+ principal is AgentCore::IamEntity,
260
+ action,
261
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
262
+ ) when {
263
+ principal.id like "arn:aws:*::<%= accountId %>:*"
264
+ };
265
+ ```
266
+
267
+ For a **Cognito** Gateway, it permits any authenticated OAuth user (the JWT authorizer has already validated the token's user pool and client before policies are evaluated):
268
+
269
+ ```cedar title="packages/<name>/policies/permit-all.cedar"
270
+ permit (
271
+ principal is AgentCore::OAuthUser,
272
+ action,
273
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
274
+ );
275
+ ```
276
+
277
+ 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.
278
+
279
+ ### Policy scope reference
280
+
281
+ The principal type depends on how the Gateway authenticates callers (see <a href="#authentication">Authentication</a>).
282
+
283
+ For an **IAM** Gateway, callers are IAM principals:
284
+
285
+ ```
286
+ principal is AgentCore::IamEntity
287
+ ```
288
+
289
+ Callers are evaluated as STS assumed-role ARNs with the session name stripped, so a role can be matched exactly — no wildcards needed:
290
+
291
+ ```cedar
292
+ principal == AgentCore::IamEntity::"arn:aws:sts::<%= accountId %>:assumed-role/<%= myAgentRoleName %>"
293
+ ```
294
+
295
+ 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`.
296
+
297
+ For a **Cognito** Gateway, callers are OAuth users built from the JWT token's `sub` claim, and JWT claims (username, scope, etc.) are available as principal tags:
298
+
299
+ ```
300
+ principal is AgentCore::OAuthUser
301
+ ```
302
+
303
+ Match individual claims in `when` clauses — for example to require a scope:
304
+
305
+ ```cedar
306
+ permit (
307
+ principal is AgentCore::OAuthUser,
308
+ action,
309
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
310
+ ) when {
311
+ principal.scope == "gateway/invoke"
312
+ };
313
+ ```
314
+
315
+ Tool invocations reach the policy engine as actions with the form:
316
+
317
+ ```
318
+ AgentCore::Action::"<target-name>___<tool-name>"
319
+ ```
320
+
321
+ 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.
322
+
323
+ The resource is always the Gateway itself:
324
+
325
+ ```cedar
326
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
327
+ ```
328
+
329
+ ### Validation considerations
330
+
331
+ 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.
332
+
333
+ 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.
334
+
335
+ 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.
336
+
337
+ ### Example: forbid one tool while keeping a broader permit
338
+
339
+ Pair a narrow `forbid` with a broader `permit` (Cedar evaluates `forbid` over `permit`):
340
+
341
+ ```cedar title="packages/<name>/policies/forbid-divide-for-py-agent.cedar"
342
+ forbid (
343
+ principal == AgentCore::IamEntity::"arn:aws:sts::<%= accountId %>:assumed-role/<%= pyAgentRoleName %>",
344
+ action == AgentCore::Action::"ts-mcp___divide",
345
+ resource == AgentCore::Gateway::"<%= gatewayArn %>"
346
+ );
347
+ ```
348
+
349
+ This denies the Python agent role from calling `ts-mcp___divide` while leaving the broader `permit-all.cedar` in place for all other callers.
350
+
351
+ </OptionFilter>
352
+
353
+ ## Local Development
354
+
355
+ The generator adds a `dev` target to the Gateway project, which runs `local-dev.ts`. Running it starts the local gateway and every attached target together:
356
+
357
+ <NxCommands commands={["dev <name>"]} />
358
+
359
+ <OptionFilter when={{ protocol: 'mcp' }} description="MCP aggregator local gateway">
360
+ The local gateway exposes 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.
361
+ </OptionFilter>
362
+
363
+ <OptionFilter when={{ protocol: 'http' }} description="Path-routing proxy local gateway">
364
+ The local gateway proxies `/<targetName>/...` paths to each attached agent's local server (connected via the <Link path="guides/connection/agentcore-gateway-agent">`agentcore-gateway#agent-connection` generator</Link>), matching the deployed Gateway's path-based routing.
365
+ </OptionFilter>
366
+
367
+ See the connection guides for the full local development story.
368
+
369
+ ## Deploying your AgentCore Gateway
370
+
371
+ The AgentCore Gateway generator creates CDK or Terraform infrastructure as code based on your selected `iac`. You can use this to deploy your Gateway.
372
+
373
+ <Infrastructure>
374
+ <Fragment slot="cdk">
375
+ The CDK construct for deploying your Gateway lives in the `common/constructs` folder. You can consume this in a CDK application, for example:
376
+
377
+ ```ts {7} title="packages/infra/src/stacks/application-stack.ts"
378
+ import { MyGateway } from '@my-scope/common-constructs';
379
+
380
+ export class ApplicationStack extends Stack {
381
+ constructor(scope: Construct, id: string, props?: StackProps) {
382
+ super(scope, id, props);
383
+
384
+ new MyGateway(this, 'MyGateway');
385
+ }
386
+ }
387
+ ```
388
+
389
+ This sets up your Gateway infrastructure, including the `AgentCore::Gateway`, its Cedar `PolicyEngine`, and the AWS WAF Web ACL (see [AWS WAF](#aws-waf) below). Register MCP server targets with `gateway.addMcpServer(...)` — see the <Link path="guides/connection/agentcore-gateway-mcp">MCP server connection guide</Link>.
390
+ </Fragment>
391
+ <Fragment slot="terraform">
392
+ The Terraform module for deploying your Gateway is in the `common/terraform` folder. You can use this in a Terraform configuration, for example:
393
+
394
+ ```hcl title="packages/infra/src/main.tf"
395
+ module "my_gateway" {
396
+ source = "../../common/terraform/src/app/gateways/my-gateway"
397
+ }
398
+ ```
399
+
400
+ This sets up your Gateway infrastructure, including the `aws_bedrockagentcore_gateway`, its Cedar policy engine, and the AWS WAF Web ACL (see [AWS WAF](#aws-waf) below). Register MCP server targets with an `aws_bedrockagentcore_gateway_target` resource — see the <Link path="guides/connection/agentcore-gateway-mcp">MCP server connection guide</Link>.
401
+ </Fragment>
402
+ </Infrastructure>
403
+
404
+ ### AWS WAF
405
+
406
+ By default, the generated construct associates an [AWS WAFv2](https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html) Web ACL with the Gateway. AWS WAF inspects every inbound request inline _before_ it reaches a target, protecting your Gateway from web exploits, bot traffic, and volumetric attacks. The Web ACL uses the AWS managed default ruleset ([`AWSManagedRulesCommonRuleSet`](https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-baseline.html#aws-managed-rule-groups-baseline-crs) and [`AWSManagedRulesKnownBadInputsRuleSet`](https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-baseline.html#aws-managed-rule-groups-baseline-known-bad-inputs)), providing protection against common web exploits including the OWASP Top 10. WAF request logs are written to a CloudWatch Logs group.
407
+
408
+ The Web ACL is `REGIONAL` and created in the Gateway's region, as required for AgentCore Gateway associations.
409
+
410
+ :::caution[SizeRestrictions_BODY deviation from defaults]
411
+ The `SizeRestrictions_BODY` rule from `AWSManagedRulesCommonRuleSet` is overridden to `Count` rather than `Block`, since the rule's 8 KB limit is too restrictive for typical MCP tool payloads. Oversized requests will still be recorded as metrics so you can monitor them. See the [AWS WAF body size limits](https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-statement-oversize-handling.html) guide for more details.
412
+ :::
413
+
414
+ You can edit the generated Gateway construct to add, remove, or adjust rules (for example, to add [rate-based rules](https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-statement-type-rate-based.html) or additional managed rule groups).
415
+
416
+ <Infrastructure>
417
+ <Fragment slot="cdk">
418
+ To opt out (for example, to attach your own Web ACL), set `enableWaf` to `false` when you instantiate the Gateway construct:
419
+
420
+ ```ts {2}
421
+ new MyGateway(this, 'MyGateway', {
422
+ enableWaf: false,
423
+ });
424
+ ```
425
+
426
+ The construct exposes the created Web ACL as `webAcl` for further configuration.
427
+ </Fragment>
428
+ <Fragment slot="terraform">
429
+ To opt out (for example, to attach your own Web ACL), set `enable_waf` to `false` on the Gateway module:
430
+
431
+ ```hcl {2}
432
+ module "my_gateway" {
433
+ enable_waf = false
434
+ }
435
+ ```
436
+
437
+ The module outputs the created Web ACL ARN as `waf_web_acl_arn` for further configuration.
438
+ </Fragment>
439
+ </Infrastructure>
440
+
441
+ ## Connections
442
+
443
+ Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
444
+
445
+ <CardGrid>
446
+ <ConnectionCard
447
+ title="AgentCore Gateway to MCP Server"
448
+ description="Aggregate an MCP server behind an AgentCore Gateway"
449
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-mcp`}
450
+ source="agentcore"
451
+ target="mcp"
452
+ />
453
+ <ConnectionCard
454
+ title="AgentCore Gateway to AgentCore Gateway"
455
+ description="Aggregate an AgentCore Gateway behind another AgentCore Gateway"
456
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-gateway`}
457
+ source="agentcore"
458
+ target="agentcore"
459
+ />
460
+ <ConnectionCard
461
+ title="TypeScript Agent to AgentCore Gateway"
462
+ description="Connect a TypeScript Agent to an AgentCore Gateway"
463
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-gateway`}
464
+ source="strands"
465
+ sourceBadge="typescript"
466
+ target="agentcore"
467
+ />
468
+ <ConnectionCard
469
+ title="Python Agent to AgentCore Gateway"
470
+ description="Connect a Python Agent to an AgentCore Gateway"
471
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-agent-gateway`}
472
+ source="strands"
473
+ sourceBadge="python"
474
+ target="agentcore"
475
+ />
476
+ <ConnectionCard
477
+ title="AgentCore Gateway to Agent"
478
+ description="Front an agent with an AgentCore Gateway as a runtime target"
479
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-agent`}
480
+ source="agentcore"
481
+ target="strands"
482
+ />
483
+ <ConnectionCard
484
+ title="React Website to AgentCore Gateway"
485
+ description="Connect a React website to agents through an AgentCore Gateway"
486
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-agentcore-gateway`}
487
+ source="react"
488
+ target="agentcore"
489
+ />
490
+ </CardGrid>