@aws/nx-plugin-mcp 0.120.0 → 0.122.0

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 (82) hide show
  1. package/bin/aws-nx-mcp.js +2365 -2078
  2. package/docs/guides/astro-docs.mdx +142 -0
  3. package/docs/guides/connection/py-agent-a2a.mdx +105 -0
  4. package/docs/guides/connection/py-agent-mcp.mdx +147 -0
  5. package/docs/guides/connection/react-agui.mdx +240 -0
  6. package/docs/guides/connection/react-fastapi.mdx +1476 -0
  7. package/docs/guides/connection/react-py-agent.mdx +198 -0
  8. package/docs/guides/connection/react-smithy.mdx +1355 -0
  9. package/docs/guides/connection/react-trpc.mdx +447 -0
  10. package/docs/guides/connection/react-ts-agent.mdx +198 -0
  11. package/docs/guides/connection/smithy-rdb.mdx +161 -0
  12. package/docs/guides/connection/trpc-rdb.mdx +127 -0
  13. package/docs/guides/connection/ts-agent-a2a.mdx +106 -0
  14. package/docs/guides/connection/ts-agent-mcp.mdx +144 -0
  15. package/docs/guides/connection/ts-agent-rdb.mdx +141 -0
  16. package/docs/guides/connection/ts-mcp-server-rdb.mdx +135 -0
  17. package/docs/guides/connection.mdx +126 -0
  18. package/docs/guides/docker-bundling.mdx +403 -0
  19. package/docs/guides/fastapi.mdx +509 -0
  20. package/docs/guides/license.mdx +293 -0
  21. package/docs/guides/nx-generator.mdx +588 -0
  22. package/docs/guides/py-agent.mdx +483 -0
  23. package/docs/guides/py-mcp-server.mdx +161 -0
  24. package/docs/guides/python-lambda-function.mdx +207 -0
  25. package/docs/guides/python-project.mdx +228 -0
  26. package/docs/guides/react-website-auth.mdx +216 -0
  27. package/docs/guides/react-website.mdx +421 -0
  28. package/docs/guides/runtime-config.mdx +312 -0
  29. package/docs/guides/terraform-project.mdx +317 -0
  30. package/docs/guides/trpc.mdx +816 -0
  31. package/docs/guides/ts-agent.mdx +436 -0
  32. package/docs/guides/ts-lambda-function.mdx +218 -0
  33. package/docs/guides/ts-mcp-server.mdx +169 -0
  34. package/docs/guides/ts-nx-plugin.mdx +159 -0
  35. package/docs/guides/ts-rdb.mdx +759 -0
  36. package/docs/guides/ts-smithy-api.mdx +661 -0
  37. package/docs/guides/typescript-infrastructure.mdx +408 -0
  38. package/docs/guides/typescript-project.mdx +312 -0
  39. package/docs/guides/workspace.mdx +181 -0
  40. package/docs/snippets/agent/architecture.mdx +72 -0
  41. package/docs/snippets/agent/bedrock-deployment.mdx +172 -0
  42. package/docs/snippets/agent/runtime-arn.mdx +64 -0
  43. package/docs/snippets/api/api-architecture.mdx +93 -0
  44. package/docs/snippets/api/api-choice-note.mdx +6 -0
  45. package/docs/snippets/api/cors-configuration-cdk-note.mdx +25 -0
  46. package/docs/snippets/api/cors-configuration-terraform-note.mdx +28 -0
  47. package/docs/snippets/api/shared-constructs.mdx +38 -0
  48. package/docs/snippets/api/type-safe-api-integrations.mdx +643 -0
  49. package/docs/snippets/api/waf-configuration.mdx +37 -0
  50. package/docs/snippets/connection/a2a-infrastructure.mdx +63 -0
  51. package/docs/snippets/connection/lambda-rdb-ssl-requirements.mdx +40 -0
  52. package/docs/snippets/connection/mcp-server-rdb-ssl-requirements.mdx +35 -0
  53. package/docs/snippets/connection/rdb-api-infrastructure.mdx +72 -0
  54. package/docs/snippets/connection/react-agent-infrastructure.mdx +61 -0
  55. package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +35 -0
  56. package/docs/snippets/lambda-function/architecture.mdx +36 -0
  57. package/docs/snippets/lambda-function/deploying-your-function.mdx +118 -0
  58. package/docs/snippets/mcp/architecture.mdx +58 -0
  59. package/docs/snippets/mcp/assistant-docs.mdx +10 -0
  60. package/docs/snippets/mcp/bedrock-deployment.mdx +167 -0
  61. package/docs/snippets/mcp/config.mdx +13 -0
  62. package/docs/snippets/mcp/configuration-py.mdx +42 -0
  63. package/docs/snippets/mcp/configuration-ts.mdx +53 -0
  64. package/docs/snippets/mcp/observability.mdx +8 -0
  65. package/docs/snippets/mcp/shared-constructs.mdx +32 -0
  66. package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +602 -0
  67. package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +915 -0
  68. package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +161 -0
  69. package/docs/snippets/pdk-migration/example/04-deploy.mdx +229 -0
  70. package/docs/snippets/pdk-migration/faq/aws-arch.mdx +17 -0
  71. package/docs/snippets/pdk-migration/faq/cdk-graph.mdx +29 -0
  72. package/docs/snippets/pdk-migration/faq/infrastructure-python-java.mdx +19 -0
  73. package/docs/snippets/pdk-migration/faq/pdk-nag.mdx +15 -0
  74. package/docs/snippets/pdk-migration/faq/pipeline.mdx +15 -0
  75. package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +310 -0
  76. package/docs/snippets/pdk-migration/faq/use-of-projen.mdx +15 -0
  77. package/docs/snippets/prerequisites.mdx +20 -0
  78. package/docs/snippets/required-prerequisites.mdx +12 -0
  79. package/docs/snippets/shared-constructs.mdx +40 -0
  80. package/docs/snippets/tools/acurl.mdx +73 -0
  81. package/docs/snippets/ts-bundle.mdx +14 -0
  82. package/package.json +1 -1
@@ -0,0 +1,142 @@
1
+ ---
2
+ title: Astro Docs
3
+ description: Reference documentation for an Astro + Starlight documentation site
4
+ generator: ts#astro-docs
5
+ ---
6
+ import { FileTree } from '@astrojs/starlight/components';
7
+ import RunGenerator from '@components/run-generator.astro';
8
+ import GeneratorParameters from '@components/generator-parameters.astro';
9
+ import NxCommands from '@components/nx-commands.astro';
10
+
11
+ This generator scaffolds a documentation site powered by [Astro](https://astro.build/)
12
+ and the [Starlight](https://starlight.astro.build/) docs theme. It wires up
13
+ localisation, reusable content snippets, locale-aware internal links and a
14
+ [`starlight-blog`](https://starlight-blog-docs.vercel.app/) plugin by default.
15
+
16
+ By default it also scaffolds an automated translation pipeline powered by a
17
+ [Strands Agent](https://strandsagents.com/) on
18
+ [Amazon Bedrock](https://aws.amazon.com/bedrock/).
19
+
20
+ ## Usage
21
+
22
+ ### Generate an Astro docs site
23
+
24
+ You can generate a new Astro docs site in two ways:
25
+
26
+ <RunGenerator generator="ts#astro-docs" />
27
+
28
+ ### Options
29
+
30
+ <GeneratorParameters generator="ts#astro-docs" />
31
+
32
+ ## Generator Output
33
+
34
+ By default the generator creates the following project structure at `docs/` in the
35
+ workspace root (configurable via the `name`, `directory` and `subDirectory` options):
36
+
37
+ <FileTree>
38
+ - astro.config.mjs Astro + Starlight configuration (locales, sidebar, blog plugin)
39
+ - tsconfig.json Extends astro/tsconfigs/strict with @components / @assets path aliases
40
+ - project.json Nx project with `build`, `start`, `preview` (and `translate` if enabled) targets
41
+ - scripts
42
+ - translate.ts Translation driver — a Strands agent with a scoped file-editor tool (omitted with `--noTranslation`)
43
+ - translate.config.json Source/target locales, glob patterns, model id, region (omitted with `--noTranslation`)
44
+ - src
45
+ - components
46
+ - link.astro Locale-aware link component (resolves paths against the current locale)
47
+ - snippet.astro Locale-aware snippet loader component
48
+ - content
49
+ - docs
50
+ - en
51
+ - index.mdx Landing page
52
+ - guides
53
+ - getting-started.mdx Sample guide referencing the link and snippet components
54
+ - blog
55
+ - welcome.mdx Sample blog post (omitted with `--noBlog`)
56
+ - snippets
57
+ - example.mdx Sample reusable snippet
58
+ - styles
59
+ - custom.css Starlight theme overrides
60
+ - README.md Project README
61
+ </FileTree>
62
+
63
+ ### Localisation
64
+
65
+ The generator defaults to a single locale (`en`) and redirects the root URL to
66
+ it. To add more languages:
67
+
68
+ 1. Add an entry under `locales` in `astro.config.mjs` (for example `ko: { label: '한국어' }`).
69
+ 2. Create a matching directory under `src/content/docs/<locale>/`.
70
+ 3. Populate it manually, or use the translation target described below.
71
+
72
+ ## Translation
73
+
74
+ Unless you passed `--noTranslation`, the generator adds a `translate` target to
75
+ `project.json`, so you can run:
76
+
77
+ <NxCommands commands={[
78
+ 'translate docs -- --all',
79
+ 'translate docs -- --languages jp,ko',
80
+ 'translate docs -- --dry-run',
81
+ ]} />
82
+
83
+ When run without `--all`, the script only translates files that have changed
84
+ since the last translation commit on the current branch — meaning you can
85
+ safely re-run it on every docs PR without re-translating the whole site.
86
+
87
+ ### Configuring translation
88
+
89
+ Edit `scripts/translate.config.json` to change:
90
+
91
+ | Field | Purpose |
92
+ | --- | --- |
93
+ | `sourceLanguage` | Locale to translate **from** (default `en`). |
94
+ | `targetLanguages` | Locales to translate **to**. Empty by default. For example `["fr", "de", "es", "ja", "ko"]`. |
95
+ | `docsDir` | Path to the docs content directory, relative to the project root. |
96
+ | `include` | Glob patterns (relative to `<docsDir>/<sourceLanguage>`) for files to translate. |
97
+ | `exclude` | Glob patterns to skip. |
98
+ | `modelId` | Bedrock model to use for translations. |
99
+ | `awsRegion` | AWS region the Bedrock client is configured with. Can also be set via `AWS_REGION`. |
100
+ | `concurrency` | Max number of concurrent agent invocations. |
101
+ | `translationCommitMessage` | Commit message marker for translation commits (default `docs: update translations`). |
102
+
103
+ ### Locale-aware internal links
104
+
105
+ The generator ships a `Link` component that automatically resolves internal
106
+ docs paths against the current locale, so a single source of truth produces
107
+ the right URL in every language:
108
+
109
+ ```mdx
110
+ import Link from '@components/link.astro';
111
+
112
+ <Link path="guides/getting-started">Read the getting-started guide</Link>
113
+ ```
114
+
115
+ ### Snippets
116
+
117
+ Reusable content fragments live in `src/content/docs/<locale>/snippets/`. The
118
+ generated `Snippet` component loads the snippet that matches the current
119
+ locale:
120
+
121
+ ```mdx
122
+ import Snippet from '@components/snippet.astro';
123
+
124
+ <Snippet name="example" />
125
+ ```
126
+
127
+ ### Wiring up CI
128
+
129
+ No CI workflow is generated out of the box — add one that:
130
+
131
+ 1. Configures AWS credentials with permission to invoke Bedrock `InvokeModel` on
132
+ the configured model.
133
+ 2. Runs the `translate` target on pull requests that touch your source-language
134
+ docs:
135
+
136
+ <NxCommands commands={['translate docs']} />
137
+
138
+ 3. Commits the resulting translations back to the PR branch. The commit message
139
+ must match the `translationCommitMessage` value in
140
+ `scripts/translate.config.json` (default `docs: update translations`) so that
141
+ subsequent incremental runs can detect the baseline commit and only
142
+ re-translate the files that changed since.
@@ -0,0 +1,105 @@
1
+ ---
2
+ title: Python Agent to A2A Agent
3
+ description: Connect a Python Agent to a remote A2A agent
4
+ when:
5
+ sourceType: py#agent
6
+ targetType:
7
+ - ts#agent
8
+ - py#agent
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 Snippet from '@components/snippet.astro';
16
+
17
+ The `connection` generator can connect your <Link path="guides/py-agent">Python Agent</Link> to a remote [A2A](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-a2a.html) agent — either <Link path="guides/ts-agent">TypeScript</Link> or <Link path="guides/py-agent">Python</Link> — so your agent can delegate to another agent as a tool.
18
+
19
+ The generator sets up all the necessary wiring so your agent can discover and invoke the remote A2A agent, both when deployed to AWS (via Bedrock AgentCore) and when running locally.
20
+
21
+ ## Prerequisites
22
+
23
+ Before using this generator, ensure you have:
24
+
25
+ 1. A Python project with a <Link path="guides/py-agent">Strands Agent</Link> component (any protocol)
26
+ 2. A project with an Agent component generated with `--protocol=A2A` and `--auth=IAM` (either <Link path="guides/ts-agent">`ts#agent`</Link> or <Link path="guides/py-agent">`py#agent`</Link>)
27
+ 3. Both components created with `computeType: BedrockAgentCoreRuntime`
28
+
29
+ ## Usage
30
+
31
+ ### Run the Generator
32
+
33
+ <RunGenerator generator="connection" />
34
+
35
+ Select your host agent project as the source and your A2A agent project as the target. If your projects contain multiple components, specify the `sourceComponent` and `targetComponent` options to disambiguate.
36
+
37
+ ### Options
38
+
39
+ <GeneratorParameters generator="connection" />
40
+
41
+ ## Generator Output
42
+
43
+ The generator creates a shared `agent_connection` Python project at `packages/common/agent_connection/` (if it doesn't already exist). Per-connection client modules are generated into this shared project:
44
+
45
+ <FileTree>
46
+
47
+ - packages/common/agent\_connection
48
+ - \<scope>\_agent\_connection
49
+ - \_\_init\_\_.py Re-exports per-connection clients
50
+ - core
51
+ - agentcore\_a2a\_client.py Core AgentCore A2A client with SigV4 authentication
52
+ - app
53
+ - \<target\_agent\_name>\_client.py Per-connection client for each A2A agent
54
+
55
+ </FileTree>
56
+
57
+ Additionally, the generator:
58
+ - Transforms your agent's `agent.py` to register the remote A2A agent as a tool using `@tool`
59
+ - Adds the `agent_connection` project as a workspace dependency of your agent project
60
+ - Updates the agent's `serve-local` target to depend on the target agent's `serve-local` target
61
+
62
+ ## Using the Connected A2A Agent
63
+
64
+ The generator transforms your agent's `agent.py` to wrap the remote A2A agent as a tool:
65
+
66
+ ```python title="packages/my-project/my_module/agent/agent.py" {4,9-15,21}
67
+ from contextlib import contextmanager
68
+ from strands import Agent, tool
69
+
70
+ from my_scope_agent_connection import RemoteAgentClient
71
+
72
+ @contextmanager
73
+ def get_agent(session_id: str):
74
+ remote_agent = RemoteAgentClient.create(session_id=session_id)
75
+
76
+ @tool
77
+ def ask_remote_agent(prompt: str) -> str:
78
+ """Delegate a question to the remote RemoteAgent A2A agent and return its reply."""
79
+ return str(remote_agent(prompt))
80
+
81
+ yield Agent(
82
+ system_prompt="...",
83
+ tools=[ask_remote_agent],
84
+ )
85
+ ```
86
+
87
+ 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
+
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`.
90
+
91
+ ## Infrastructure
92
+
93
+ <Snippet name="connection/a2a-infrastructure" parentHeading="Infrastructure" />
94
+
95
+ ## Local Development
96
+
97
+ The generator configures the host agent's `serve-local` target to:
98
+ 1. Start the connected A2A agent(s) automatically
99
+ 2. Set `SERVE_LOCAL=true` so the generated client connects directly to `http://localhost:<port>/` instead of AgentCore
100
+
101
+ Run the agent locally with:
102
+
103
+ <NxCommands commands={["<agent-name>-serve-local <project-name>"]} />
104
+
105
+ This will start both the host agent and all connected A2A agents, with the host agent calling the remote agents over plain HTTP on their assigned local ports.
@@ -0,0 +1,147 @@
1
+ ---
2
+ title: Python Agent to MCP
3
+ description: Connect a Python Agent to an MCP server
4
+ when:
5
+ sourceType: py#agent
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 connect your <Link path="guides/py-agent">Python Agent</Link> to an MCP server (either <Link path="guides/ts-mcp-server">TypeScript</Link> or <Link path="guides/py-mcp-server">Python</Link>).
18
+
19
+ The generator sets up all the necessary wiring so your agent can discover and invoke the MCP server's tools, both when deployed to AWS (via Bedrock AgentCore) and when running locally.
20
+
21
+ ## Prerequisites
22
+
23
+ Before using this generator, ensure you have:
24
+
25
+ 1. A Python project with a <Link path="guides/py-agent">Strands Agent</Link> component
26
+ 2. A project with an MCP server component (either <Link path="guides/ts-mcp-server">`ts#mcp-server`</Link> or <Link path="guides/py-mcp-server">`py#mcp-server`</Link>)
27
+ 3. Both components created with `computeType: BedrockAgentCoreRuntime`
28
+
29
+ ## Usage
30
+
31
+ ### Run the Generator
32
+
33
+ <RunGenerator generator="connection" />
34
+
35
+ Select your agent project as the source and your MCP server project as the target. If your projects contain multiple components, specify the `sourceComponent` and `targetComponent` options to disambiguate.
36
+
37
+ ### Options
38
+
39
+ <GeneratorParameters generator="connection" />
40
+
41
+ ## Generator Output
42
+
43
+ The generator creates a shared `agent_connection` Python project at `packages/common/agent_connection/` (if it doesn't already exist). Per-connection client modules are generated into this shared project:
44
+
45
+ <FileTree>
46
+
47
+ - packages/common/agent\_connection
48
+ - \<scope>\_agent\_connection
49
+ - \_\_init\_\_.py Re-exports per-connection clients
50
+ - core
51
+ - agentcore\_mcp\_client.py Core AgentCore MCP client
52
+ - app
53
+ - \<mcp\_server\_name>\_client.py Per-connection client for each MCP server
54
+
55
+ </FileTree>
56
+
57
+ Additionally, the generator:
58
+ - Transforms your agent's `agent.py` to import and use the MCP server's tools via a class-based client
59
+ - Adds the `agent_connection` project as a workspace dependency of your agent project
60
+ - Updates the agent's `serve-local` target to depend on the MCP server's serve target
61
+
62
+ ## Using the Connected MCP Server
63
+
64
+ The generator transforms your agent's `agent.py` to use the MCP server's tools:
65
+
66
+ ```python title="packages/my-project/my_module/agent/agent.py" {4,10-14}
67
+ from contextlib import contextmanager
68
+ from strands import Agent
69
+
70
+ from my_scope_agent_connection import MyMcpServerClient
71
+
72
+ @contextmanager
73
+ def get_agent(session_id: str):
74
+ my_mcp_server = MyMcpServerClient.create(session_id=session_id)
75
+ with (
76
+ my_mcp_server,
77
+ ):
78
+ yield Agent(
79
+ system_prompt="...",
80
+ tools=[*my_mcp_server.list_tools_sync()],
81
+ )
82
+ ```
83
+
84
+ 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).
85
+
86
+ ## Infrastructure
87
+
88
+ <Infrastructure>
89
+ <Fragment slot="cdk">
90
+ After running the connection generator, you need to grant the agent permission to invoke the MCP server:
91
+
92
+ ```ts title="packages/infra/src/stacks/application-stack.ts" {5}
93
+ const mcpServer = new MyMcpServer(this, 'MyMcpServer');
94
+ const myAgent = new MyAgent(this, 'MyAgent');
95
+
96
+ // Grant the agent permissions to invoke the MCP server
97
+ mcpServer.grantInvokeAccess(myAgent);
98
+ ```
99
+
100
+ The MCP server's AgentCore runtime ARN is automatically registered in the `agentcore` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> by the generated CDK construct, so the agent can discover it at runtime.
101
+ </Fragment>
102
+ <Fragment slot="terraform">
103
+ After running the connection generator, you need to grant the agent permission to invoke the MCP server in your Terraform configuration:
104
+
105
+ ```hcl title="packages/infra/src/main.tf" {12-24}
106
+ module "inventory_mcp_server" {
107
+ source = "../../common/terraform/src/app/mcp-servers/inventory-mcp"
108
+ }
109
+
110
+ module "story_agent" {
111
+ source = "../../common/terraform/src/app/agents/story-agent"
112
+ }
113
+
114
+ # Grant the agent permissions to invoke the MCP server
115
+ resource "aws_iam_policy" "agent_invoke_mcp" {
116
+ name = "AgentInvokeMcpPolicy"
117
+ policy = jsonencode({
118
+ Version = "2012-10-17"
119
+ Statement = [{
120
+ Effect = "Allow"
121
+ Action = "bedrock-agentcore:InvokeAgent"
122
+ Resource = module.inventory_mcp_server.agent_core_runtime_arn
123
+ }]
124
+ })
125
+ }
126
+
127
+ resource "aws_iam_role_policy_attachment" "agent_invoke_mcp" {
128
+ role = module.story_agent.agent_core_runtime_role_arn
129
+ policy_arn = aws_iam_policy.agent_invoke_mcp.arn
130
+ }
131
+ ```
132
+
133
+ The MCP server's AgentCore runtime ARN is automatically registered in the `agentcore` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> by the generated Terraform module, so the agent can discover it at runtime.
134
+ </Fragment>
135
+ </Infrastructure>
136
+
137
+ ## Local Development
138
+
139
+ The generator configures the agent's `serve-local` target to:
140
+ 1. Start the connected MCP server(s) automatically
141
+ 2. Set `SERVE_LOCAL=true` so the generated client uses direct HTTP transport instead of AgentCore
142
+
143
+ Run the agent locally with:
144
+
145
+ <NxCommands commands={["<agent-name>-serve-local <project-name>"]} />
146
+
147
+ This will start both the agent and all connected MCP servers, with the agent connecting to the MCP servers directly via HTTP on their assigned local ports.
@@ -0,0 +1,240 @@
1
+ ---
2
+ title: React to AG-UI Agent
3
+ description: Connect a React website to an Agent via the AG-UI protocol using CopilotKit
4
+ when:
5
+ sourceType: react
6
+ targetType:
7
+ - ts#agent
8
+ - py#agent
9
+ protocol: AG-UI
10
+ ---
11
+ import { FileTree } from '@astrojs/starlight/components';
12
+ import Link from '@components/link.astro';
13
+ import RunGenerator from '@components/run-generator.astro';
14
+ import NxCommands from '@components/nx-commands.astro';
15
+ import GeneratorParameters from '@components/generator-parameters.astro';
16
+ import Snippet from '@components/snippet.astro';
17
+
18
+ Nx Plugin for AWS provides a generator to connect a React website to an Agent that exposes the [AG-UI protocol](https://docs.ag-ui.com/). It wires up [CopilotKit](https://docs.copilotkit.ai/aws-strands) with an [`@ag-ui/client`](https://docs.ag-ui.com/) `HttpAgent` on your website, with AWS IAM and Cognito authentication support.
19
+
20
+ ## Prerequisites
21
+
22
+ Before using this generator, ensure you have:
23
+
24
+ 1. A React website (generated using the <Link path="guides/react-website">`ts#react-website` generator</Link>)
25
+ 2. A TypeScript or Python Agent with `protocol=AG-UI` (generated using the <Link path="guides/ts-agent">`ts#agent`</Link> or <Link path="guides/py-agent">`py#agent`</Link> generator)
26
+ 3. For deployed agents, Cognito Auth added via the <Link path="/guides/react-website-auth">`ts#react-website-auth` generator</Link>
27
+
28
+ ## Usage
29
+
30
+ ### Run the Generator
31
+
32
+ <RunGenerator generator="connection" />
33
+
34
+ You will be prompted to select your React website as the source project and the project containing your AG-UI Agent as the target project. If your target project contains multiple components (such as multiple agents or other component types), you will be prompted to specify a `targetComponent` to disambiguate.
35
+
36
+ ### Options
37
+
38
+ <GeneratorParameters generator="connection" />
39
+
40
+ ## Generator Output
41
+
42
+ The generator creates a **single shared** `AguiProvider` component, one hook per connected agent, and a themed wrapper for the CopilotKit chat components:
43
+
44
+ <FileTree>
45
+
46
+ - src
47
+ - components
48
+ - AguiProvider.tsx Single `CopilotKitProvider` for every AG-UI agent. Created on the first `connection` run and updated on subsequent runs to register each new agent.
49
+ - copilot
50
+ - index.tsx Re-exports `CopilotChat`, `CopilotSidebar` and `CopilotPopup` with slot defaults that match your website's `uxProvider` (Cloudscape, Shadcn, or no theme at all).
51
+ - *ThemeComponents*.tsx Per-slot theme components (e.g. `CloudscapeAssistantMessage.tsx`, `ShadcnChatInput.tsx`). Only vended when `uxProvider` is `Cloudscape` or `Shadcn`.
52
+ - hooks
53
+ - useAgui\<AgentName>.tsx Registers one AG-UI agent. One file per `connection` run.
54
+ - useSigV4.tsx SigV4 signing (IAM only)
55
+
56
+ </FileTree>
57
+
58
+ Running `connection` a second time for a different agent **adds a new `useAgui<AgentName>.tsx` hook** and updates `AguiProvider.tsx` to register both hooks — any custom edits you've made to the provider are preserved. `main.tsx` keeps its single `<AguiProvider>` wrapper — you never end up with nested providers.
59
+
60
+ The following dependencies are added to the root `package.json`:
61
+
62
+ - `@copilotkit/react-core` — ships `CopilotKitProvider` and chat components (`CopilotChat`, `CopilotSidebar`, `CopilotPopup`)
63
+ - `@ag-ui/client` — `HttpAgent` used by the generated hooks
64
+ - `aws4fetch`, `oidc-client-ts`, `react-oidc-context`, `@aws-sdk/credential-providers` — IAM auth only
65
+ - `react-oidc-context` — Cognito auth
66
+
67
+ ## How It Works
68
+
69
+ ### AG-UI Connection
70
+
71
+ Each `useAgui<AgentName>` hook reads its agent's runtime value from <Link path="guides/runtime-config">Runtime Configuration</Link> and instantiates an `@ag-ui/client` `HttpAgent`:
72
+
73
+ - **Deployed**: the runtime value is a Bedrock AgentCore Runtime ARN, which is converted to the AgentCore HTTPS endpoint: `https://bedrock-agentcore.<region>.amazonaws.com/runtimes/<encoded-arn>/invocations?qualifier=DEFAULT`
74
+ - **Local development**: `serve-local` overrides the value to the agent's local URL (e.g. `http://localhost:8081`)
75
+
76
+ The shared `AguiProvider` calls every generated hook and spreads each one into `selfManagedAgents` on a single `CopilotKitProvider`, which exposes them all to CopilotKit components.
77
+
78
+ ### CopilotKit Integration
79
+
80
+ [CopilotKit](https://docs.copilotkit.ai/aws-strands) is the 1st-party reference React client for the AG-UI protocol and ships ready-made chat components:
81
+
82
+ - `<CopilotChat />` — full chat interface
83
+ - `<CopilotSidebar />` — fixed side panel chat
84
+ - `<CopilotPopup />` — floating chat popup
85
+
86
+ Place any of these anywhere inside the `<AguiProvider>` wrapper (already wired into `main.tsx` for you).
87
+
88
+ ### Authentication
89
+
90
+ The generated code handles authentication depending on your agent's configuration:
91
+
92
+ - **IAM** (default): uses AWS SigV4-signed HTTP requests. Credentials are obtained from the Cognito Identity Pool configured with your website's auth.
93
+ - **Cognito**: embeds the JWT access token in the `Authorization` header as a Bearer token.
94
+
95
+ ## Infrastructure
96
+
97
+ <Snippet name="connection/react-agent-infrastructure" parentHeading="Infrastructure" />
98
+
99
+ ## Using the Generated Code
100
+
101
+ ### Adding a Chat Interface
102
+
103
+ Instantiate CopilotKit components with `agentId` to select which agent to use. The id is the agent's name — the same one you chose when you ran the <Link path="guides/ts-agent">`ts#agent`</Link> or <Link path="guides/py-agent">`py#agent`</Link> generator — and you can also find it in the generated hook file (e.g. the key returned from `packages/web/src/hooks/useAgui<AgentName>.tsx`).
104
+
105
+ Import the chat components from the generated `./components/copilot` module so the theme that matches your website's `uxProvider` is applied automatically:
106
+
107
+ ```tsx
108
+ import { CopilotChat } from './components/copilot';
109
+
110
+ function ChatPage() {
111
+ return (
112
+ <CopilotChat
113
+ agentId="agent"
114
+ labels={{
115
+ welcomeMessageText: 'How can I help you today?',
116
+ chatInputPlaceholder: 'Ask me anything...',
117
+ }}
118
+ />
119
+ );
120
+ }
121
+ ```
122
+
123
+ ### Connecting Multiple AG-UI Agents
124
+
125
+ Run the `connection` generator once per agent. Every agent registered via the shared `AguiProvider` is visible from anywhere in the app — instantiate a CopilotKit component with a different `agentId` to route each chat to the agent you want:
126
+
127
+ ```tsx
128
+ import { CopilotChat } from './components/copilot';
129
+
130
+ <CopilotChat agentId="story" /> {/* talks to StoryAgent */}
131
+ <CopilotChat agentId="research" /> {/* talks to ResearchAgent */}
132
+ ```
133
+
134
+ ## Customising the Look and Feel
135
+
136
+ `<CopilotChat />` (and `<CopilotSidebar />`, `<CopilotPopup />`) use a recursive **slot system** — you can override any sub-component with either a Tailwind class string, a prop object, or a custom React component. See the [CopilotKit slots guide](https://docs.copilotkit.ai/aws-strands/custom-look-and-feel/slots) for the full slot tree.
137
+
138
+ ### Built-in Themes
139
+
140
+ The generator reads `metadata.uxProvider` from your React website project and vends a themed wrapper module at `src/components/copilot/index.tsx` so the chat components match the rest of your UI without any extra configuration:
141
+
142
+ | `uxProvider` | Styling applied to `CopilotChat` / `CopilotSidebar` / `CopilotPopup` |
143
+ | ------------ | -------------------------------------------------------------------- |
144
+ | `Cloudscape` | Messages render inside Cloudscape `ChatBubble`s with gen-AI `Avatar`s (matching the [Cloudscape generative AI chat pattern](https://cloudscape.design/patterns/genai/generative-AI-chat/)); the typing indicator becomes a `LoadingBar` and the input is a `PromptInput`. Built from `@cloudscape-design/components` and `@cloudscape-design/chat-components`. |
145
+ | `Shadcn` | Assistant messages render in a `bg-muted` bubble with a `Sparkles` avatar; user messages render right-aligned in a `bg-primary` bubble with a `User` avatar. The input is a rounded `Textarea` + pill-shaped send/stop `Button` (Enter submits, Shift+Enter newlines). Uses shadcn primitives from the shared `common-shadcn` package. |
146
+ | `None` (or anything else) | No theme — the module just re-exports the default CopilotKit components. |
147
+
148
+ Import the themed components from the **local theme module** (not `@copilotkit/react-core/v2` directly) so the theme is applied automatically:
149
+
150
+ ```tsx
151
+ import { CopilotChat } from './components/copilot';
152
+
153
+ <CopilotChat agentId="agent" />
154
+ ```
155
+
156
+ The theme is applied as slot defaults, so any slot you explicitly pass still wins — you keep full control whenever you need a one-off override.
157
+
158
+ ### Customising the Theme
159
+
160
+ The generated theme lives entirely inside your project:
161
+
162
+ - `src/components/copilot/index.tsx` — exports the themed `CopilotChat` / `CopilotSidebar` / `CopilotPopup` and the `cloudscapeCopilotTheme` / `shadcnCopilotTheme` objects. Edit this file to change the default slot wiring for every chat in your app.
163
+ - `src/components/copilot/<ThemeComponent>.tsx` — per-slot theme components (e.g. `CloudscapeAssistantMessage`, `ShadcnChatInput`). Edit these to tweak the look of a single slot without re-wiring the theme.
164
+
165
+ For example, to drop in your own user-message renderer while keeping the rest of the theme, edit the relevant file in `src/components/copilot/` and re-export it from `index.tsx`.
166
+
167
+ ### Tailwind styling via slots
168
+
169
+ Per-chat overrides still work alongside the theme — anything you pass as a slot prop overrides the themed default:
170
+
171
+ ```tsx
172
+ <CopilotChat
173
+ agentId="agent"
174
+ // style the input and its children
175
+ input={{
176
+ textArea: 'text-blue-600',
177
+ sendButton: 'bg-blue-600 hover:bg-blue-700',
178
+ }}
179
+ // style nested message slots
180
+ messageView={{
181
+ assistantMessage: 'bg-blue-50 rounded-xl p-2',
182
+ userMessage: 'bg-blue-100 rounded-xl',
183
+ }}
184
+ />
185
+ ```
186
+
187
+ ### Replacing a slot with a custom component
188
+
189
+ Any slot can take a React component instead of a className, so you can replace the default entirely:
190
+
191
+ ```tsx
192
+ import { CopilotChat } from './components/copilot';
193
+
194
+ const MySendButton: React.FC<{ onClick: () => void }> = ({ onClick }) => (
195
+ <button onClick={onClick} className="my-send-btn">
196
+ Send
197
+ </button>
198
+ );
199
+
200
+ <CopilotChat
201
+ agentId="agent"
202
+ input={{ sendButton: MySendButton }}
203
+ />;
204
+ ```
205
+
206
+ Deeper overrides follow the same shape — e.g. replace just the copy button on assistant messages:
207
+
208
+ ```tsx
209
+ <CopilotChat
210
+ agentId="agent"
211
+ messageView={{
212
+ assistantMessage: {
213
+ copyButton: ({ onClick }) => <button onClick={onClick}>Copy</button>,
214
+ },
215
+ }}
216
+ />
217
+ ```
218
+
219
+ ## Local Development
220
+
221
+ The connection generator automatically configures `serve-local` integration:
222
+
223
+ 1. Running `nx serve-local <website>` will also start the agent's local server
224
+ 2. The runtime config is overridden to point to the local AG-UI URL (e.g. `http://localhost:8081`)
225
+ 3. Both the website and the agent hot-reload together
226
+
227
+ <NxCommands commands={['serve-local <WebsiteProject>']} />
228
+
229
+ :::tip[Hot Reloading]
230
+ The website and connected agent hot-reload together, enabling you to quickly iterate on both sides without deploying to AWS.
231
+ :::
232
+
233
+ ## More Information
234
+
235
+ - <Link path="guides/ts-agent">TypeScript Agent Guide</Link>
236
+ - <Link path="guides/py-agent">Python Agent Guide</Link>
237
+ - [AG-UI Protocol Documentation](https://docs.ag-ui.com/)
238
+ - [CopilotKit + AWS Strands Documentation](https://docs.copilotkit.ai/aws-strands)
239
+ - [CopilotKit Custom Look & Feel](https://docs.copilotkit.ai/aws-strands/custom-look-and-feel/slots)
240
+ - [Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/)