@aws/nx-plugin-mcp 1.0.0-rc.75 → 1.0.0-rc.77

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.
@@ -92,6 +92,25 @@ The generated code handles authentication depending on your agent's configuratio
92
92
  - **IAM** (default): uses AWS SigV4-signed HTTP requests. Credentials are obtained from the Cognito Identity Pool configured with your website's auth.
93
93
  - **Cognito**: embeds the JWT access token in the `Authorization` header as a Bearer token.
94
94
 
95
+ ### Sessions and Threads
96
+
97
+ AG-UI and AgentCore Runtime each identify a conversation differently, and the generated hook ties them together:
98
+
99
+ - **`threadId`** — the AG-UI conversation identifier, sent in the request body. CopilotKit generates a random UUID per chat unless you pass an explicit `threadId`.
100
+ - **Session ID** — the AgentCore Runtime session, sent in the `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id` header. It selects the [microVM](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-how-it-works.html) serving the request, and is what your agent's `session.ts` / `session.py` keys conversation state on.
101
+
102
+ The hook derives the session ID from the thread ID, right-padding it to the 33 characters AgentCore Runtime requires:
103
+
104
+ ```ts
105
+ function agentCoreSessionId(input: RunAgentInput): string {
106
+ return (input.threadId ?? '').padEnd(33, '0');
107
+ }
108
+ ```
109
+
110
+ Leaving `threadId` unset is simplest — CopilotKit's generated UUID is already 36 characters. If you pass one explicitly, make it at least 33 characters, since padding maps thread IDs that differ only in trailing characters onto the same session.
111
+
112
+ Both Session ID and Thread ID are provided by the browser. To restrict each user to their own conversations, refer to the <Link path="guides/py-agent">`py#agent`</Link> or <Link path="guides/ts-agent">`ts#agent`</Link> guide.
113
+
95
114
  ## Infrastructure
96
115
 
97
116
  <Snippet name="connection/react-agent-infrastructure" parentHeading="Infrastructure" />
@@ -4,7 +4,7 @@ description: Generate a Python Agent for building AI agents with tools and deplo
4
4
  generator: py#agent
5
5
  ---
6
6
 
7
- import { FileTree, Tabs, TabItem, CardGrid } from '@astrojs/starlight/components';
7
+ import { FileTree, Tabs, TabItem, CardGrid, Steps } from '@astrojs/starlight/components';
8
8
  import Astro from '@astrojs/react';
9
9
  import ConnectionCard from '@components/connection-card.astro';
10
10
  import RunGenerator from '@components/run-generator.astro';
@@ -516,6 +516,23 @@ The session ID itself comes from the AgentCore Runtime session (propagated via t
516
516
  :::note[Local Development]
517
517
  When running locally (`LOCAL_DEV=true`, set automatically by the `-dev` target), session data is always stored on disk under `tmp/agents/strands/<agent-name>` at the workspace root, regardless of the configured `session` option, for convenience.
518
518
  :::
519
+
520
+ #### Restricting sessions to their owner
521
+
522
+ The session ID arrives from the caller, so on its own it identifies a conversation but not who the conversation belongs to. AgentCore Runtime authorizes an invocation against the agent runtime resource ARN rather than against an individual session, which leaves the agent free to decide what a session means to your application.
523
+
524
+ :::caution[The session also selects the microVM]
525
+ A session ID selects the [microVM](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-how-it-works.html) that serves the request, so its filesystem, `/tmp` and in-process caches are shared by every request resolving to that session. Two callers who send the same session ID share those resources even when their stored conversations are separate.
526
+ :::
527
+
528
+ To restrict each user to their own conversations:
529
+
530
+ <Steps>
531
+ 1. Add an API to create a session, using <Link path="guides/trpc">tRPC</Link>, <Link path="guides/fastapi">FastAPI</Link> or <Link path="guides/ts-smithy-api">Smithy</Link>. Generate an opaque session ID (at least 33 characters) and store it alongside the calling user's ID — for example in a table created with the <Link path="guides/py-dynamodb">`py#dynamodb`</Link> generator. Each API guide shows how to retrieve the calling user's ID.
532
+ 2. In your agent, look up the stored user ID for the session ID it was given, and reject the request when it does not match the caller. With `auth=cognito` the caller's JWT reaches your agent code, so its `sub` claim identifies them.
533
+ </Steps>
534
+
535
+ Generate the session ID rather than deriving it from user-supplied values such as a conversation name — anything a caller can predict, a caller can send.
519
536
  </OptionFilter>
520
537
 
521
538
  <OptionFilter when={{ framework: 'langchain' }} description="LangChain session management (session.py)">
@@ -119,6 +119,42 @@ Set `advanced_security_mode` to `ENFORCED` in the `user_pool_add_ons` block in `
119
119
  </Fragment>
120
120
  </Infrastructure>
121
121
 
122
+ #### Multi-factor authentication (MFA)
123
+
124
+ By default users must configure MFA (an SMS code or a time-based one time password) before they can sign in. You can make MFA optional, turn it off entirely, or restrict which second-factor methods are available:
125
+
126
+ <Infrastructure>
127
+ <Fragment slot="cdk">
128
+ ```ts
129
+ import { Mfa } from 'aws-cdk-lib/aws-cognito';
130
+
131
+ new UserIdentity(this, 'Identity', {
132
+ mfa: Mfa.OPTIONAL,
133
+ mfaSecondFactor: { sms: false, otp: true },
134
+ });
135
+ ```
136
+
137
+ `mfa` accepts `Mfa.OFF` / `Mfa.OPTIONAL` / `Mfa.REQUIRED`. `mfaSecondFactor.sms` and `mfaSecondFactor.otp` enable or disable each second-factor method independently; they have no effect when `mfa` is `Mfa.OFF`. Setting `mfa: Mfa.REQUIRED` with both methods disabled is rejected at synth time, since nobody could then complete sign-in.
138
+ </Fragment>
139
+ <Fragment slot="terraform">
140
+ ```hcl
141
+ module "user_identity" {
142
+ source = "../../common/terraform/src/core/user-identity"
143
+
144
+ mfa = "OPTIONAL"
145
+ mfa_second_factor_sms = false
146
+ mfa_second_factor_otp = true
147
+ }
148
+ ```
149
+
150
+ `mfa` accepts `"OFF"` / `"OPTIONAL"` / `"ON"`. `mfa_second_factor_sms` and `mfa_second_factor_otp` enable or disable each second-factor method independently; they have no effect when `mfa` is `"OFF"`.
151
+ </Fragment>
152
+ </Infrastructure>
153
+
154
+ :::caution[SMS MFA is tied to phone number verification]
155
+ Cognito rejects SMS-based phone number verification unless SMS is also an enabled MFA method whenever MFA is not off, in both CDK and Terraform. Disabling `mfaSecondFactor.sms` / `mfa_second_factor_sms` while `mfa` is on therefore also disables SMS-based phone number verification for the user pool.
156
+ :::
157
+
122
158
  #### Web Application Firewall (WAF)
123
159
 
124
160
  By default the User Pool is associated with an [AWS WAFv2](https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html) Web ACL using the `AWSManagedRulesCommonRuleSet` and `AWSManagedRulesKnownBadInputsRuleSet` managed rule groups. You can disable this if you wish to manage your own Web ACL or do not require one:
@@ -4,7 +4,7 @@ description: Generate a TypeScript Agent for building AI agents with tools and d
4
4
  generator: ts#agent
5
5
  ---
6
6
 
7
- import { FileTree, Tabs, TabItem, CardGrid } from '@astrojs/starlight/components';
7
+ import { FileTree, Tabs, TabItem, CardGrid, Steps } from '@astrojs/starlight/components';
8
8
  import Astro from '@astrojs/react';
9
9
  import ConnectionCard from '@components/connection-card.astro';
10
10
  import RunGenerator from '@components/run-generator.astro';
@@ -365,6 +365,23 @@ The session ID itself comes from the AgentCore Runtime session (propagated via t
365
365
  :::note[Local Development]
366
366
  When running locally (`LOCAL_DEV=true`, set automatically by the `-dev` target), session data is always stored on disk under `tmp/agents/strands/<agent-name>` at the workspace root, regardless of the configured `session` option, for convenience.
367
367
  :::
368
+
369
+ #### Restricting sessions to their owner
370
+
371
+ The session ID arrives from the caller, so on its own it identifies a conversation but not who the conversation belongs to. AgentCore Runtime authorizes an invocation against the agent runtime resource ARN rather than against an individual session, which leaves the agent free to decide what a session means to your application.
372
+
373
+ :::caution[The session also selects the microVM]
374
+ A session ID selects the [microVM](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-how-it-works.html) that serves the request, so its filesystem, `/tmp` and in-process caches are shared by every request resolving to that session. Two callers who send the same session ID share those resources even when their stored conversations are separate.
375
+ :::
376
+
377
+ To restrict each user to their own conversations:
378
+
379
+ <Steps>
380
+ 1. Add an API to create a session, using <Link path="guides/trpc">tRPC</Link>, <Link path="guides/fastapi">FastAPI</Link> or <Link path="guides/ts-smithy-api">Smithy</Link>. Generate an opaque session ID (at least 33 characters) and store it alongside the calling user's ID — for example in a table created with the <Link path="guides/ts-dynamodb">`ts#dynamodb`</Link> generator. Each API guide shows how to retrieve the calling user's ID.
381
+ 2. In your agent, look up the stored user ID for the session ID it was given, and reject the request when it does not match the caller. With `auth=cognito` the caller's JWT reaches your agent code, so its `sub` claim identifies them.
382
+ </Steps>
383
+
384
+ Generate the session ID rather than deriving it from user-supplied values such as a conversation name — anything a caller can predict, a caller can send.
368
385
  </OptionFilter>
369
386
 
370
387
  ## Invoking your Agent
@@ -2,6 +2,7 @@
2
2
  title: Deploying your DynamoDB Table
3
3
  ---
4
4
  import Infrastructure from '@components/infrastructure.astro';
5
+ import Snippet from '@components/snippet.astro';
5
6
 
6
7
  The DynamoDB generator creates CDK or Terraform infrastructure based on your selected `iac`.
7
8
 
@@ -137,30 +138,8 @@ module "my_table" {
137
138
  </Fragment>
138
139
  </Infrastructure>
139
140
 
140
- ### Encryption Key Rotation
141
+ ### Encryption
141
142
 
142
- The KMS key used to encrypt the table has automatic key rotation enabled by default. Disable it if your security policy manages rotation externally.
143
+ The table is encrypted with a customer-managed KMS key by default, created automatically for you. Switch to an AWS managed key, the AWS owned key, or bring your own KMS key, if you manage encryption differently.
143
144
 
144
- #### Disable Encryption Key Rotation
145
-
146
- <Infrastructure>
147
- <Fragment slot="cdk">
148
-
149
- ```ts title="packages/infra/src/stacks/application-stack.ts"
150
- import { MyTable } from '@my-scope/common-constructs';
151
-
152
- const table = new MyTable(this, 'Table', {
153
- enableKeyRotation: false,
154
- });
155
- ```
156
- </Fragment>
157
- <Fragment slot="terraform">
158
-
159
- ```hcl title="packages/infra/src/main.tf"
160
- module "my_table" {
161
- source = "../../common/terraform/src/app/dynamodb/my-table"
162
- enable_key_rotation = false
163
- }
164
- ```
165
- </Fragment>
166
- </Infrastructure>
145
+ <Snippet name="dynamodb/encryption-options" parentHeading="Encryption" />
@@ -0,0 +1,168 @@
1
+ ---
2
+ title: Encryption Options
3
+ ---
4
+ import Infrastructure from '@components/infrastructure.astro';
5
+ import OptionFilter from '@components/option-filter.astro';
6
+
7
+ #### Use an AWS Managed Key
8
+
9
+ Uses the shared `aws/dynamodb` KMS key that AWS manages on your behalf. It's visible in your account's KMS console and billed per request, but there's no key for you to create, rotate or delete.
10
+
11
+ <Infrastructure>
12
+ <Fragment slot="cdk">
13
+
14
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
15
+ import { TableEncryption } from 'aws-cdk-lib/aws-dynamodb';
16
+ import { MyTable } from '@my-scope/common-constructs';
17
+
18
+ const table = new MyTable(this, 'Table', {
19
+ encryption: TableEncryption.AWS_MANAGED,
20
+ });
21
+ ```
22
+
23
+ :::tip[Checkov]
24
+ Choosing `AWS_MANAGED` means the table is no longer encrypted with a customer-managed key, which fails Checkov's `CKV_AWS_119`. Suppress it on the table:
25
+
26
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
27
+ import { suppressRules } from '@my-scope/common-constructs';
28
+
29
+ suppressRules(table.table, ['CKV_AWS_119'], 'Using an AWS managed key rather than a customer-managed CMK');
30
+ ```
31
+ :::
32
+ </Fragment>
33
+ <Fragment slot="terraform">
34
+
35
+ ```hcl title="packages/infra/src/main.tf"
36
+ module "my_table" {
37
+ source = "../../common/terraform/src/app/dynamodb/my-table"
38
+ encryption = "AWS_MANAGED"
39
+ }
40
+ ```
41
+ </Fragment>
42
+ </Infrastructure>
43
+
44
+ #### Use the AWS Owned Key
45
+
46
+ Uses a key fully owned and managed by AWS — free, with no key visible in your account at all. The simplest option when you don't need a customer- or account-visible key for compliance reasons.
47
+
48
+ <Infrastructure>
49
+ <Fragment slot="cdk">
50
+
51
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
52
+ import { TableEncryption } from 'aws-cdk-lib/aws-dynamodb';
53
+ import { MyTable } from '@my-scope/common-constructs';
54
+
55
+ const table = new MyTable(this, 'Table', {
56
+ encryption: TableEncryption.DEFAULT,
57
+ });
58
+ ```
59
+
60
+ :::tip[Checkov]
61
+ Choosing `DEFAULT` means the table is no longer encrypted with a customer-managed key, which fails Checkov's `CKV_AWS_119`. Suppress it on the table:
62
+
63
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
64
+ import { suppressRules } from '@my-scope/common-constructs';
65
+
66
+ suppressRules(table.table, ['CKV_AWS_119'], 'Using the AWS owned key rather than a customer-managed CMK');
67
+ ```
68
+ :::
69
+ </Fragment>
70
+ <Fragment slot="terraform">
71
+
72
+ ```hcl title="packages/infra/src/main.tf"
73
+ module "my_table" {
74
+ source = "../../common/terraform/src/app/dynamodb/my-table"
75
+ encryption = "DEFAULT"
76
+ }
77
+ ```
78
+ </Fragment>
79
+ </Infrastructure>
80
+
81
+ <OptionFilter when={{ iac: 'terraform' }} description="Switching an already-deployed table away from CUSTOMER_MANAGED">
82
+ #### Switching away from CUSTOMER_MANAGED
83
+
84
+ On an **already-deployed** table, changing `encryption` away from `CUSTOMER_MANAGED` (to either `AWS_MANAGED` or `DEFAULT`) in a single `terraform apply` fails: Terraform destroys the customer-managed key before updating the table, and DynamoDB then rejects the update because the key is already pending deletion.
85
+
86
+ Work around it by updating the table's encryption directly via the AWS CLI first, then letting Terraform catch up and clean up the orphaned key:
87
+
88
+ ```bash
89
+ # For AWS_MANAGED:
90
+ aws dynamodb update-table --table-name <table-name> \
91
+ --sse-specification Enabled=true,SSEType=KMS,KMSMasterKeyId=alias/aws/dynamodb
92
+
93
+ # For DEFAULT:
94
+ aws dynamodb update-table --table-name <table-name> --sse-specification Enabled=false
95
+
96
+ # Then wait for this to report ENABLED (or for SSEDescription to disappear, for DEFAULT):
97
+ aws dynamodb describe-table --table-name <table-name> --query Table.SSEDescription.Status
98
+ ```
99
+
100
+ Then update `encryption` in your Terraform config and run `terraform apply` as normal — Terraform now only needs to destroy the already-unused key, with nothing left depending on it.
101
+ </OptionFilter>
102
+
103
+ #### Use Your Own KMS Key
104
+
105
+ Provide an existing customer-managed key instead of having one created for you. The key must already grant the DynamoDB service the permissions it needs in its own key policy.
106
+
107
+ <Infrastructure>
108
+ <Fragment slot="cdk">
109
+
110
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
111
+ import { Key } from 'aws-cdk-lib/aws-kms';
112
+ import { MyTable } from '@my-scope/common-constructs';
113
+
114
+ const key = Key.fromKeyArn(this, 'Key', 'arn:aws:kms:us-east-1:111111111111:key/my-key-id');
115
+
116
+ const table = new MyTable(this, 'Table', {
117
+ encryptionKey: key,
118
+ });
119
+ ```
120
+ </Fragment>
121
+ <Fragment slot="terraform">
122
+
123
+ ```hcl title="packages/infra/src/main.tf"
124
+ module "my_table" {
125
+ source = "../../common/terraform/src/app/dynamodb/my-table"
126
+ kms_key_arn = "arn:aws:kms:us-east-1:111111111111:key/my-key-id"
127
+ }
128
+ ```
129
+ </Fragment>
130
+ </Infrastructure>
131
+
132
+ #### Encryption Key Rotation
133
+
134
+ When the table creates its own customer-managed KMS key (the default, and only when you haven't provided your own key), that key has automatic key rotation enabled by default. Disable it if your security policy manages rotation externally.
135
+
136
+ ##### Disable Encryption Key Rotation
137
+
138
+ <Infrastructure>
139
+ <Fragment slot="cdk">
140
+
141
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
142
+ import { MyTable } from '@my-scope/common-constructs';
143
+
144
+ const table = new MyTable(this, 'Table', {
145
+ enableKeyRotation: false,
146
+ });
147
+ ```
148
+
149
+ :::tip[Checkov]
150
+ Disabling key rotation, or bringing your own key that doesn't rotate, fails Checkov's `CKV_AWS_7`. Suppress it on the key:
151
+
152
+ ```ts title="packages/infra/src/stacks/application-stack.ts"
153
+ import { suppressRules } from '@my-scope/common-constructs';
154
+
155
+ suppressRules(table.table.encryptionKey!, ['CKV_AWS_7'], 'Key rotation is managed externally');
156
+ ```
157
+ :::
158
+ </Fragment>
159
+ <Fragment slot="terraform">
160
+
161
+ ```hcl title="packages/infra/src/main.tf"
162
+ module "my_table" {
163
+ source = "../../common/terraform/src/app/dynamodb/my-table"
164
+ enable_key_rotation = false
165
+ }
166
+ ```
167
+ </Fragment>
168
+ </Infrastructure>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin-mcp",
3
- "version": "1.0.0-rc.75",
3
+ "version": "1.0.0-rc.77",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",