@aws/nx-plugin-mcp 1.0.0-rc.9 → 1.0.0-rc.91
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 +13439 -11631
- 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 +277 -0
- package/docs/get_started/tutorials/contribute-generator.mdx +408 -0
- package/docs/get_started/tutorials/dungeon-game/1.mdx +1578 -0
- package/docs/get_started/tutorials/dungeon-game/2.mdx +245 -0
- package/docs/get_started/tutorials/dungeon-game/3.mdx +66 -0
- package/docs/get_started/tutorials/dungeon-game/4.mdx +164 -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/upgrading.mdx +157 -0
- package/docs/guides/agentcore-gateway.mdx +490 -0
- package/docs/guides/agentcore-harness.mdx +312 -0
- package/docs/guides/astro-docs.mdx +8 -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 +115 -0
- package/docs/guides/connection/py-agent-gateway.mdx +182 -0
- package/docs/guides/connection/py-agent-mcp.mdx +43 -14
- package/docs/guides/connection/py-agent-rdb.mdx +169 -0
- package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
- package/docs/guides/connection/py-fast-api-rdb.mdx +175 -0
- package/docs/guides/connection/py-mcp-server-dynamodb.mdx +115 -0
- package/docs/guides/connection/py-mcp-server-rdb.mdx +178 -0
- package/docs/guides/connection/react-agentcore-gateway.mdx +112 -0
- package/docs/guides/connection/react-agui.mdx +33 -14
- package/docs/guides/connection/react-fastapi.mdx +39 -3
- package/docs/guides/connection/react-py-agent.mdx +10 -16
- package/docs/guides/connection/react-smithy.mdx +4 -4
- package/docs/guides/connection/react-trpc.mdx +1 -1
- package/docs/guides/connection/react-ts-agent.mdx +9 -9
- 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 +4 -4
- package/docs/guides/connection/trpc-rdb.mdx +5 -5
- package/docs/guides/connection/ts-agent-a2a.mdx +14 -11
- package/docs/guides/connection/ts-agent-dynamodb.mdx +35 -36
- package/docs/guides/connection/ts-agent-gateway.mdx +147 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +12 -9
- package/docs/guides/connection/ts-agent-rdb.mdx +61 -25
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +35 -36
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +59 -18
- package/docs/guides/connection.mdx +122 -5
- package/docs/guides/docker-bundling.mdx +82 -14
- package/docs/guides/fastapi.mdx +253 -12
- package/docs/guides/local-development.mdx +87 -0
- package/docs/guides/nx-generator.mdx +4 -3
- package/docs/guides/nx-migration.mdx +165 -0
- package/docs/guides/py-agent.mdx +332 -55
- package/docs/guides/py-dynamodb.mdx +476 -0
- package/docs/guides/py-mcp-server.mdx +57 -2
- package/docs/guides/py-rdb.mdx +269 -0
- package/docs/guides/python-lambda-function.mdx +1 -1
- package/docs/guides/python-project.mdx +31 -0
- package/docs/guides/react-website-auth.mdx +104 -5
- package/docs/guides/react-website.mdx +409 -95
- package/docs/guides/runtime-config.mdx +17 -4
- package/docs/guides/security.mdx +75 -0
- package/docs/guides/smithy-project.mdx +167 -0
- package/docs/guides/terraform-project.mdx +119 -8
- package/docs/guides/trpc.mdx +55 -14
- package/docs/guides/ts-agent.mdx +207 -23
- 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 +111 -29
- package/docs/guides/ts-nx-plugin.mdx +4 -4
- package/docs/guides/ts-rdb.mdx +116 -466
- package/docs/guides/ts-smithy-api.mdx +260 -16
- package/docs/guides/typescript-infrastructure.mdx +79 -25
- package/docs/guides/typescript-project.mdx +157 -24
- package/docs/guides/workspace.mdx +31 -2
- 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 +38 -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 +218 -373
- 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 +2 -2
- 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 +42 -19
- package/docs/snippets/dynamodb/deploying-table.mdx +176 -0
- package/docs/snippets/dynamodb/encryption-options.mdx +168 -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/experimental-generator.mdx +8 -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/mcp/shared-constructs.mdx +4 -5
- 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 +1 -4
- package/docs/snippets/rdb/admin-credentials.mdx +42 -0
- package/docs/snippets/rdb/architecture.mdx +39 -0
- package/docs/snippets/rdb/cluster-instances.mdx +31 -0
- package/docs/snippets/rdb/deletion-protection.mdx +64 -0
- package/docs/snippets/rdb/deploying.mdx +178 -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 +36 -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/recommended-prerequisites.mdx +10 -0
- package/docs/snippets/required-prerequisites.mdx +1 -4
- 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 +170 -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/agentcore-harness/schema.json +53 -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/open-api/json-metadata/schema.json +20 -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 +6 -1
- package/src/py/mcp-server/schema.json +6 -0
- package/src/py/project/schema.json +6 -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,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Python Agent to Gateway
|
|
3
|
+
description: Connect a Python Agent to an AgentCore Gateway
|
|
4
|
+
when:
|
|
5
|
+
sourceType: py#agent
|
|
6
|
+
targetType: agentcore-gateway
|
|
7
|
+
---
|
|
8
|
+
import { FileTree, Tabs, TabItem } 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 your <Link path="guides/py-agent">Python Agent</Link> to an <Link path="guides/agentcore-gateway">AgentCore Gateway</Link>.
|
|
16
|
+
|
|
17
|
+
The generator wires the agent so it authenticates to the Gateway with IAM SigV4 (via `httpx` request signing) when deployed, and connects to the local gateway started by the Gateway project when running locally.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
Before using this generator, ensure you have:
|
|
22
|
+
|
|
23
|
+
1. A Python project with a <Link path="guides/py-agent">Agent</Link> component (`infra: agentcore`)
|
|
24
|
+
2. A <Link path="guides/agentcore-gateway">`agentcore-gateway`</Link> project with `protocol: mcp` and `auth: iam`
|
|
25
|
+
|
|
26
|
+
The Gateway must serve the `mcp` protocol — the agent reaches it as an MCP client, so its targets are exposed as tools. The Gateway must also use IAM authentication: the agent signs its requests with SigV4 using its own execution role. The generator rejects Cognito-authenticated gateways.
|
|
27
|
+
|
|
28
|
+
:::note[One direction per Gateway]
|
|
29
|
+
A single Gateway cannot both be called by an agent and front one. Fronting agent runtimes needs `protocol: http` (see <Link path="guides/connection/agentcore-gateway-agent">Gateway to Agent</Link>), whereas being called by an agent needs `protocol: mcp`. Use a separate Gateway for each direction.
|
|
30
|
+
:::
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Run the Generator
|
|
35
|
+
|
|
36
|
+
<RunGenerator generator="connection" />
|
|
37
|
+
|
|
38
|
+
Select the agent project as the source and the Gateway project as the target.
|
|
39
|
+
|
|
40
|
+
### Options
|
|
41
|
+
|
|
42
|
+
<GeneratorParameters generator="connection" />
|
|
43
|
+
|
|
44
|
+
## Generator Output
|
|
45
|
+
|
|
46
|
+
The generator emits shared core-gateway modules into your `agent_connection` Python project, plus a per-Gateway wrapper, and modifies your agent:
|
|
47
|
+
|
|
48
|
+
<FileTree>
|
|
49
|
+
|
|
50
|
+
- packages/common/agent\_connection
|
|
51
|
+
- \<scope>\_agent\_connection
|
|
52
|
+
- core/
|
|
53
|
+
- agentcore\_endpoints.py Framework-agnostic ARN/URL resolution
|
|
54
|
+
- agentcore\_gateway\_mcp\_transport.py Framework-agnostic Gateway MCP transport
|
|
55
|
+
- agentcore\_gateway\_mcp\_client\_\<framework>.py Gateway MCP client for your agent's framework
|
|
56
|
+
- auth/ Framework-agnostic SigV4 / session-forwarding `httpx.Auth`
|
|
57
|
+
- app/
|
|
58
|
+
- \<gateway\_snake>\_client\_\<framework>.py Per-Gateway client wrapper
|
|
59
|
+
- \_\_init\_\_.py Re-exports the Gateway client
|
|
60
|
+
|
|
61
|
+
</FileTree>
|
|
62
|
+
|
|
63
|
+
The client suffix matches your agent's framework (`_strands` or `_langchain`).
|
|
64
|
+
|
|
65
|
+
Additionally, the generator:
|
|
66
|
+
|
|
67
|
+
- Modifies your agent's `agent.py` to import the Gateway client and register its tools in `tools`
|
|
68
|
+
- Adds `agent_connection` as a workspace dependency of the agent
|
|
69
|
+
- Wires the agent's `<agent>-dev` target to depend on the Gateway's `dev` target
|
|
70
|
+
|
|
71
|
+
## Using the connected Gateway
|
|
72
|
+
|
|
73
|
+
The generator transforms your agent's `agent.py` to use the Gateway client:
|
|
74
|
+
|
|
75
|
+
<Tabs syncKey="agent-framework">
|
|
76
|
+
<TabItem label="Strands" _filter={{ framework: 'strands' }}>
|
|
77
|
+
```python title="packages/example/example/my_agent/agent.py" {4,8,9-13}
|
|
78
|
+
from contextlib import contextmanager
|
|
79
|
+
from strands import Agent
|
|
80
|
+
|
|
81
|
+
from my_scope_agent_connection import MyGatewayClientStrands
|
|
82
|
+
|
|
83
|
+
@contextmanager
|
|
84
|
+
def get_agent():
|
|
85
|
+
my_gateway = MyGatewayClientStrands.create()
|
|
86
|
+
with (
|
|
87
|
+
my_gateway,
|
|
88
|
+
):
|
|
89
|
+
yield Agent(
|
|
90
|
+
system_prompt="...",
|
|
91
|
+
tools=[*my_gateway.list_tools_sync()],
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`MyGatewayClientStrands.create()` returns a single context-manageable `MCPClient` whose `list_tools_sync()` yields every tool available through the Gateway.
|
|
96
|
+
</TabItem>
|
|
97
|
+
<TabItem label="LangChain" _filter={{ framework: 'langchain' }}>
|
|
98
|
+
```python title="packages/example/example/my_agent/agent.py" {4,7,11}
|
|
99
|
+
from langchain.agents import create_agent
|
|
100
|
+
from langchain_aws import ChatBedrockConverse
|
|
101
|
+
|
|
102
|
+
from my_scope_agent_connection import MyGatewayClientLangChain
|
|
103
|
+
|
|
104
|
+
def get_agent():
|
|
105
|
+
my_gateway = MyGatewayClientLangChain.create()
|
|
106
|
+
return create_agent(
|
|
107
|
+
model=ChatBedrockConverse(model=MODEL_ID, region_name=REGION),
|
|
108
|
+
system_prompt="...",
|
|
109
|
+
tools=[*my_gateway],
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`MyGatewayClientLangChain.create()` returns a list of tools loaded via [`langchain-mcp-adapters`](https://docs.langchain.com/oss/python/langchain/mcp). Each tool opens a fresh session per call, so no `with` block is needed.
|
|
114
|
+
</TabItem>
|
|
115
|
+
</Tabs>
|
|
116
|
+
|
|
117
|
+
In both cases the client behaves the same way per mode:
|
|
118
|
+
|
|
119
|
+
- **Deployed mode** (`LOCAL_DEV` unset): tools pointed at the Gateway's MCP endpoint, SigV4-signed.
|
|
120
|
+
- **Local mode** (`LOCAL_DEV=true`): plain-HTTP tools pointed at the local gateway started by the Gateway project's `dev` target.
|
|
121
|
+
|
|
122
|
+
The session ID is propagated to downstream MCP servers automatically via the `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id` header.
|
|
123
|
+
|
|
124
|
+
## Infrastructure
|
|
125
|
+
|
|
126
|
+
After running the generator you must grant the agent permission to invoke the Gateway.
|
|
127
|
+
|
|
128
|
+
<Infrastructure>
|
|
129
|
+
<Fragment slot="cdk">
|
|
130
|
+
```ts title="packages/infra/src/stacks/application-stack.ts" {5}
|
|
131
|
+
const gateway = new MyGateway(this, 'MyGateway');
|
|
132
|
+
const myAgent = new MyAgent(this, 'MyAgent');
|
|
133
|
+
|
|
134
|
+
// Grant the agent permissions to invoke the Gateway
|
|
135
|
+
gateway.grantInvokeAccess(myAgent);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The Gateway URL is automatically registered in the `agentcore.gateways.<ClassName>` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> by the generated CDK construct, so the agent can discover it at runtime.
|
|
139
|
+
</Fragment>
|
|
140
|
+
<Fragment slot="terraform">
|
|
141
|
+
```hcl title="packages/infra/src/main.tf" {8-13}
|
|
142
|
+
module "my_gateway" {
|
|
143
|
+
source = "../../common/terraform/src/app/gateways/my-gateway"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module "my_agent" {
|
|
147
|
+
source = "../../common/terraform/src/app/agents/my-agent"
|
|
148
|
+
|
|
149
|
+
# Grant the agent permission to invoke the Gateway
|
|
150
|
+
additional_iam_policy_statements = [{
|
|
151
|
+
Effect = "Allow"
|
|
152
|
+
Action = ["bedrock-agentcore:InvokeGateway"]
|
|
153
|
+
Resource = [module.my_gateway.gateway_arn]
|
|
154
|
+
}]
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The Gateway URL is automatically registered in the `agentcore.gateways.<ClassName>` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> by the generated Terraform module, so the agent can discover it at runtime.
|
|
159
|
+
</Fragment>
|
|
160
|
+
</Infrastructure>
|
|
161
|
+
|
|
162
|
+
## Local Development
|
|
163
|
+
|
|
164
|
+
The generator configures the agent's `dev` target to:
|
|
165
|
+
|
|
166
|
+
1. Start the connected Gateway's local gateway and every attached MCP server
|
|
167
|
+
2. Set `LOCAL_DEV=true` so the generated client points at the local gateway instead of the deployed Gateway
|
|
168
|
+
|
|
169
|
+
Run the agent locally with:
|
|
170
|
+
|
|
171
|
+
<NxCommands commands={["<agent-name>-dev <project-name>"]} />
|
|
172
|
+
|
|
173
|
+
To run the agent locally **against the deployed Gateway** instead (for example, to exercise Cedar policies), use the agent's `serve` target. Without `LOCAL_DEV` set, the client resolves the deployed Gateway URL from runtime configuration and SigV4-signs requests with your local AWS credentials:
|
|
174
|
+
|
|
175
|
+
<NxCommands commands={["<agent-name>-serve <project-name>"]} />
|
|
176
|
+
|
|
177
|
+
### Local fidelity
|
|
178
|
+
|
|
179
|
+
The local gateway stands in for the deployed Gateway, so:
|
|
180
|
+
|
|
181
|
+
- **No Cedar policy evaluation.** Every tool is visible to the agent regardless of policies. Use the `serve` target to exercise policies against the deployed Gateway.
|
|
182
|
+
- **Tool-name prefixing is preserved.** Each local MCP server's tools are exposed as `<target-name>___<tool-name>`, matching what the deployed Gateway emits. This keeps the agent's system prompt and the Cedar action names you reference consistent across local and deployed runs.
|
|
@@ -7,7 +7,7 @@ when:
|
|
|
7
7
|
- ts#mcp-server
|
|
8
8
|
- py#mcp-server
|
|
9
9
|
---
|
|
10
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
10
|
+
import { FileTree, Tabs, TabItem } from '@astrojs/starlight/components';
|
|
11
11
|
import Link from '@components/link.astro';
|
|
12
12
|
import RunGenerator from '@components/run-generator.astro';
|
|
13
13
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
@@ -22,7 +22,7 @@ The generator sets up all the necessary wiring so your agent can discover and in
|
|
|
22
22
|
|
|
23
23
|
Before using this generator, ensure you have:
|
|
24
24
|
|
|
25
|
-
1. A Python project with a <Link path="guides/py-agent">
|
|
25
|
+
1. A Python project with a <Link path="guides/py-agent">Python Agent</Link> component (Strands or LangChain)
|
|
26
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
27
|
3. Both components created with `infra: agentcore`
|
|
28
28
|
|
|
@@ -48,30 +48,37 @@ The generator creates a shared `agent_connection` Python project at `packages/co
|
|
|
48
48
|
- \<scope>\_agent\_connection
|
|
49
49
|
- \_\_init\_\_.py Re-exports per-connection clients
|
|
50
50
|
- core
|
|
51
|
-
- agentcore\
|
|
51
|
+
- agentcore\_endpoints.py Framework-agnostic ARN/URL resolution
|
|
52
|
+
- agentcore\_mcp\_transport.py Framework-agnostic MCP transport
|
|
53
|
+
- agentcore\_mcp\_client\_\<framework>.py MCP client wrapping the transport for your agent's framework
|
|
54
|
+
- auth/ Framework-agnostic SigV4 / session-forwarding `httpx.Auth`
|
|
52
55
|
- app
|
|
53
|
-
- \<mcp\_server\_name>\_client
|
|
56
|
+
- \<mcp\_server\_name>\_client\_\<framework>.py Per-connection client for each MCP server
|
|
54
57
|
|
|
55
58
|
</FileTree>
|
|
56
59
|
|
|
60
|
+
The client suffix matches your agent's framework (`_strands` or `_langchain`).
|
|
61
|
+
|
|
57
62
|
Additionally, the generator:
|
|
58
63
|
- Transforms your agent's `agent.py` to import and use the MCP server's tools via a class-based client
|
|
59
64
|
- Adds the `agent_connection` project as a workspace dependency of your agent project
|
|
60
|
-
- Updates the agent's `
|
|
65
|
+
- Updates the agent's `dev` target to depend on the MCP server's serve target
|
|
61
66
|
|
|
62
67
|
## Using the Connected MCP Server
|
|
63
68
|
|
|
64
69
|
The generator transforms your agent's `agent.py` to use the MCP server's tools:
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
<Tabs syncKey="agent-framework">
|
|
72
|
+
<TabItem label="Strands" _filter={{ framework: 'strands' }}>
|
|
73
|
+
```python title="packages/my-project/my_module/agent/agent.py" {4,8,9-13}
|
|
67
74
|
from contextlib import contextmanager
|
|
68
75
|
from strands import Agent
|
|
69
76
|
|
|
70
|
-
from my_scope_agent_connection import
|
|
77
|
+
from my_scope_agent_connection import MyMcpServerClientStrands
|
|
71
78
|
|
|
72
79
|
@contextmanager
|
|
73
|
-
def get_agent(
|
|
74
|
-
my_mcp_server =
|
|
80
|
+
def get_agent():
|
|
81
|
+
my_mcp_server = MyMcpServerClientStrands.create()
|
|
75
82
|
with (
|
|
76
83
|
my_mcp_server,
|
|
77
84
|
):
|
|
@@ -81,7 +88,29 @@ def get_agent(session_id: str):
|
|
|
81
88
|
)
|
|
82
89
|
```
|
|
83
90
|
|
|
84
|
-
The
|
|
91
|
+
The Strands client is a context manager, entered in a `with` block around the agent.
|
|
92
|
+
</TabItem>
|
|
93
|
+
<TabItem label="LangChain" _filter={{ framework: 'langchain' }}>
|
|
94
|
+
```python title="packages/my-project/my_module/agent/agent.py" {4,7,11}
|
|
95
|
+
from langchain.agents import create_agent
|
|
96
|
+
from langchain_aws import ChatBedrockConverse
|
|
97
|
+
|
|
98
|
+
from my_scope_agent_connection import MyMcpServerClientLangChain
|
|
99
|
+
|
|
100
|
+
def get_agent():
|
|
101
|
+
my_mcp_server = MyMcpServerClientLangChain.create()
|
|
102
|
+
return create_agent(
|
|
103
|
+
model=ChatBedrockConverse(model=MODEL_ID, region_name=REGION),
|
|
104
|
+
system_prompt="...",
|
|
105
|
+
tools=[*my_mcp_server],
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The LangChain client returns a list of tools loaded via [`langchain-mcp-adapters`](https://docs.langchain.com/oss/python/langchain/mcp). Each tool opens a fresh MCP session per call, so the tools stay usable for the agent's lifetime — no `with` block is needed.
|
|
110
|
+
</TabItem>
|
|
111
|
+
</Tabs>
|
|
112
|
+
|
|
113
|
+
The AgentCore session ID is propagated to the MCP server automatically via the `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id` header for both frameworks, ensuring consistency for [Bedrock AgentCore Observability](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability.html).
|
|
85
114
|
|
|
86
115
|
## Infrastructure
|
|
87
116
|
|
|
@@ -102,7 +131,7 @@ The MCP server's AgentCore runtime ARN is automatically registered in the `agent
|
|
|
102
131
|
<Fragment slot="terraform">
|
|
103
132
|
After running the connection generator, you need to grant the agent permission to invoke the MCP server in your Terraform configuration:
|
|
104
133
|
|
|
105
|
-
```hcl title="packages/infra/src/main.tf" {
|
|
134
|
+
```hcl title="packages/infra/src/main.tf" {9-25}
|
|
106
135
|
module "inventory_mcp_server" {
|
|
107
136
|
source = "../../common/terraform/src/app/mcp-servers/inventory-mcp"
|
|
108
137
|
}
|
|
@@ -136,12 +165,12 @@ The MCP server's AgentCore runtime ARN is automatically registered in the `agent
|
|
|
136
165
|
|
|
137
166
|
## Local Development
|
|
138
167
|
|
|
139
|
-
The generator configures the agent's `
|
|
168
|
+
The generator configures the agent's `dev` target to:
|
|
140
169
|
1. Start the connected MCP server(s) automatically
|
|
141
|
-
2. Set `
|
|
170
|
+
2. Set `LOCAL_DEV=true` so the generated client uses direct HTTP transport instead of AgentCore
|
|
142
171
|
|
|
143
172
|
Run the agent locally with:
|
|
144
173
|
|
|
145
|
-
<NxCommands commands={["<agent-name>-
|
|
174
|
+
<NxCommands commands={["<agent-name>-dev <project-name>"]} />
|
|
146
175
|
|
|
147
176
|
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,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Python Agent to Relational Database
|
|
3
|
+
description: Connect a Python Agent to a Relational Database
|
|
4
|
+
when:
|
|
5
|
+
sourceType: py#agent
|
|
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-agent">Python Agent</Link> to a <Link path="guides/py-rdb">Python Relational Database</Link> project, making the database session available inside your agent tools.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A <Link path="guides/py-agent">`py#agent`</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 Agent project as the source and your relational database project as the target. If the project contains multiple agent 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_agent-dev` on the database's `dev` target
|
|
42
|
+
- pyproject.toml Adds the database package as a workspace dependency
|
|
43
|
+
- my\_service
|
|
44
|
+
- my\_agent
|
|
45
|
+
- Dockerfile Adds the RDS CA bundle used for direct Aurora connections
|
|
46
|
+
|
|
47
|
+
</FileTree>
|
|
48
|
+
|
|
49
|
+
## Using the Database in Agent Tools
|
|
50
|
+
|
|
51
|
+
Import `session_context` from your database package and use it inside your agent tools:
|
|
52
|
+
|
|
53
|
+
```python title="packages/my_service/my_service/my_agent/agent.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
|
+
from strands import tool
|
|
58
|
+
|
|
59
|
+
@tool
|
|
60
|
+
async def list_examples() -> list:
|
|
61
|
+
"""List all example records."""
|
|
62
|
+
async with session_context() as session:
|
|
63
|
+
return [item.model_dump() for item in (await session.execute(select(ExampleModel))).all()]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Infrastructure
|
|
67
|
+
|
|
68
|
+
The generated agent construct implements `IGrantable` and `IConnectable`, so you can grant network and IAM access to the database directly on the construct.
|
|
69
|
+
|
|
70
|
+
<Infrastructure>
|
|
71
|
+
<Fragment slot="cdk">
|
|
72
|
+
|
|
73
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
74
|
+
import { SecurityGroup } from 'aws-cdk-lib/aws-ec2';
|
|
75
|
+
import { RuntimeNetworkConfiguration } from 'aws-cdk-lib/aws-bedrockagentcore';
|
|
76
|
+
import { MyDatabase } from '@my-scope/common-constructs';
|
|
77
|
+
|
|
78
|
+
const db = new MyDatabase(this, 'Db', { vpc, ... });
|
|
79
|
+
|
|
80
|
+
const myAgent = new MyAgent(this, 'MyAgent', {
|
|
81
|
+
networkConfiguration: RuntimeNetworkConfiguration.usingVpc(this, {
|
|
82
|
+
vpc,
|
|
83
|
+
vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS },
|
|
84
|
+
securityGroups: [
|
|
85
|
+
new SecurityGroup(this, 'MyAgentSecurityGroup', { vpc, allowAllOutbound: true }),
|
|
86
|
+
],
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
db.allowDefaultPortFrom(myAgent);
|
|
91
|
+
db.grantConnect(myAgent);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`allowDefaultPortFrom` opens the security group rule so the agent runtime can reach the database port. `grantConnect` grants IAM `rds-db:connect` permission to the agent's execution role.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
</Fragment>
|
|
98
|
+
<Fragment slot="terraform">
|
|
99
|
+
|
|
100
|
+
Run the agent 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:
|
|
101
|
+
|
|
102
|
+
```hcl title="packages/infra/src/main.tf"
|
|
103
|
+
module "my_database" {
|
|
104
|
+
source = "../../common/terraform/src/app/dbs/my-database"
|
|
105
|
+
vpc_id = aws_vpc.main.id
|
|
106
|
+
database_subnet_ids = aws_subnet.database[*].id
|
|
107
|
+
lambda_subnet_ids = aws_subnet.private[*].id
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module "my_agent" {
|
|
111
|
+
source = "../../common/terraform/src/app/agents/my-agent"
|
|
112
|
+
enable_vpc = true
|
|
113
|
+
vpc_id = aws_vpc.main.id
|
|
114
|
+
subnet_ids = aws_subnet.private[*].id
|
|
115
|
+
|
|
116
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
117
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
118
|
+
|
|
119
|
+
additional_iam_policy_statements = [
|
|
120
|
+
{
|
|
121
|
+
Effect = "Allow"
|
|
122
|
+
Action = ["rds-db:connect"]
|
|
123
|
+
Resource = [
|
|
124
|
+
"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}"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
resource "aws_vpc_security_group_ingress_rule" "agent_to_database" {
|
|
131
|
+
description = "Allow the agent runtime to connect to the database"
|
|
132
|
+
security_group_id = module.my_database.security_group_id
|
|
133
|
+
referenced_security_group_id = module.my_agent.security_group_id
|
|
134
|
+
from_port = module.my_database.cluster_port
|
|
135
|
+
to_port = module.my_database.cluster_port
|
|
136
|
+
ip_protocol = "tcp"
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resource "aws_vpc_security_group_egress_rule" "agent_to_database" {
|
|
140
|
+
description = "Allow outbound traffic from the agent runtime to the database"
|
|
141
|
+
security_group_id = module.my_agent.security_group_id
|
|
142
|
+
referenced_security_group_id = module.my_database.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
|
+
|
|
149
|
+
`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. That application exposes the `database` namespace by default, so the database module's runtime configuration entry is deployed without further configuration.
|
|
150
|
+
|
|
151
|
+
</Fragment>
|
|
152
|
+
</Infrastructure>
|
|
153
|
+
|
|
154
|
+
### SSL Requirements When Connecting Without RDS Proxy
|
|
155
|
+
|
|
156
|
+
When the agent connects directly to the Aurora cluster (without RDS Proxy), the connection generator updates the generated agent Dockerfile to install the Amazon RDS CA bundle into the system trust store:
|
|
157
|
+
|
|
158
|
+
```dockerfile
|
|
159
|
+
ADD https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /usr/local/share/ca-certificates/rds-global-bundle.crt
|
|
160
|
+
RUN update-ca-certificates
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
When using RDS Proxy, you do not need to configure the RDS CA bundle in the agent runtime.
|
|
164
|
+
|
|
165
|
+
## Local Development
|
|
166
|
+
|
|
167
|
+
<NxCommands commands={["<agent-name>-dev <project-name>"]} />
|
|
168
|
+
|
|
169
|
+
This starts the agent 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,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: FastAPI to DynamoDB
|
|
3
|
+
description: Connect a FastAPI to a Python DynamoDB project
|
|
4
|
+
when:
|
|
5
|
+
sourceType: py#fast-api
|
|
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 Snippet from '@components/snippet.astro';
|
|
12
|
+
|
|
13
|
+
The `connection` generator wires a <Link path="guides/fastapi">FastAPI</Link> to a <Link path="guides/py-dynamodb">Python DynamoDB</Link> project, configuring local development so both start together automatically.
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
Before using this generator, ensure you have:
|
|
18
|
+
|
|
19
|
+
1. A FastAPI project (generated with `py#api --framework=fastapi`), see the <Link path="guides/fastapi">`py#api`</Link> guide
|
|
20
|
+
2. A <Link path="guides/py-dynamodb">`py#dynamodb`</Link> project
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Run the Generator
|
|
25
|
+
|
|
26
|
+
<RunGenerator generator="connection" />
|
|
27
|
+
|
|
28
|
+
Select your FastAPI project as the source and your DynamoDB project as the target.
|
|
29
|
+
|
|
30
|
+
### Options
|
|
31
|
+
|
|
32
|
+
<GeneratorParameters generator="connection" />
|
|
33
|
+
|
|
34
|
+
## Generator Output
|
|
35
|
+
|
|
36
|
+
The generator updates the FastAPI's `project.json` to add a dependency from its `dev` target to the DynamoDB project's `dev` target, and adds the DynamoDB package as a workspace dependency. No source files are modified.
|
|
37
|
+
|
|
38
|
+
## Using DynamoDB in Route Handlers
|
|
39
|
+
|
|
40
|
+
Import entity classes from the DynamoDB package and use them inside your route handlers:
|
|
41
|
+
|
|
42
|
+
```python title="packages/my_api/my_api/api.py"
|
|
43
|
+
from my_scope.my_table.entities.example import ExampleModel
|
|
44
|
+
|
|
45
|
+
@app.get("/examples")
|
|
46
|
+
def list_examples():
|
|
47
|
+
return list(ExampleModel.scan())
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Infrastructure
|
|
51
|
+
|
|
52
|
+
<Snippet name="connection/lambda-dynamodb-access" />
|
|
53
|
+
|
|
54
|
+
## Local Development
|
|
55
|
+
|
|
56
|
+
<Snippet name="connection/py-dynamodb-local-development" />
|