@aws/nx-plugin-mcp 1.0.0-rc.32 → 1.0.0-rc.34

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 (34) hide show
  1. package/bin/aws-nx-mcp.js +1444 -1348
  2. package/docs/guides/connection/py-agent-rdb.mdx +162 -0
  3. package/docs/guides/connection/py-fast-api-rdb.mdx +170 -0
  4. package/docs/guides/connection/py-mcp-server-rdb.mdx +171 -0
  5. package/docs/guides/connection/smithy-rdb.mdx +1 -1
  6. package/docs/guides/connection/trpc-rdb.mdx +1 -1
  7. package/docs/guides/connection/ts-agent-rdb.mdx +45 -16
  8. package/docs/guides/connection/ts-mcp-server-rdb.mdx +45 -11
  9. package/docs/guides/connection.mdx +28 -1
  10. package/docs/guides/py-rdb.mdx +250 -0
  11. package/docs/guides/ts-rdb.mdx +48 -483
  12. package/docs/snippets/connection/py-lambda-rdb-ssl-requirements.mdx +7 -0
  13. package/docs/snippets/connection/rdb-api-infrastructure.mdx +36 -15
  14. package/docs/snippets/rdb/architecture.mdx +38 -0
  15. package/docs/snippets/rdb/cluster-instances.mdx +31 -0
  16. package/docs/snippets/rdb/deletion-protection.mdx +34 -0
  17. package/docs/snippets/rdb/deploying.mdx +107 -0
  18. package/docs/snippets/rdb/encryption-key-rotation.mdx +30 -0
  19. package/docs/snippets/rdb/engine-version.mdx +63 -0
  20. package/docs/snippets/rdb/infrastructure.mdx +35 -0
  21. package/docs/snippets/rdb/logging.mdx +32 -0
  22. package/docs/snippets/rdb/rds-proxy.mdx +50 -0
  23. package/docs/snippets/rdb/removal-policy.mdx +57 -0
  24. package/docs/snippets/rdb/serverless-capacity.mdx +32 -0
  25. package/generators.json +27 -0
  26. package/package.json +1 -1
  27. package/src/preset/schema.json +6 -0
  28. package/src/py/rdb/agent-connection/schema.json +27 -0
  29. package/src/py/rdb/fast-api-connection/schema.json +23 -0
  30. package/src/py/rdb/mcp-server-connection/schema.json +27 -0
  31. package/src/py/rdb/schema.json +77 -0
  32. package/src/ts/rdb/schema.json +1 -1
  33. /package/docs/snippets/connection/{lambda-rdb-ssl-requirements.mdx → ts-lambda-rdb-ssl-requirements.mdx} +0 -0
  34. /package/docs/snippets/connection/{mcp-server-rdb-ssl-requirements.mdx → ts-mcp-server-rdb-ssl-requirements.mdx} +0 -0
@@ -48,7 +48,7 @@ The generator modifies two files in your MCP server's source directory:
48
48
 
49
49
  Additionally, the `<mcp-server-name>-dev` target is updated to depend on the database's `dev` target.
50
50
 
51
- ## How It Works
51
+ ## Using the Database in MCP Tools
52
52
 
53
53
  The Prisma client is fetched inside `createServer` and available to all tools and resources registered there:
54
54
 
@@ -85,10 +85,17 @@ The generated MCP server construct implements `IGrantable` and `IConnectable`, s
85
85
  <Fragment slot="cdk">
86
86
 
87
87
  ```ts title="packages/infra/src/stacks/application-stack.ts"
88
+ import { RuntimeNetworkConfiguration } from 'aws-cdk-lib/aws-bedrockagentcore';
88
89
  import { MyDatabase } from ':my-scope/common-constructs';
89
90
 
90
91
  const db = new MyDatabase(this, 'Db', { vpc, ... });
91
- const myMcpServer = new MyMcpServer(this, 'MyMcpServer', { vpc, ... });
92
+
93
+ const myMcpServer = new MyMcpServer(this, 'MyMcpServer', {
94
+ networkConfiguration: RuntimeNetworkConfiguration.usingVpc(this, {
95
+ vpc,
96
+ vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS },
97
+ }),
98
+ });
92
99
 
93
100
  db.allowDefaultPortFrom(myMcpServer);
94
101
  db.grantConnect(myMcpServer);
@@ -99,34 +106,61 @@ db.grantConnect(myMcpServer);
99
106
  </Fragment>
100
107
  <Fragment slot="terraform">
101
108
 
102
- Pass the database module outputs into your MCP server module so it can reach the database and read its runtime configuration:
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:
103
110
 
104
111
  ```hcl title="packages/infra/src/main.tf"
105
112
  module "my_database" {
106
113
  source = "../../common/terraform/src/app/dbs/my-database"
107
114
  vpc_id = module.vpc.vpc_id
108
115
  database_subnet_ids = module.vpc.private_isolated_subnet_ids
116
+ lambda_subnet_ids = module.vpc.private_subnet_ids
109
117
  }
110
118
 
111
119
  module "my_mcp_server" {
112
- source = "../../common/terraform/src/app/mcp-servers/my-mcp-server"
120
+ source = "../../common/terraform/src/app/mcp-servers/my-mcp-server"
121
+ enable_vpc = true
122
+ vpc_id = module.vpc.vpc_id
123
+ subnet_ids = module.vpc.private_subnet_ids
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
+ security_group_id = module.my_database.security_group_id
141
+ referenced_security_group_id = module.my_mcp_server.security_group_id
142
+ from_port = module.my_database.cluster_port
143
+ to_port = module.my_database.cluster_port
144
+ ip_protocol = "tcp"
145
+ }
113
146
 
114
- appconfig_application_id = module.my_database.appconfig_application_id
115
- database_cluster_resource_id = module.my_database.cluster_resource_id
116
- database_runtime_user = module.my_database.database_runtime_user
117
- database_security_group_id = module.my_database.security_group_id
118
- database_port = module.my_database.cluster_port
147
+ resource "aws_vpc_security_group_egress_rule" "mcp_server_to_database" {
148
+ security_group_id = module.my_mcp_server.security_group_id
149
+ referenced_security_group_id = module.my_database.security_group_id
150
+ from_port = module.my_database.cluster_port
151
+ to_port = module.my_database.cluster_port
152
+ ip_protocol = "tcp"
119
153
  }
120
154
  ```
121
155
 
122
- Ensure the MCP server's execution role has `rds-db:connect` permission and that its security group can reach the database security group on the database port.
156
+ `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.
123
157
 
124
158
  </Fragment>
125
159
  </Infrastructure>
126
160
 
127
161
  ### SSL Requirements When Connecting Without RDS Proxy
128
162
 
129
- <Snippet name="connection/mcp-server-rdb-ssl-requirements" parentHeading="SSL Requirements When Connecting Without RDS Proxy" />
163
+ <Snippet name="connection/ts-mcp-server-rdb-ssl-requirements" parentHeading="SSL Requirements When Connecting Without RDS Proxy" />
130
164
 
131
165
  ## Local Development
132
166
 
@@ -125,11 +125,38 @@ The Connection generator supports the following connections:
125
125
  target="aurora"
126
126
  />
127
127
  <ConnectionCard
128
- title="MCP Server to Relational Database"
128
+ title="TypeScript MCP Server to Relational Database"
129
129
  description="Connect a TypeScript MCP Server to an Aurora relational database"
130
130
  href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-rdb`}
131
131
  source="mcp"
132
+ sourceBadge="typescript"
133
+ target="aurora"
134
+ />
135
+ <ConnectionCard
136
+ title="FastAPI to Python Relational Database"
137
+ description="Connect a FastAPI to a Python Aurora relational database"
138
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-fast-api-rdb`}
139
+ source="fastapi"
140
+ target="aurora"
141
+ targetBadge="python"
142
+ />
143
+ <ConnectionCard
144
+ title="Python Agent to Python Relational Database"
145
+ description="Connect a Python Agent to a Python Aurora relational database"
146
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-agent-rdb`}
147
+ source="strands"
148
+ sourceBadge="python"
132
149
  target="aurora"
150
+ targetBadge="python"
151
+ />
152
+ <ConnectionCard
153
+ title="Python MCP Server to Python Relational Database"
154
+ description="Connect a Python MCP Server to a Python Aurora relational database"
155
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-mcp-server-rdb`}
156
+ source="mcp"
157
+ sourceBadge="python"
158
+ target="aurora"
159
+ targetBadge="python"
133
160
  />
134
161
  <ConnectionCard
135
162
  title="tRPC API to TypeScript DynamoDB"
@@ -0,0 +1,250 @@
1
+ ---
2
+ title: Python Relational Database
3
+ description: Create a Python relational database project
4
+ generator: py#rdb
5
+ ---
6
+
7
+ import { FileTree, CardGrid, Tabs, TabItem } from '@astrojs/starlight/components';
8
+ import Astro from '@astrojs/react';
9
+ import ConnectionCard from '@components/connection-card.astro';
10
+ import Infrastructure from '@components/infrastructure.astro';
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
+ This generator creates a new Python relational database project backed by [Amazon Aurora](https://aws.amazon.com/rds/aurora/) (PostgreSQL or MySQL), [SQLModel](https://sqlmodel.tiangolo.com/) for data modelling, and [Alembic](https://alembic.sqlalchemy.org/) for schema migrations. It generates the application code and infrastructure needed to provision and manage a database using AWS CDK or Terraform, with declarative schema definition, automatic migration deployment, and a database client.
18
+
19
+ ## Usage
20
+
21
+ ### Generate a Relational Database
22
+
23
+ <RunGenerator generator="py#rdb" />
24
+
25
+ ### Options
26
+
27
+ <GeneratorParameters generator="py#rdb" />
28
+
29
+ ## Generator Output
30
+
31
+ The generator creates the following project structure in the `<directory>/<name>` directory:
32
+
33
+ <FileTree>
34
+ - \<name>
35
+ - \_\_init\_\_.py Package exports (`get_engine`, `session_context`)
36
+ - connection.py Database engine and session factory with IAM authentication
37
+ - utils.py Runtime config and local development helpers
38
+ - migration_handler.py Lambda handler that runs Alembic migrations during deployment
39
+ - create_db_user_handler.py Lambda handler that creates the application database user during deployment
40
+ - models
41
+ - example.py Example SQLModel table definition
42
+ - migrations
43
+ - versions Alembic-generated migration scripts
44
+ - env.py Alembic environment (connects to the database)
45
+ - script.py.mako Alembic migration script template
46
+ - alembic.ini Alembic configuration
47
+ - config.json Local development connection details and runtime config key
48
+ - Dockerfile.migration Container image for the migration handler
49
+ - Dockerfile.create-db-user Container image for the create-db-user handler
50
+ - project.json Project configuration and build targets
51
+ </FileTree>
52
+
53
+ Local development scripts are shared across all database projects and generated into `packages/common/scripts/`:
54
+
55
+ <FileTree>
56
+ - packages/common/scripts/src/rdb
57
+ - pull-image.ts Pulls the database container image
58
+ - start-container.ts Starts a local database container
59
+ - wait-for-postgres-db.ts Waits for the local database to be ready (PostgreSQL)
60
+ - wait-for-mysql-db.ts Waits for the local database to be ready (MySQL)
61
+ </FileTree>
62
+
63
+ ### Infrastructure
64
+
65
+ <Snippet name="rdb/infrastructure" />
66
+
67
+ #### Architecture
68
+
69
+ <Snippet name="rdb/architecture" />
70
+
71
+ ## Local Development
72
+
73
+ ### Data Modelling
74
+
75
+ The generated project uses [SQLModel](https://sqlmodel.tiangolo.com/) to define your database schema. The workflow is model-first: add or update SQLModel table classes under your database project's `<name>/models/` directory, then generate a migration from those model changes.
76
+
77
+ Example model:
78
+
79
+ ```python title="packages/my_db/my_db/models/example.py"
80
+ from sqlalchemy import Column, String
81
+ from sqlmodel import Field, SQLModel
82
+
83
+
84
+ class ExampleModel(SQLModel, table=True):
85
+ id: int | None = Field(default=None, primary_key=True)
86
+ name: str = Field(sa_column=Column(String(255), nullable=False))
87
+ description: str | None = Field(default=None, sa_column=Column(String(255), nullable=True))
88
+ ```
89
+
90
+ Import your models in `<name>/models/__init__.py` so Alembic can discover them during autogeneration.
91
+
92
+ ### Creating Migrations
93
+
94
+ After adding or updating models, use Alembic to generate and apply migration scripts. The generated `alembic` target automatically starts a local database container before running:
95
+
96
+ <NxCommands commands={['run <project>:alembic revision --autogenerate -m "describe your change"']} />
97
+
98
+ This generates a new migration script under `migrations/versions/`. Review the generated script before applying it.
99
+
100
+ Apply the migration to your local database:
101
+
102
+ <NxCommands commands={['run <project>:migrate']} />
103
+
104
+ When you deploy the AWS stack, the generated infrastructure automatically applies the generated migrations to the deployed database.
105
+
106
+ ### Applying Existing Migrations
107
+
108
+ When you pull migration files created by other developers, apply them to your local database:
109
+
110
+ <NxCommands commands={['run <project>:migrate']} />
111
+
112
+ ### Running Alembic Commands
113
+
114
+ The generated `alembic` target exposes the Alembic CLI, so you can run any Alembic command against the local database. See the [Alembic command reference](https://alembic.sqlalchemy.org/en/latest/ops.html) for available commands.
115
+
116
+ <NxCommands commands={['run <project>:alembic <alembic-command>']} />
117
+
118
+ ### Stopping the Local Database
119
+
120
+ Stopping `dev` (e.g. with `Ctrl+C`) automatically removes the local database container, but preserves the named volume so your data persists across restarts.
121
+
122
+ :::caution[Windows]
123
+ Due to limitations with signal handling on Windows, the container is not automatically removed when `dev` is stopped. You will need to remove it manually:
124
+
125
+ ```bash
126
+ <engine> rm -f <scope>-<db-name>
127
+ ```
128
+
129
+ Replace `<engine>` with your container engine (`docker` or `finch`), `<scope>` with your Nx workspace scope (e.g. `proj`), and `<db-name>` with your database project name (e.g. `my-db`).
130
+ :::
131
+
132
+ ## Connecting to the Database
133
+
134
+ Import `session_context` from your database package and use it as an async context manager to obtain an `AsyncSession`:
135
+
136
+ ```python
137
+ from sqlmodel import select
138
+
139
+ from my_scope.my_db import session_context
140
+ from my_scope.my_db.models.example import ExampleModel
141
+
142
+ async def example():
143
+ async with session_context() as session:
144
+ results = (await session.execute(select(ExampleModel))).all()
145
+ ```
146
+
147
+ The database client automatically:
148
+ - Retrieves database configuration from AWS AppConfig using `RUNTIME_CONFIG_APP_ID` environment variable
149
+ - Generates temporary authentication tokens via `boto3` RDS Signer for IAM authentication
150
+ - Establishes TLS connections using `ssl.create_default_context()`
151
+
152
+ ## Deploying your Database
153
+
154
+ <Snippet name="rdb/deploying" parentHeading="Deploying your Database" />
155
+
156
+ ### RDS Proxy Configuration
157
+
158
+ <Snippet name="rdb/rds-proxy" parentHeading="RDS Proxy Configuration" />
159
+
160
+ #### SSL Requirements When Connecting Without RDS Proxy
161
+
162
+ The Amazon RDS CA bundle must be in the runtime's system trust store.
163
+
164
+ ##### Container Runtimes
165
+
166
+ <Tabs>
167
+ <TabItem label="Amazon Linux">
168
+
169
+ ```dockerfile
170
+ ADD https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /etc/pki/ca-trust/source/anchors/global-bundle.pem
171
+ RUN update-ca-trust
172
+ ```
173
+
174
+ </TabItem>
175
+ <TabItem label="Debian">
176
+
177
+ ```dockerfile
178
+ ADD https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /usr/local/share/ca-certificates/rds-global-bundle.crt
179
+ RUN update-ca-certificates
180
+ ```
181
+
182
+ </TabItem>
183
+ </Tabs>
184
+
185
+ ##### Zip Lambda Functions
186
+
187
+ For zip-deployed Lambda functions (such as a <Link path="guides/fastapi">`py#api` FastAPI</Link>), the Amazon Linux 2023 Lambda execution environment's built-in CA trust store includes the Amazon Root CAs used by RDS.
188
+
189
+ When using RDS Proxy, you do not need to configure the RDS CA bundle in the runtime that connects to the database.
190
+
191
+ ### Cluster Instances
192
+
193
+ <Snippet name="rdb/cluster-instances" />
194
+
195
+ ### Serverless Capacity
196
+
197
+ <Snippet name="rdb/serverless-capacity" />
198
+
199
+ ### Engine Version
200
+
201
+ <Snippet name="rdb/engine-version" />
202
+
203
+ ### Deletion Protection
204
+
205
+ <Snippet name="rdb/deletion-protection" />
206
+
207
+ ### Removal Policy
208
+
209
+ <Snippet name="rdb/removal-policy" />
210
+
211
+ ### Logging and Monitoring
212
+
213
+ <Snippet name="rdb/logging" />
214
+
215
+ ### Encryption Key Rotation
216
+
217
+ <Snippet name="rdb/encryption-key-rotation" />
218
+
219
+ ## Connections
220
+
221
+ Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
222
+
223
+ <CardGrid>
224
+ <ConnectionCard
225
+ title="Python Agent to Relational Database"
226
+ description="Connect a Python Agent to an Aurora relational database"
227
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-agent-rdb`}
228
+ source="strands"
229
+ sourceBadge="python"
230
+ target="aurora"
231
+ targetBadge="python"
232
+ />
233
+ <ConnectionCard
234
+ title="FastAPI to Relational Database"
235
+ description="Connect a FastAPI to an Aurora relational database"
236
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-fast-api-rdb`}
237
+ source="fastapi"
238
+ target="aurora"
239
+ targetBadge="python"
240
+ />
241
+ <ConnectionCard
242
+ title="Python MCP Server to Relational Database"
243
+ description="Connect a Python MCP Server to an Aurora relational database"
244
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-mcp-server-rdb`}
245
+ source="mcp"
246
+ sourceBadge="python"
247
+ target="aurora"
248
+ targetBadge="python"
249
+ />
250
+ </CardGrid>