@aws/nx-plugin-mcp 1.0.0-rc.6 → 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.
- package/bin/aws-nx-mcp.js +11731 -10471
- package/docs/get_started/building-with-ai.mdx +116 -0
- package/docs/get_started/concepts.mdx +67 -0
- package/docs/get_started/existing-project.mdx +180 -0
- package/docs/get_started/graph-builder.mdx +39 -0
- package/docs/get_started/quick-start.mdx +266 -0
- package/docs/get_started/tutorials/contribute-generator.mdx +408 -0
- package/docs/get_started/tutorials/dungeon-game/1.mdx +1210 -0
- package/docs/get_started/tutorials/dungeon-game/2.mdx +237 -0
- package/docs/get_started/tutorials/dungeon-game/3.mdx +76 -0
- package/docs/get_started/tutorials/dungeon-game/4.mdx +162 -0
- package/docs/get_started/tutorials/dungeon-game/overview.mdx +145 -0
- package/docs/get_started/tutorials/dungeon-game/wrap-up.mdx +41 -0
- package/docs/get_started/tutorials/existing-project.mdx +4 -0
- package/docs/get_started/upgrading.mdx +147 -0
- package/docs/guides/agentcore-gateway.mdx +490 -0
- package/docs/guides/connection/agentcore-gateway-agent.mdx +222 -0
- package/docs/guides/connection/agentcore-gateway-gateway.mdx +154 -0
- package/docs/guides/connection/agentcore-gateway-mcp.mdx +134 -0
- package/docs/guides/connection/py-agent-a2a.mdx +48 -16
- package/docs/guides/connection/py-agent-dynamodb.mdx +116 -0
- package/docs/guides/connection/py-agent-gateway.mdx +178 -0
- package/docs/guides/connection/py-agent-mcp.mdx +43 -14
- package/docs/guides/connection/py-agent-rdb.mdx +178 -0
- package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
- package/docs/guides/connection/py-fast-api-rdb.mdx +184 -0
- package/docs/guides/connection/py-mcp-server-dynamodb.mdx +116 -0
- package/docs/guides/connection/py-mcp-server-rdb.mdx +187 -0
- package/docs/guides/connection/react-agentcore-gateway.mdx +112 -0
- package/docs/guides/connection/react-agui.mdx +13 -13
- package/docs/guides/connection/react-fastapi.mdx +38 -2
- package/docs/guides/connection/react-py-agent.mdx +9 -15
- package/docs/guides/connection/react-smithy.mdx +3 -3
- package/docs/guides/connection/react-trpc.mdx +1 -1
- package/docs/guides/connection/react-ts-agent.mdx +8 -8
- package/docs/guides/connection/smithy-dynamodb.mdx +5 -5
- package/docs/guides/connection/smithy-rdb.mdx +9 -9
- package/docs/guides/connection/trpc-dynamodb.mdx +5 -5
- package/docs/guides/connection/trpc-rdb.mdx +6 -6
- package/docs/guides/connection/ts-agent-a2a.mdx +14 -11
- package/docs/guides/connection/ts-agent-dynamodb.mdx +5 -5
- package/docs/guides/connection/ts-agent-gateway.mdx +143 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +12 -9
- package/docs/guides/connection/ts-agent-rdb.mdx +70 -25
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +5 -5
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +68 -18
- package/docs/guides/connection.mdx +122 -5
- package/docs/guides/docker-bundling.mdx +68 -11
- package/docs/guides/fastapi.mdx +249 -9
- package/docs/guides/local-development.mdx +87 -0
- package/docs/guides/nx-generator.mdx +7 -2
- package/docs/guides/nx-migration.mdx +165 -0
- package/docs/guides/py-agent.mdx +264 -49
- package/docs/guides/py-dynamodb.mdx +476 -0
- package/docs/guides/py-mcp-server.mdx +61 -2
- package/docs/guides/py-rdb.mdx +265 -0
- package/docs/guides/python-lambda-function.mdx +1 -1
- package/docs/guides/react-website-auth.mdx +65 -4
- package/docs/guides/react-website.mdx +144 -25
- package/docs/guides/runtime-config.mdx +1 -1
- package/docs/guides/security.mdx +75 -0
- package/docs/guides/smithy-project.mdx +175 -0
- package/docs/guides/terraform-project.mdx +2 -2
- package/docs/guides/trpc.mdx +53 -16
- package/docs/guides/ts-agent.mdx +183 -10
- package/docs/guides/ts-dcr-proxy.mdx +569 -0
- package/docs/guides/ts-dynamodb.mdx +66 -242
- package/docs/guides/ts-lambda-function.mdx +1 -1
- package/docs/guides/ts-mcp-server.mdx +109 -29
- package/docs/guides/ts-nx-plugin.mdx +3 -3
- package/docs/guides/ts-rdb.mdx +113 -467
- package/docs/guides/ts-smithy-api.mdx +221 -16
- package/docs/guides/typescript-infrastructure.mdx +25 -15
- package/docs/guides/typescript-project.mdx +133 -26
- package/docs/guides/workspace.mdx +10 -3
- package/docs/snippets/agent/architecture.mdx +1 -1
- package/docs/snippets/agent/bedrock-deployment.mdx +9 -5
- package/docs/snippets/agent/runtime-arn.mdx +23 -2
- package/docs/snippets/agent/securing-your-agent.mdx +39 -0
- package/docs/snippets/api/access-logging.mdx +33 -0
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +1 -1
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +1 -1
- package/docs/snippets/api/type-safe-api-integrations.mdx +33 -2
- package/docs/snippets/api/waf-configuration.mdx +3 -3
- package/docs/snippets/connection/a2a-infrastructure.mdx +1 -1
- package/docs/snippets/connection/dynamodb-local-development.mdx +2 -2
- package/docs/snippets/connection/lambda-dynamodb-access.mdx +1 -1
- package/docs/snippets/connection/py-dynamodb-local-development.mdx +7 -0
- package/docs/snippets/connection/py-lambda-rdb-ssl-requirements.mdx +7 -0
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +51 -19
- package/docs/snippets/dynamodb/deploying-table.mdx +166 -0
- package/docs/snippets/dynamodb/gsi-config.mdx +38 -0
- package/docs/snippets/dynamodb/infrastructure.mdx +33 -0
- package/docs/snippets/dynamodb/local-dev-start.mdx +13 -0
- package/docs/snippets/dynamodb/local-dev-windows.mdx +15 -0
- package/docs/snippets/lambda-function/deploying-your-function.mdx +3 -3
- package/docs/snippets/mcp/architecture.mdx +1 -1
- package/docs/snippets/mcp/bedrock-deployment.mdx +9 -5
- package/docs/snippets/mcp/config.mdx +3 -2
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +7 -5
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +29 -10
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +4 -4
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +5 -111
- package/docs/snippets/prerequisites.mdx +2 -1
- package/docs/snippets/rdb/architecture.mdx +38 -0
- package/docs/snippets/rdb/cluster-instances.mdx +31 -0
- package/docs/snippets/rdb/deletion-protection.mdx +34 -0
- package/docs/snippets/rdb/deploying.mdx +187 -0
- package/docs/snippets/rdb/encryption-key-rotation.mdx +30 -0
- package/docs/snippets/rdb/engine-version.mdx +63 -0
- package/docs/snippets/rdb/infrastructure.mdx +35 -0
- package/docs/snippets/rdb/logging-mysql.mdx +5 -0
- package/docs/snippets/rdb/logging-postgres.mdx +5 -0
- package/docs/snippets/rdb/performance-insights.mdx +34 -0
- package/docs/snippets/rdb/rds-proxy.mdx +50 -0
- package/docs/snippets/rdb/removal-policy.mdx +57 -0
- package/docs/snippets/rdb/serverless-capacity.mdx +32 -0
- package/docs/snippets/required-prerequisites.mdx +1 -2
- package/docs/snippets/runtime-config-app-id-note.mdx +8 -0
- package/docs/snippets/shared-constructs.mdx +1 -1
- package/docs/snippets/trivy-image-scan.mdx +37 -0
- package/generators.json +145 -10
- package/package.json +1 -1
- package/src/agentcore-gateway/agent-connection/schema.json +31 -0
- package/src/agentcore-gateway/gateway-connection/schema.json +31 -0
- package/src/agentcore-gateway/mcp-connection/schema.json +31 -0
- package/src/agentcore-gateway/react-connection/schema.json +31 -0
- package/src/agentcore-gateway/schema.json +72 -0
- package/src/connection/schema.json +5 -0
- package/src/infra/app/schema.json +5 -0
- package/src/init/schema.json +35 -0
- package/src/internal/test-matrix/schema.json +21 -0
- package/src/license/schema.json +5 -0
- package/src/preset/schema.json +16 -5
- package/src/py/agent/a2a-connection/schema.json +5 -0
- package/src/py/agent/gateway-connection/schema.json +31 -0
- package/src/py/agent/mcp-connection/schema.json +5 -0
- package/src/py/agent/react-connection/schema.json +5 -0
- package/src/py/agent/schema.json +15 -1
- package/src/py/api/schema.json +5 -0
- package/src/py/dynamodb/agent-connection/schema.json +27 -0
- package/src/py/dynamodb/fast-api-connection/schema.json +23 -0
- package/src/py/dynamodb/mcp-server-connection/schema.json +27 -0
- package/src/py/dynamodb/schema.json +76 -0
- package/src/py/fast-api/react/schema.json +5 -0
- package/src/py/fast-api/schema.json +6 -0
- package/src/py/lambda-function/schema.json +5 -0
- package/src/py/mcp-server/schema.json +6 -0
- package/src/py/project/schema.json +5 -0
- package/src/py/rdb/agent-connection/schema.json +27 -0
- package/src/py/rdb/fast-api-connection/schema.json +23 -0
- package/src/py/rdb/mcp-server-connection/schema.json +27 -0
- package/src/py/rdb/schema.json +78 -0
- package/src/smithy/project/schema.json +28 -1
- package/src/smithy/react-connection/schema.json +5 -0
- package/src/smithy/ts/api/schema.json +6 -0
- package/src/terraform/project/schema.json +5 -0
- package/src/trpc/backend/schema.json +6 -0
- package/src/trpc/react/schema.json +5 -0
- package/src/ts/agent/a2a-connection/schema.json +5 -0
- package/src/ts/agent/gateway-connection/schema.json +31 -0
- package/src/ts/agent/mcp-connection/schema.json +5 -0
- package/src/ts/agent/react-connection/schema.json +5 -0
- package/src/ts/agent/schema.json +14 -0
- package/src/ts/api/schema.json +5 -0
- package/src/ts/astro-docs/schema.json +3 -3
- package/src/ts/dcr-proxy/schema.json +44 -0
- package/src/ts/docs/schema.json +3 -3
- package/src/ts/dynamodb/agent-connection/schema.json +5 -0
- package/src/ts/dynamodb/mcp-server-connection/schema.json +5 -0
- package/src/ts/dynamodb/schema.json +26 -2
- package/src/ts/dynamodb/smithy-connection/schema.json +5 -0
- package/src/ts/dynamodb/trpc-connection/schema.json +5 -0
- package/src/ts/lambda-function/schema.json +5 -0
- package/src/ts/lib/schema.json +5 -0
- package/src/ts/mcp-server/schema.json +6 -0
- package/src/ts/nx-generator/schema.json +5 -0
- package/src/ts/nx-migration/schema.json +63 -0
- package/src/ts/nx-plugin/schema.json +5 -0
- package/src/ts/rdb/agent-connection/schema.json +5 -0
- package/src/ts/rdb/mcp-server-connection/schema.json +5 -0
- package/src/ts/rdb/schema.json +7 -1
- package/src/ts/rdb/smithy-connection/schema.json +5 -0
- package/src/ts/rdb/trpc-connection/schema.json +5 -0
- package/src/ts/react-website/app/schema.json +12 -6
- package/src/ts/react-website/cognito-auth/schema.json +5 -0
- package/src/ts/react-website/runtime-config/schema.json +5 -0
- package/src/ts/website/app/schema.json +11 -6
- package/src/ts/website/auth/schema.json +5 -0
- /package/docs/snippets/connection/{lambda-rdb-ssl-requirements.mdx → ts-lambda-rdb-ssl-requirements.mdx} +0 -0
- /package/docs/snippets/connection/{mcp-server-rdb-ssl-requirements.mdx → ts-mcp-server-rdb-ssl-requirements.mdx} +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: FastAPI to Relational Database
|
|
3
|
+
description: Connect a FastAPI to a Python Relational Database
|
|
4
|
+
when:
|
|
5
|
+
sourceType: py#fast-api
|
|
6
|
+
targetType: py#rdb
|
|
7
|
+
---
|
|
8
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
11
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator wires a <Link path="guides/fastapi">FastAPI</Link> to a <Link path="guides/py-rdb">Python Relational Database</Link> project, injecting a typed SQLModel session into your route handlers via a FastAPI dependency.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A FastAPI project (generated with `py#api --framework=fastapi`), see the <Link path="guides/fastapi">`py#api`</Link> guide
|
|
22
|
+
2. A <Link path="guides/py-rdb">`py#rdb`</Link> project
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Run the Generator
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="connection" />
|
|
29
|
+
|
|
30
|
+
Select your FastAPI project as the source and your relational database project as the target.
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
<GeneratorParameters generator="connection" />
|
|
35
|
+
|
|
36
|
+
## Generator Output
|
|
37
|
+
|
|
38
|
+
The generator modifies your FastAPI project:
|
|
39
|
+
|
|
40
|
+
<FileTree>
|
|
41
|
+
|
|
42
|
+
- packages/my_api
|
|
43
|
+
- project.json Adds a dependency from `dev` on the database's `dev` target
|
|
44
|
+
- pyproject.toml Adds the database package as a workspace dependency
|
|
45
|
+
- my_api
|
|
46
|
+
- dependencies
|
|
47
|
+
- my_db.py FastAPI `MyDbSession` dependency for the database session
|
|
48
|
+
|
|
49
|
+
</FileTree>
|
|
50
|
+
|
|
51
|
+
## Using the Database in Route Handlers
|
|
52
|
+
|
|
53
|
+
This generator configures an injectable [FastAPI Dependency](https://fastapi.tiangolo.com/tutorial/dependencies/) which you can use in your route handlers:
|
|
54
|
+
|
|
55
|
+
```python title="packages/my_api/my_api/api.py" {2,6,10}
|
|
56
|
+
from sqlmodel import select
|
|
57
|
+
from my_api.dependencies.my_db import MyDbSession
|
|
58
|
+
from my_scope.my_db.models.example import ExampleModel
|
|
59
|
+
|
|
60
|
+
@app.get("/examples")
|
|
61
|
+
async def list_examples(my_db: MyDbSession):
|
|
62
|
+
return (await my_db.execute(select(ExampleModel))).all()
|
|
63
|
+
|
|
64
|
+
@app.post("/examples")
|
|
65
|
+
async def create_example(name: str, my_db: MyDbSession):
|
|
66
|
+
item = ExampleModel(name=name)
|
|
67
|
+
my_db.add(item)
|
|
68
|
+
await my_db.commit()
|
|
69
|
+
await my_db.refresh(item)
|
|
70
|
+
return item
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
FastAPI automatically opens a new session per request and closes it when the handler returns.
|
|
74
|
+
|
|
75
|
+
## Infrastructure
|
|
76
|
+
|
|
77
|
+
To allow the FastAPI Lambda function to connect to the database at runtime, it must be deployed into the same VPC as the database and granted network and IAM access.
|
|
78
|
+
|
|
79
|
+
<Infrastructure>
|
|
80
|
+
<Fragment slot="cdk">
|
|
81
|
+
|
|
82
|
+
In your application stack, deploy the API into the same VPC as the database, then call `allowDefaultPortFrom` and `grantConnect` to open the network path and grant IAM `rds-db:connect` permission to the Lambda handler:
|
|
83
|
+
|
|
84
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
85
|
+
import { MyDatabase } from '@my-scope/common-constructs';
|
|
86
|
+
|
|
87
|
+
const db = new MyDatabase(this, 'Db', { vpc, ... });
|
|
88
|
+
|
|
89
|
+
const api = new MyApi(this, 'Api', {
|
|
90
|
+
integrations: MyApi.defaultIntegrations(this)
|
|
91
|
+
.withDefaultOptions({
|
|
92
|
+
vpc,
|
|
93
|
+
vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS },
|
|
94
|
+
})
|
|
95
|
+
.build(),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
Object.entries(api.integrations).forEach(([operation, integration]) => {
|
|
99
|
+
db.allowDefaultPortFrom(integration.handler, `Allow ${operation} to connect to the database`);
|
|
100
|
+
db.grantConnect(integration.handler);
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Deploy the API Lambda functions into a **private subnet with egress**, not a private isolated subnet. At runtime, `session_context()` retrieves database configuration from AWS AppConfig, which is a public AWS service endpoint that requires outbound internet access.
|
|
105
|
+
|
|
106
|
+
:::note
|
|
107
|
+
This example grants every handler in your API access, but if only some handlers need access it's better to configure individually.
|
|
108
|
+
:::
|
|
109
|
+
|
|
110
|
+
</Fragment>
|
|
111
|
+
<Fragment slot="terraform">
|
|
112
|
+
|
|
113
|
+
Deploy the API into the same VPC as the database, grant it `rds-db:connect` via `additional_iam_policy_statements`, and open the network path with a pair of security group rules:
|
|
114
|
+
|
|
115
|
+
The example below references the VPC resources from the <Link path="guides/py-rdb">Python Relational Database</Link> deployment guide: `aws_subnet.database` subnets have no internet route, while `aws_subnet.private` subnets have NAT egress.
|
|
116
|
+
|
|
117
|
+
```hcl title="packages/infra/src/main.tf"
|
|
118
|
+
module "my_database" {
|
|
119
|
+
source = "../../common/terraform/src/app/dbs/my-database"
|
|
120
|
+
vpc_id = aws_vpc.main.id
|
|
121
|
+
database_subnet_ids = aws_subnet.database[*].id
|
|
122
|
+
lambda_subnet_ids = aws_subnet.private[*].id
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module "api" {
|
|
126
|
+
source = "../../common/terraform/src/app/apis/my-api"
|
|
127
|
+
enable_vpc = true
|
|
128
|
+
vpc_id = aws_vpc.main.id
|
|
129
|
+
subnet_ids = aws_subnet.private[*].id
|
|
130
|
+
|
|
131
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
132
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
133
|
+
|
|
134
|
+
additional_iam_policy_statements = [
|
|
135
|
+
{
|
|
136
|
+
Effect = "Allow"
|
|
137
|
+
Action = ["rds-db:connect"]
|
|
138
|
+
Resource = [
|
|
139
|
+
"arn:aws:rds-db:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:dbuser:${module.my_database.connect_resource_id}/${module.my_database.database_runtime_user}"
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
resource "aws_vpc_security_group_ingress_rule" "api_to_database" {
|
|
146
|
+
description = "Allow the API Lambda functions to connect to the database"
|
|
147
|
+
security_group_id = module.my_database.security_group_id
|
|
148
|
+
referenced_security_group_id = module.api.security_group_id
|
|
149
|
+
from_port = module.my_database.cluster_port
|
|
150
|
+
to_port = module.my_database.cluster_port
|
|
151
|
+
ip_protocol = "tcp"
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
resource "aws_vpc_security_group_egress_rule" "api_to_database" {
|
|
155
|
+
description = "Allow outbound traffic from the API Lambda functions to the database"
|
|
156
|
+
security_group_id = module.api.security_group_id
|
|
157
|
+
referenced_security_group_id = module.my_database.security_group_id
|
|
158
|
+
from_port = module.my_database.cluster_port
|
|
159
|
+
to_port = module.my_database.cluster_port
|
|
160
|
+
ip_protocol = "tcp"
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Deploy the API Lambda functions into **private subnets with egress**, not private isolated subnets. `appconfig_application_id`/`appconfig_application_arn` come from the shared <Link path="guides/runtime-config">runtime configuration</Link> AppConfig application declared once in your root module, not from the database module — passing them sets `RUNTIME_CONFIG_APP_ID` on the Lambda functions and grants them read access to the application.
|
|
165
|
+
|
|
166
|
+
The AppConfig application must expose the `database` namespace so the database module's runtime configuration entry is deployed. Include it in the `namespaces` when instantiating the `runtime-config/appconfig` module:
|
|
167
|
+
|
|
168
|
+
```hcl title="packages/infra/src/main.tf"
|
|
169
|
+
module "runtime_config_appconfig" {
|
|
170
|
+
source = "../../common/terraform/src/core/runtime-config/appconfig"
|
|
171
|
+
|
|
172
|
+
application_name = "my-app-runtime-config"
|
|
173
|
+
namespaces = ["connection", "agentcore", "database"]
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
</Fragment>
|
|
178
|
+
</Infrastructure>
|
|
179
|
+
|
|
180
|
+
## Local Development
|
|
181
|
+
|
|
182
|
+
<NxCommands commands={["dev <project-name>"]} />
|
|
183
|
+
|
|
184
|
+
This starts the FastAPI and all connected databases. The `LOCAL_DEV=true` environment variable causes the database client to connect to its local Docker database instead of Aurora.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Python MCP Server to DynamoDB
|
|
3
|
+
description: Connect a Python MCP Server to a Python DynamoDB project
|
|
4
|
+
when:
|
|
5
|
+
sourceType: py#mcp-server
|
|
6
|
+
targetType: py#dynamodb
|
|
7
|
+
---
|
|
8
|
+
import Link from '@components/link.astro';
|
|
9
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
10
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
11
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
12
|
+
import Snippet from '@components/snippet.astro';
|
|
13
|
+
|
|
14
|
+
The `connection` generator wires a <Link path="guides/py-mcp-server">Python MCP Server</Link> to a <Link path="guides/py-dynamodb">Python DynamoDB</Link> project, configuring local development so both start together automatically.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
Before using this generator, ensure you have:
|
|
19
|
+
|
|
20
|
+
1. A <Link path="guides/py-mcp-server">`py#mcp-server`</Link> project
|
|
21
|
+
2. A <Link path="guides/py-dynamodb">`py#dynamodb`</Link> project
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Run the Generator
|
|
26
|
+
|
|
27
|
+
<RunGenerator generator="connection" />
|
|
28
|
+
|
|
29
|
+
Select your MCP server project as the source and your DynamoDB project as the target. If the project contains multiple MCP server components, specify `sourceComponent` to disambiguate.
|
|
30
|
+
|
|
31
|
+
### Options
|
|
32
|
+
|
|
33
|
+
<GeneratorParameters generator="connection" />
|
|
34
|
+
|
|
35
|
+
## Generator Output
|
|
36
|
+
|
|
37
|
+
The generator updates the MCP server's `<mcp-server-name>-dev` target in `project.json` to depend on the DynamoDB project's `dev` target, and adds the DynamoDB package as a workspace dependency. No source files are modified.
|
|
38
|
+
|
|
39
|
+
## Using DynamoDB in Tools
|
|
40
|
+
|
|
41
|
+
Import entity classes from the DynamoDB package and use them inside your MCP server tools:
|
|
42
|
+
|
|
43
|
+
```python title="packages/my_project/my_project/my_mcp_server/server.py"
|
|
44
|
+
from my_scope.my_table.entities.example import ExampleModel
|
|
45
|
+
|
|
46
|
+
@mcp.tool()
|
|
47
|
+
def list_examples() -> str:
|
|
48
|
+
"""List all example items."""
|
|
49
|
+
items = list(ExampleModel.scan())
|
|
50
|
+
return str([item.attribute_values for item in items])
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Infrastructure
|
|
54
|
+
|
|
55
|
+
To allow the MCP server's Lambda function to access the DynamoDB table, grant the necessary permissions in your infrastructure.
|
|
56
|
+
|
|
57
|
+
<Infrastructure>
|
|
58
|
+
<Fragment slot="cdk">
|
|
59
|
+
|
|
60
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
61
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
62
|
+
|
|
63
|
+
const table = new MyTable(this, 'Table');
|
|
64
|
+
const myMcpServer = new MyMcpServer(this, 'MyMcpServer');
|
|
65
|
+
|
|
66
|
+
table.grantReadWriteData(myMcpServer);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`grantReadWriteData` grants both the DynamoDB and KMS permissions to the MCP server's execution role.
|
|
70
|
+
</Fragment>
|
|
71
|
+
<Fragment slot="terraform">
|
|
72
|
+
|
|
73
|
+
```hcl title="packages/infra/src/main.tf"
|
|
74
|
+
module "my_table" {
|
|
75
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
resource "aws_iam_role_policy" "dynamodb_access" {
|
|
79
|
+
role = module.my_mcp_server.lambda_role_name
|
|
80
|
+
|
|
81
|
+
policy = jsonencode({
|
|
82
|
+
Version = "2012-10-17"
|
|
83
|
+
Statement = [
|
|
84
|
+
{
|
|
85
|
+
Effect = "Allow"
|
|
86
|
+
Action = [
|
|
87
|
+
"dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:UpdateItem",
|
|
88
|
+
"dynamodb:DeleteItem", "dynamodb:Query", "dynamodb:Scan",
|
|
89
|
+
"dynamodb:BatchGetItem", "dynamodb:BatchWriteItem",
|
|
90
|
+
]
|
|
91
|
+
Resource = [
|
|
92
|
+
module.my_table.table_arn,
|
|
93
|
+
"${module.my_table.table_arn}/index/*",
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
Effect = "Allow"
|
|
98
|
+
Action = [
|
|
99
|
+
"kms:Encrypt",
|
|
100
|
+
"kms:Decrypt",
|
|
101
|
+
"kms:ReEncrypt*",
|
|
102
|
+
"kms:GenerateDataKey*",
|
|
103
|
+
"kms:DescribeKey"
|
|
104
|
+
]
|
|
105
|
+
Resource = [module.my_table.kms_key_arn]
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
</Fragment>
|
|
112
|
+
</Infrastructure>
|
|
113
|
+
|
|
114
|
+
## Local Development
|
|
115
|
+
|
|
116
|
+
<Snippet name="connection/py-dynamodb-local-development" />
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Python MCP Server to Relational Database
|
|
3
|
+
description: Connect a Python MCP Server to a Relational Database
|
|
4
|
+
when:
|
|
5
|
+
sourceType: py#mcp-server
|
|
6
|
+
targetType: py#rdb
|
|
7
|
+
---
|
|
8
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
11
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator wires a <Link path="guides/py-mcp-server">Python MCP Server</Link> to a <Link path="guides/py-rdb">Python Relational Database</Link> project, making the database session available to all tools registered in the server.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A <Link path="guides/py-mcp-server">`py#mcp-server`</Link> project
|
|
22
|
+
2. A <Link path="guides/py-rdb">`py#rdb`</Link> project
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Run the Generator
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="connection" />
|
|
29
|
+
|
|
30
|
+
Select your MCP server project as the source and your relational database project as the target. If the project contains multiple MCP server components, specify `sourceComponent` to disambiguate.
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
<GeneratorParameters generator="connection" />
|
|
35
|
+
|
|
36
|
+
## Generator Output
|
|
37
|
+
|
|
38
|
+
<FileTree>
|
|
39
|
+
|
|
40
|
+
- packages/my\_service
|
|
41
|
+
- project.json Adds a dependency from `my_mcp_server-dev` on the database's `dev` target
|
|
42
|
+
- pyproject.toml Adds the database package as a workspace dependency
|
|
43
|
+
- my\_service
|
|
44
|
+
- my\_mcp\_server
|
|
45
|
+
- Dockerfile Adds the RDS CA bundle used for direct Aurora connections
|
|
46
|
+
|
|
47
|
+
</FileTree>
|
|
48
|
+
|
|
49
|
+
## Using the Database in MCP Tools
|
|
50
|
+
|
|
51
|
+
Import `session_context` from your database package and use it inside your MCP server tools:
|
|
52
|
+
|
|
53
|
+
```python title="packages/my_service/my_service/my_mcp_server/server.py"
|
|
54
|
+
from sqlmodel import select
|
|
55
|
+
from my_scope.my_db import session_context
|
|
56
|
+
from my_scope.my_db.models.example import ExampleModel
|
|
57
|
+
|
|
58
|
+
@mcp.tool()
|
|
59
|
+
async def list_examples() -> str:
|
|
60
|
+
"""List all example records."""
|
|
61
|
+
async with session_context() as session:
|
|
62
|
+
items = (await session.execute(select(ExampleModel))).all()
|
|
63
|
+
return str([item.model_dump() for item in items])
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Multiple Databases
|
|
67
|
+
|
|
68
|
+
Running the generator again with a different target adds the second database alongside the first. Both session contexts are available to all tools:
|
|
69
|
+
|
|
70
|
+
```python title="packages/my_service/my_service/my_mcp_server/server.py"
|
|
71
|
+
from my_scope.my_db import session_context as my_db_session_context
|
|
72
|
+
from my_scope.other_db import session_context as other_db_session_context
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Infrastructure
|
|
76
|
+
|
|
77
|
+
The generated MCP server construct implements `IGrantable` and `IConnectable`, so you can grant network and IAM access to the database directly on the construct.
|
|
78
|
+
|
|
79
|
+
<Infrastructure>
|
|
80
|
+
<Fragment slot="cdk">
|
|
81
|
+
|
|
82
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
83
|
+
import { SecurityGroup } from 'aws-cdk-lib/aws-ec2';
|
|
84
|
+
import { RuntimeNetworkConfiguration } from 'aws-cdk-lib/aws-bedrockagentcore';
|
|
85
|
+
import { MyDatabase } from '@my-scope/common-constructs';
|
|
86
|
+
|
|
87
|
+
const db = new MyDatabase(this, 'Db', { vpc, ... });
|
|
88
|
+
|
|
89
|
+
const myMcpServer = new MyMcpServer(this, 'MyMcpServer', {
|
|
90
|
+
networkConfiguration: RuntimeNetworkConfiguration.usingVpc(this, {
|
|
91
|
+
vpc,
|
|
92
|
+
vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS },
|
|
93
|
+
securityGroups: [
|
|
94
|
+
new SecurityGroup(this, 'MyMcpServerSecurityGroup', { vpc, allowAllOutbound: true }),
|
|
95
|
+
],
|
|
96
|
+
}),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
db.allowDefaultPortFrom(myMcpServer);
|
|
100
|
+
db.grantConnect(myMcpServer);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`allowDefaultPortFrom` opens the security group rule so the MCP server runtime can reach the database port. `grantConnect` grants IAM `rds-db:connect` permission to the server's execution role.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
</Fragment>
|
|
107
|
+
<Fragment slot="terraform">
|
|
108
|
+
|
|
109
|
+
Run the MCP server inside the same VPC as the database, grant it `rds-db:connect` via `additional_iam_policy_statements`, and open the network path with a pair of security group rules. The `aws_vpc.main` and `aws_subnet` resources are defined in the database deployment guide:
|
|
110
|
+
|
|
111
|
+
```hcl title="packages/infra/src/main.tf"
|
|
112
|
+
module "my_database" {
|
|
113
|
+
source = "../../common/terraform/src/app/dbs/my-database"
|
|
114
|
+
vpc_id = aws_vpc.main.id
|
|
115
|
+
database_subnet_ids = aws_subnet.database[*].id
|
|
116
|
+
lambda_subnet_ids = aws_subnet.private[*].id
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module "my_mcp_server" {
|
|
120
|
+
source = "../../common/terraform/src/app/mcp-servers/my-mcp-server"
|
|
121
|
+
enable_vpc = true
|
|
122
|
+
vpc_id = aws_vpc.main.id
|
|
123
|
+
subnet_ids = aws_subnet.private[*].id
|
|
124
|
+
|
|
125
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
126
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
127
|
+
|
|
128
|
+
additional_iam_policy_statements = [
|
|
129
|
+
{
|
|
130
|
+
Effect = "Allow"
|
|
131
|
+
Action = ["rds-db:connect"]
|
|
132
|
+
Resource = [
|
|
133
|
+
"arn:aws:rds-db:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:dbuser:${module.my_database.connect_resource_id}/${module.my_database.database_runtime_user}"
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resource "aws_vpc_security_group_ingress_rule" "mcp_server_to_database" {
|
|
140
|
+
description = "Allow the MCP server runtime to connect to the database"
|
|
141
|
+
security_group_id = module.my_database.security_group_id
|
|
142
|
+
referenced_security_group_id = module.my_mcp_server.security_group_id
|
|
143
|
+
from_port = module.my_database.cluster_port
|
|
144
|
+
to_port = module.my_database.cluster_port
|
|
145
|
+
ip_protocol = "tcp"
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
resource "aws_vpc_security_group_egress_rule" "mcp_server_to_database" {
|
|
149
|
+
description = "Allow outbound traffic from the MCP server runtime to the database"
|
|
150
|
+
security_group_id = module.my_mcp_server.security_group_id
|
|
151
|
+
referenced_security_group_id = module.my_database.security_group_id
|
|
152
|
+
from_port = module.my_database.cluster_port
|
|
153
|
+
to_port = module.my_database.cluster_port
|
|
154
|
+
ip_protocol = "tcp"
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`appconfig_application_id`/`appconfig_application_arn` come from the shared <Link path="guides/runtime-config">runtime configuration</Link> AppConfig application declared once in your root module, not from the database module. Include the `database` namespace when instantiating it so the database module's runtime configuration entry is deployed:
|
|
159
|
+
|
|
160
|
+
```hcl title="packages/infra/src/main.tf"
|
|
161
|
+
module "runtime_config_appconfig" {
|
|
162
|
+
source = "../../common/terraform/src/core/runtime-config/appconfig"
|
|
163
|
+
|
|
164
|
+
application_name = "my-app-runtime-config"
|
|
165
|
+
namespaces = ["connection", "agentcore", "database"]
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
</Fragment>
|
|
170
|
+
</Infrastructure>
|
|
171
|
+
|
|
172
|
+
### SSL Requirements When Connecting Without RDS Proxy
|
|
173
|
+
|
|
174
|
+
When the MCP server connects directly to the Aurora cluster (without RDS Proxy), the connection generator updates the generated MCP server Dockerfile to install the Amazon RDS CA bundle into the system trust store:
|
|
175
|
+
|
|
176
|
+
```dockerfile
|
|
177
|
+
ADD https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /usr/local/share/ca-certificates/rds-global-bundle.crt
|
|
178
|
+
RUN update-ca-certificates
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
When using RDS Proxy, you do not need to configure the RDS CA bundle in the MCP server runtime.
|
|
182
|
+
|
|
183
|
+
## Local Development
|
|
184
|
+
|
|
185
|
+
<NxCommands commands={["<mcp-server-name>-dev <project-name>"]} />
|
|
186
|
+
|
|
187
|
+
This starts the MCP server and all connected databases. The `LOCAL_DEV=true` environment variable causes the database client to connect to its local Docker database instead of Aurora.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: React Website to AgentCore Gateway
|
|
3
|
+
description: Connect a React website to agents through an AgentCore Gateway
|
|
4
|
+
when:
|
|
5
|
+
sourceType: ts#react-website
|
|
6
|
+
targetType: agentcore-gateway
|
|
7
|
+
---
|
|
8
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
11
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator can connect a <Link path="guides/react-website">React website</Link> to the agents fronted by an <Link path="guides/agentcore-gateway">AgentCore Gateway</Link> generated with `protocol: http`.
|
|
16
|
+
|
|
17
|
+
The browser talks only to the Gateway — requests to `<gatewayUrl>/<targetName>/invocations` are proxied to the agent runtime behind it. Because the website never needs to reach the runtimes directly, the agents can be deployed inside a VPC, with the Gateway as the single governed entry point providing authentication and observability.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
Before using this generator, ensure you have:
|
|
22
|
+
|
|
23
|
+
1. A <Link path="guides/react-website">React website</Link> project
|
|
24
|
+
2. An <Link path="guides/agentcore-gateway">`agentcore-gateway`</Link> project generated with `protocol: http`
|
|
25
|
+
3. At least one AG-UI or HTTP agent attached to the Gateway via the <Link path="guides/connection/agentcore-gateway-agent">Gateway to agent connection generator</Link>
|
|
26
|
+
|
|
27
|
+
The generator creates a website client for **each** AG-UI or HTTP agent attached to the Gateway (A2A targets are skipped — they speak agent-to-agent JSON-RPC, not a browser protocol). It generates the same clients as connecting the website to each agent directly (<Link path="guides/connection/react-agui">AG-UI/CopilotKit</Link> for AG-UI agents, an <Link path="guides/connection/react-py-agent">OpenAPI client</Link> for Python HTTP agents), routed through the Gateway rather than at the runtime.
|
|
28
|
+
|
|
29
|
+
:::note[Authentication]
|
|
30
|
+
The browser authenticates with the **Gateway**, not the agents: SigV4 for an IAM Gateway (via the website's Cognito identity pool), or a JWT bearer token for a Cognito Gateway.
|
|
31
|
+
:::
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Run the Generator
|
|
36
|
+
|
|
37
|
+
<RunGenerator generator="connection" />
|
|
38
|
+
|
|
39
|
+
Select the website project as the source and the Gateway project as the target.
|
|
40
|
+
|
|
41
|
+
### Options
|
|
42
|
+
|
|
43
|
+
<GeneratorParameters generator="connection" />
|
|
44
|
+
|
|
45
|
+
## Generator Output
|
|
46
|
+
|
|
47
|
+
For each fronted AG-UI agent, the same files as the <Link path="guides/connection/react-agui">React to AG-UI agent connection</Link> are generated (an `AguiProvider`, a `useAgui<Agent>` hook and a themed CopilotKit component module), with the hook reading the Gateway's URL from runtime configuration:
|
|
48
|
+
|
|
49
|
+
<FileTree>
|
|
50
|
+
|
|
51
|
+
- packages/\<website>/src
|
|
52
|
+
- components
|
|
53
|
+
- AguiProvider.tsx CopilotKit provider registering each agent
|
|
54
|
+
- copilot/ Themed chat components
|
|
55
|
+
- hooks
|
|
56
|
+
- useAgui\<Agent>.tsx Connects to the agent via the Gateway's `/<targetName>/invocations` route
|
|
57
|
+
|
|
58
|
+
</FileTree>
|
|
59
|
+
|
|
60
|
+
For each fronted Python HTTP agent, the same files as the <Link path="guides/connection/react-py-agent">React to Python agent connection</Link> are generated (a type-safe OpenAPI client, hooks, and a provider), with the client's base URL routed through the Gateway.
|
|
61
|
+
|
|
62
|
+
The Gateway's URL is registered in the `connection.gateways.<GatewayClassName>` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link>, so it is published to the website's `runtime-config.json`.
|
|
63
|
+
|
|
64
|
+
## Granting website users access
|
|
65
|
+
|
|
66
|
+
For an **IAM** Gateway, grant the website's authenticated users permission to invoke it (a **Cognito** Gateway needs no grant — the browser authenticates with its JWT bearer token instead):
|
|
67
|
+
|
|
68
|
+
<Infrastructure>
|
|
69
|
+
<Fragment slot="cdk">
|
|
70
|
+
```ts title="packages/infra/src/stacks/application-stack.ts" {6}
|
|
71
|
+
const identity = new UserIdentity(this, 'UserIdentity');
|
|
72
|
+
new Website(this, 'Website');
|
|
73
|
+
|
|
74
|
+
const myGateway = new MyGateway(this, 'MyGateway');
|
|
75
|
+
myGateway.addAgent(myAgent);
|
|
76
|
+
myGateway.grantInvokeAccess(identity.identityPool.authenticatedRole);
|
|
77
|
+
```
|
|
78
|
+
</Fragment>
|
|
79
|
+
<Fragment slot="terraform">
|
|
80
|
+
```hcl title="packages/infra/src/main.tf"
|
|
81
|
+
resource "aws_iam_policy" "gateway_invoke_policy" {
|
|
82
|
+
name = "GatewayInvokePolicy"
|
|
83
|
+
|
|
84
|
+
policy = jsonencode({
|
|
85
|
+
Version = "2012-10-17"
|
|
86
|
+
Statement = [
|
|
87
|
+
{
|
|
88
|
+
Effect = "Allow"
|
|
89
|
+
Action = ["bedrock-agentcore:InvokeGateway"]
|
|
90
|
+
Resource = [module.my_gateway.gateway_arn]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
resource "aws_iam_role_policy_attachment" "authenticated_gateway_access" {
|
|
97
|
+
role = module.user_identity.authenticated_role_name
|
|
98
|
+
policy_arn = aws_iam_policy.gateway_invoke_policy.arn
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
</Fragment>
|
|
102
|
+
</Infrastructure>
|
|
103
|
+
|
|
104
|
+
## Local Development
|
|
105
|
+
|
|
106
|
+
The website's `dev` target gains a dependency on the Gateway project's `dev` target, which starts the local gateway plus every attached agent. The website's runtime configuration is overridden in `local-dev` mode to point the Gateway's URL at the local gateway, so the browser exercises the same `/<targetName>/invocations` routes locally:
|
|
107
|
+
|
|
108
|
+
<NxCommands commands={["dev <website-name>"]} />
|
|
109
|
+
|
|
110
|
+
## Connecting new agents
|
|
111
|
+
|
|
112
|
+
The generator connects the website to the agents attached to the Gateway **at the time it runs**. After attaching another agent to the Gateway, re-run the connection generator to generate its website client — existing clients are left untouched.
|
|
@@ -22,7 +22,7 @@ Nx Plugin for AWS provides a generator to connect a React website to an Agent th
|
|
|
22
22
|
Before using this generator, ensure you have:
|
|
23
23
|
|
|
24
24
|
1. A React website (generated using the <Link path="guides/react-website">`ts#website` generator</Link>)
|
|
25
|
-
2. A TypeScript or Python Agent with `protocol=
|
|
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
26
|
3. For deployed agents, Cognito Auth added via the <Link path="/guides/react-website-auth">`ts#website#auth` generator</Link>
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
@@ -47,8 +47,8 @@ The generator creates a **single shared** `AguiProvider` component, one hook per
|
|
|
47
47
|
- components
|
|
48
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
49
|
- copilot
|
|
50
|
-
- index.tsx Re-exports `CopilotChat`, `CopilotSidebar` and `CopilotPopup` with slot defaults that match your website's `
|
|
51
|
-
- *ThemeComponents*.tsx Per-slot theme components (e.g. `CloudscapeAssistantMessage.tsx`, `ShadcnChatInput.tsx`). Only vended when `
|
|
50
|
+
- index.tsx Re-exports `CopilotChat`, `CopilotSidebar` and `CopilotPopup` with slot defaults that match your website's `ux` (Cloudscape, Shadcn, or no theme at all).
|
|
51
|
+
- *ThemeComponents*.tsx Per-slot theme components (e.g. `CloudscapeAssistantMessage.tsx`, `ShadcnChatInput.tsx`). Only vended when `ux` is `cloudscape` or `shadcn`.
|
|
52
52
|
- hooks
|
|
53
53
|
- useAgui\<AgentName>.tsx Registers one AG-UI agent. One file per `connection` run.
|
|
54
54
|
- useSigV4.tsx SigV4 signing (IAM only)
|
|
@@ -71,7 +71,7 @@ The following dependencies are added to the root `package.json`:
|
|
|
71
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
72
|
|
|
73
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**: `
|
|
74
|
+
- **Local development**: `dev` overrides the value to the agent's local URL (e.g. `http://localhost:8081`)
|
|
75
75
|
|
|
76
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
77
|
|
|
@@ -102,7 +102,7 @@ The generated code handles authentication depending on your agent's configuratio
|
|
|
102
102
|
|
|
103
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
104
|
|
|
105
|
-
Import the chat components from the generated `./components/copilot` module so the theme that matches your website's `
|
|
105
|
+
Import the chat components from the generated `./components/copilot` module so the theme that matches your website's `ux` is applied automatically:
|
|
106
106
|
|
|
107
107
|
```tsx
|
|
108
108
|
import { CopilotChat } from './components/copilot';
|
|
@@ -137,13 +137,13 @@ import { CopilotChat } from './components/copilot';
|
|
|
137
137
|
|
|
138
138
|
### Built-in Themes
|
|
139
139
|
|
|
140
|
-
The generator reads `metadata.
|
|
140
|
+
The generator reads `metadata.ux` 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
141
|
|
|
142
|
-
| `
|
|
142
|
+
| `ux` | Styling applied to `CopilotChat` / `CopilotSidebar` / `CopilotPopup` |
|
|
143
143
|
| ------------ | -------------------------------------------------------------------- |
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
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
147
|
|
|
148
148
|
Import the themed components from the **local theme module** (not `@copilotkit/react-core/v2` directly) so the theme is applied automatically:
|
|
149
149
|
|
|
@@ -218,13 +218,13 @@ Deeper overrides follow the same shape — e.g. replace just the copy button on
|
|
|
218
218
|
|
|
219
219
|
## Local Development
|
|
220
220
|
|
|
221
|
-
The connection generator automatically configures `
|
|
221
|
+
The connection generator automatically configures `dev` integration:
|
|
222
222
|
|
|
223
|
-
1. Running `nx
|
|
223
|
+
1. Running `nx dev <website>` will also start the agent's local server
|
|
224
224
|
2. The runtime config is overridden to point to the local AG-UI URL (e.g. `http://localhost:8081`)
|
|
225
225
|
3. Both the website and the agent hot-reload together
|
|
226
226
|
|
|
227
|
-
<NxCommands commands={['
|
|
227
|
+
<NxCommands commands={['dev <WebsiteProject>']} />
|
|
228
228
|
|
|
229
229
|
:::tip[Hot Reloading]
|
|
230
230
|
The website and connected agent hot-reload together, enabling you to quickly iterate on both sides without deploying to AWS.
|