@aws/nx-plugin-mcp 1.0.0-rc.59 → 1.0.0-rc.60
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.
|
@@ -22,6 +22,8 @@ A website always gets <Link path="guides/react-website-auth">Cognito authenticat
|
|
|
22
22
|
|
|
23
23
|
An `infra` project is added at the end — <Link path="guides/typescript-infrastructure">`ts#infra`</Link> or <Link path="guides/terraform-project">`terraform#project`</Link>, matching your IaC choice. Every generated project vends constructs for it to instantiate, so this is what you deploy. Because it owns that name, no component on the canvas can be called `infra`.
|
|
24
24
|
|
|
25
|
+
Use **Vertical** / **Horizontal** in the toolbar to swap which way the graph flows — the connection points move to the top and bottom edges of each component, and the layout is transposed to match.
|
|
26
|
+
|
|
25
27
|
Drag the canvas background to pan around, and drag a component to reposition it. Shift-click to select several components and move them as a group. Click a connection to select it, then press <kbd>Delete</kbd> to remove it (or use the ✕ on the connection itself).
|
|
26
28
|
|
|
27
29
|
The palette lists every project and component type that can take part in a connection, and you can only draw the connections the plugin supports — so a graph that validates is a graph that scaffolds.
|
|
@@ -23,7 +23,7 @@ Once connected, the Gateway proxies requests for the agent under `<gatewayUrl>/<
|
|
|
23
23
|
Before using this generator, ensure you have:
|
|
24
24
|
|
|
25
25
|
1. An <Link path="guides/agentcore-gateway">`agentcore-gateway`</Link> project generated with `protocol: http`
|
|
26
|
-
2. An agent component (<Link path="guides/ts-agent">`ts#agent`</Link> or <Link path="guides/py-agent">`py#agent`</Link>) created with `infra: agentcore
|
|
26
|
+
2. An agent component (<Link path="guides/ts-agent">`ts#agent`</Link> or <Link path="guides/py-agent">`py#agent`</Link>) created with `infra: agentcore`. Either `auth: iam` (the Gateway invokes it with its own role) or `auth: cognito` (the Gateway forwards the caller's JWT — see [Forwarding caller identity](#forwarding-caller-identity-to-the-runtime)) works.
|
|
27
27
|
|
|
28
28
|
:::caution[TypeScript HTTP agents]
|
|
29
29
|
A TypeScript `http` agent serves tRPC over WebSocket, and AgentCore Gateway does not support WebSocket or bidirectional streaming — the generator rejects this combination. Generate the agent with the `ag-ui` protocol instead.
|
|
@@ -87,14 +87,22 @@ Fronting an agent with a Gateway is what makes a VPC-deployed agent reachable: c
|
|
|
87
87
|
import { RuntimeNetworkConfiguration } from 'aws-cdk-lib/aws-bedrockagentcore';
|
|
88
88
|
|
|
89
89
|
const myAgent = new MyAgent(this, 'MyAgent', {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
// Give each agent its own scope for the network configuration — usingVpc
|
|
91
|
+
// creates a security group named `SecurityGroup` under the scope you pass,
|
|
92
|
+
// so passing `this` for more than one agent collides on the construct id.
|
|
93
|
+
networkConfiguration: RuntimeNetworkConfiguration.usingVpc(
|
|
94
|
+
new Construct(this, 'MyAgentNetwork'),
|
|
95
|
+
{
|
|
96
|
+
vpc,
|
|
97
|
+
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
|
|
98
|
+
},
|
|
99
|
+
),
|
|
94
100
|
});
|
|
95
101
|
```
|
|
96
102
|
|
|
97
103
|
Use a **private subnet with egress**, not a private isolated subnet: the runtime needs outbound internet access to reach Bedrock and read its configuration from AWS AppConfig.
|
|
104
|
+
|
|
105
|
+
AgentCore Runtime VPC deployments are only supported in certain availability zones. If a deploy fails with `subnets are in unsupported availability zones`, restrict the VPC (or the subnet selection) to the supported zones for your region.
|
|
98
106
|
:::
|
|
99
107
|
</Fragment>
|
|
100
108
|
<Fragment slot="terraform">
|
|
@@ -177,13 +185,19 @@ To connect a website to the Gateway's agents, use the <Link path="guides/connect
|
|
|
177
185
|
|
|
178
186
|
## Forwarding caller identity to the runtime
|
|
179
187
|
|
|
180
|
-
By default the Gateway signs outbound calls with its own IAM role (the `GATEWAY_IAM_ROLE` credential provider), so the runtime sees the _Gateway's_ identity, not the caller's. If you want the agent to authorize on the caller — for example to read the user's `sub` or `scope` claims —
|
|
188
|
+
By default the Gateway signs outbound calls with its own IAM role (the `GATEWAY_IAM_ROLE` credential provider), so the runtime sees the _Gateway's_ identity, not the caller's. If instead you want the agent to authorize on the caller — for example to read the user's `sub` or `scope` claims — front a **Cognito** agent with a **Cognito** Gateway. The Gateway then forwards the caller's JWT to the runtime unchanged (the `JWT_PASSTHROUGH` credential provider), and the runtime revalidates it.
|
|
189
|
+
|
|
190
|
+
Generate both ends with `auth: cognito` and connect them as above:
|
|
191
|
+
|
|
192
|
+
- an agent (<Link path="guides/ts-agent">`ts#agent`</Link> or <Link path="guides/py-agent">`py#agent`</Link>) created with `auth: cognito`, and
|
|
193
|
+
- a Gateway created with `auth: cognito` fronting the **same** Cognito user pool.
|
|
194
|
+
|
|
195
|
+
Everything else is automatic — `gateway.addAgent(agent)` (CDK) and the generated Terraform runtime module handle the wiring for you based on the agent's `auth`:
|
|
181
196
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
3. **The target uses the `JWT_PASSTHROUGH` credential provider** instead of `GATEWAY_IAM_ROLE`, and the **runtime allowlists the `Authorization` header** so it reaches your agent code. Without the allowlist, AgentCore validates the token but strips the header before your container.
|
|
197
|
+
- the target is created with the `JWT_PASSTHROUGH` credential provider (rather than `GATEWAY_IAM_ROLE`), and
|
|
198
|
+
- the runtime allowlists the `Authorization` header so the forwarded token reaches your agent code. Without this allowlist AgentCore validates the token but strips the header before your container.
|
|
185
199
|
|
|
186
|
-
Callers
|
|
200
|
+
Callers invoke the Gateway with `Authorization: Bearer <jwt>` (no SigV4), and the agent reads the claims from the `Authorization` header — skipping signature validation, since the runtime's inbound authorizer has already verified the token:
|
|
187
201
|
|
|
188
202
|
```python title="packages/py_project/.../my_agent/main.py"
|
|
189
203
|
import jwt # PyJWT
|
|
@@ -195,82 +209,8 @@ async def invoke(input: InvokeInput, request: Request):
|
|
|
195
209
|
# authorize on claims['sub'], claims['scope'], ...
|
|
196
210
|
```
|
|
197
211
|
|
|
198
|
-
<Infrastructure>
|
|
199
|
-
<Fragment slot="cdk">
|
|
200
|
-
Pass `requestHeaderConfiguration` to the agent so the runtime receives the header, and create the target yourself (instead of `gateway.addAgent(agent)`) with the `JWT_PASSTHROUGH` credential provider:
|
|
201
|
-
|
|
202
|
-
```ts title="packages/infra/src/stacks/application-stack.ts" {5-7,17-19}
|
|
203
|
-
import { CfnGatewayTarget } from 'aws-cdk-lib/aws-bedrockagentcore';
|
|
204
|
-
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
205
|
-
|
|
206
|
-
const myAgent = new MyAgent(this, 'MyAgent', {
|
|
207
|
-
identity,
|
|
208
|
-
// Let the runtime receive the forwarded Authorization header.
|
|
209
|
-
requestHeaderConfiguration: { allowlistedHeaders: ['Authorization'] },
|
|
210
|
-
});
|
|
211
|
-
const myGateway = new MyGateway(this, 'MyGateway', { identity });
|
|
212
|
-
|
|
213
|
-
const target = new CfnGatewayTarget(this, 'Target-my-agent', {
|
|
214
|
-
gatewayIdentifier: myGateway.gateway.gatewayId,
|
|
215
|
-
name: myAgent.agentName,
|
|
216
|
-
targetConfiguration: {
|
|
217
|
-
http: { agentcoreRuntime: { arn: myAgent.agentCoreRuntime.agentRuntimeArn } },
|
|
218
|
-
},
|
|
219
|
-
// Forward the caller's validated JWT to the runtime unchanged.
|
|
220
|
-
credentialProviderConfigurations: [
|
|
221
|
-
{ credentialProviderType: 'JWT_PASSTHROUGH' },
|
|
222
|
-
],
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// The Gateway role still needs invoke access to the runtime.
|
|
226
|
-
myGateway.gateway.role.addToPrincipalPolicy(
|
|
227
|
-
new PolicyStatement({
|
|
228
|
-
actions: ['bedrock-agentcore:InvokeAgentRuntime'],
|
|
229
|
-
resources: [
|
|
230
|
-
myAgent.agentCoreRuntime.agentRuntimeArn,
|
|
231
|
-
`${myAgent.agentCoreRuntime.agentRuntimeArn}/*`,
|
|
232
|
-
],
|
|
233
|
-
}),
|
|
234
|
-
);
|
|
235
|
-
```
|
|
236
|
-
</Fragment>
|
|
237
|
-
<Fragment slot="terraform">
|
|
238
|
-
Add a `request_header_configuration` block to the runtime so it receives the header, and configure the target with the `JWT_PASSTHROUGH` credential provider (instead of `gateway_iam_role {}`):
|
|
239
|
-
|
|
240
|
-
```hcl title="packages/infra/src/main.tf" {5-7,20-22}
|
|
241
|
-
# Let the runtime receive the forwarded Authorization header. Add this block
|
|
242
|
-
# to the runtime resource in the agent module (packages/common/terraform/...).
|
|
243
|
-
resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
|
|
244
|
-
# ...
|
|
245
|
-
request_header_configuration {
|
|
246
|
-
request_header_allowlist = ["Authorization"]
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
resource "aws_bedrockagentcore_gateway_target" "my_agent" {
|
|
251
|
-
gateway_identifier = module.my_gateway.gateway_id
|
|
252
|
-
name = "my-agent"
|
|
253
|
-
description = "Agent runtime target my-agent"
|
|
254
|
-
|
|
255
|
-
target_configuration {
|
|
256
|
-
http {
|
|
257
|
-
agentcore_runtime {
|
|
258
|
-
arn = module.my_agent.agent_core_runtime_arn
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
# Forward the caller's validated JWT to the runtime unchanged.
|
|
264
|
-
credential_provider_configuration {
|
|
265
|
-
credential_provider_type = "JWT_PASSTHROUGH"
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
</Fragment>
|
|
270
|
-
</Infrastructure>
|
|
271
|
-
|
|
272
212
|
:::note
|
|
273
|
-
|
|
213
|
+
JWT passthrough suits a single identity provider whose token audience already covers the runtime. If one Gateway fronts agents across multiple tenants or audiences, use OAuth [on-behalf-of token exchange](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-building-adding-targets-authorization.html) instead.
|
|
274
214
|
:::
|
|
275
215
|
|
|
276
216
|
## Local Development
|