@aws/nx-plugin-mcp 0.120.0 → 0.121.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aws-nx-mcp.js +23 -35
- package/docs/guides/astro-docs.mdx +142 -0
- package/docs/guides/connection/py-agent-a2a.mdx +105 -0
- package/docs/guides/connection/py-agent-mcp.mdx +147 -0
- package/docs/guides/connection/react-agui.mdx +240 -0
- package/docs/guides/connection/react-fastapi.mdx +1476 -0
- package/docs/guides/connection/react-py-agent.mdx +198 -0
- package/docs/guides/connection/react-smithy.mdx +1355 -0
- package/docs/guides/connection/react-trpc.mdx +447 -0
- package/docs/guides/connection/react-ts-agent.mdx +198 -0
- package/docs/guides/connection/smithy-rdb.mdx +161 -0
- package/docs/guides/connection/trpc-rdb.mdx +127 -0
- package/docs/guides/connection/ts-agent-a2a.mdx +106 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +144 -0
- package/docs/guides/connection/ts-agent-rdb.mdx +141 -0
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +135 -0
- package/docs/guides/connection.mdx +126 -0
- package/docs/guides/docker-bundling.mdx +403 -0
- package/docs/guides/fastapi.mdx +509 -0
- package/docs/guides/license.mdx +293 -0
- package/docs/guides/nx-generator.mdx +588 -0
- package/docs/guides/py-agent.mdx +483 -0
- package/docs/guides/py-mcp-server.mdx +161 -0
- package/docs/guides/python-lambda-function.mdx +207 -0
- package/docs/guides/python-project.mdx +228 -0
- package/docs/guides/react-website-auth.mdx +216 -0
- package/docs/guides/react-website.mdx +421 -0
- package/docs/guides/runtime-config.mdx +312 -0
- package/docs/guides/terraform-project.mdx +317 -0
- package/docs/guides/trpc.mdx +816 -0
- package/docs/guides/ts-agent.mdx +436 -0
- package/docs/guides/ts-lambda-function.mdx +218 -0
- package/docs/guides/ts-mcp-server.mdx +169 -0
- package/docs/guides/ts-nx-plugin.mdx +159 -0
- package/docs/guides/ts-rdb.mdx +759 -0
- package/docs/guides/ts-smithy-api.mdx +661 -0
- package/docs/guides/typescript-infrastructure.mdx +408 -0
- package/docs/guides/typescript-project.mdx +312 -0
- package/docs/guides/workspace.mdx +181 -0
- package/docs/snippets/agent/architecture.mdx +72 -0
- package/docs/snippets/agent/bedrock-deployment.mdx +172 -0
- package/docs/snippets/agent/runtime-arn.mdx +64 -0
- package/docs/snippets/api/api-architecture.mdx +93 -0
- package/docs/snippets/api/api-choice-note.mdx +6 -0
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +25 -0
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +28 -0
- package/docs/snippets/api/shared-constructs.mdx +38 -0
- package/docs/snippets/api/type-safe-api-integrations.mdx +643 -0
- package/docs/snippets/api/waf-configuration.mdx +37 -0
- package/docs/snippets/connection/a2a-infrastructure.mdx +63 -0
- package/docs/snippets/connection/lambda-rdb-ssl-requirements.mdx +40 -0
- package/docs/snippets/connection/mcp-server-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +72 -0
- package/docs/snippets/connection/react-agent-infrastructure.mdx +61 -0
- package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/lambda-function/architecture.mdx +36 -0
- package/docs/snippets/lambda-function/deploying-your-function.mdx +118 -0
- package/docs/snippets/mcp/architecture.mdx +58 -0
- package/docs/snippets/mcp/assistant-docs.mdx +10 -0
- package/docs/snippets/mcp/bedrock-deployment.mdx +167 -0
- package/docs/snippets/mcp/config.mdx +13 -0
- package/docs/snippets/mcp/configuration-py.mdx +42 -0
- package/docs/snippets/mcp/configuration-ts.mdx +53 -0
- package/docs/snippets/mcp/observability.mdx +8 -0
- package/docs/snippets/mcp/shared-constructs.mdx +32 -0
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +602 -0
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +915 -0
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +161 -0
- package/docs/snippets/pdk-migration/example/04-deploy.mdx +229 -0
- package/docs/snippets/pdk-migration/faq/aws-arch.mdx +17 -0
- package/docs/snippets/pdk-migration/faq/cdk-graph.mdx +29 -0
- package/docs/snippets/pdk-migration/faq/infrastructure-python-java.mdx +19 -0
- package/docs/snippets/pdk-migration/faq/pdk-nag.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/pipeline.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +310 -0
- package/docs/snippets/pdk-migration/faq/use-of-projen.mdx +15 -0
- package/docs/snippets/prerequisites.mdx +20 -0
- package/docs/snippets/required-prerequisites.mdx +12 -0
- package/docs/snippets/shared-constructs.mdx +40 -0
- package/docs/snippets/tools/acurl.mdx +73 -0
- package/docs/snippets/ts-bundle.mdx +14 -0
- package/package.json +1 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: React to Python Agent
|
|
3
|
+
description: Connect a React website to a Python Agent
|
|
4
|
+
when:
|
|
5
|
+
sourceType: react
|
|
6
|
+
targetType: py#agent
|
|
7
|
+
protocol: HTTP
|
|
8
|
+
---
|
|
9
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
10
|
+
import Link from '@components/link.astro';
|
|
11
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
14
|
+
import Snippet from '@components/snippet.astro';
|
|
15
|
+
|
|
16
|
+
Nx Plugin for AWS provides a generator to quickly integrate your <Link path="guides/py-agent">Python Agent</Link> with a React website. It sets up all necessary configuration for connecting to your agent via a type-safe OpenAPI-generated client, including AWS IAM and Cognito authentication support.
|
|
17
|
+
|
|
18
|
+
:::tip[AG-UI agents]
|
|
19
|
+
If your Python Agent was generated with `protocol=AG-UI`, the connection generator instead wires up [CopilotKit](https://docs.copilotkit.ai/aws-strands) and an [`@ag-ui/client`](https://docs.ag-ui.com/) `HttpAgent` on the React website. See the <Link path="guides/connection/react-agui">React to AG-UI Agent</Link> guide for details.
|
|
20
|
+
:::
|
|
21
|
+
|
|
22
|
+
## Prerequisites
|
|
23
|
+
|
|
24
|
+
Before using this generator, ensure you have:
|
|
25
|
+
|
|
26
|
+
1. A React website (generated using the <Link path="guides/react-website">`ts#react-website` generator</Link>)
|
|
27
|
+
2. A Python Agent with `protocol=HTTP` (generated using the <Link path="guides/py-agent">`py#agent` generator</Link>)
|
|
28
|
+
3. Cognito Auth added via the <Link path="/guides/react-website-auth">`ts#react-website-auth` generator</Link>
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Run the Generator
|
|
33
|
+
|
|
34
|
+
<RunGenerator generator="connection" />
|
|
35
|
+
|
|
36
|
+
You will be prompted to select your React website as the source project and the project containing your Python Agent as the target project. If your target project contains multiple components (such as multiple agents or other component types), you will be prompted to specify a `targetComponent` to disambiguate.
|
|
37
|
+
|
|
38
|
+
### Options
|
|
39
|
+
|
|
40
|
+
<GeneratorParameters generator="connection" />
|
|
41
|
+
|
|
42
|
+
## Generator Output
|
|
43
|
+
|
|
44
|
+
The generator creates the following in your Python Agent project:
|
|
45
|
+
|
|
46
|
+
<FileTree>
|
|
47
|
+
|
|
48
|
+
- scripts
|
|
49
|
+
- \<agent_name>_openapi.py Script to generate an OpenAPI specification from the agent's FastAPI app
|
|
50
|
+
- project.json A new `<agent-name>-openapi` target is added
|
|
51
|
+
|
|
52
|
+
</FileTree>
|
|
53
|
+
|
|
54
|
+
The generator creates the following structure in your React application:
|
|
55
|
+
|
|
56
|
+
<FileTree>
|
|
57
|
+
|
|
58
|
+
- src
|
|
59
|
+
- components
|
|
60
|
+
- \<AgentName>Provider.tsx Provider for the OpenAPI client
|
|
61
|
+
- QueryClientProvider.tsx TanStack React Query client provider
|
|
62
|
+
- hooks
|
|
63
|
+
- useSigV4.tsx Hook for signing requests with SigV4 (IAM only)
|
|
64
|
+
- use\<AgentName>.tsx Hook returning the TanStack Query options proxy for your agent's API
|
|
65
|
+
- use\<AgentName>Client.tsx Hook returning the vanilla API client
|
|
66
|
+
- generated
|
|
67
|
+
- \<agent-name>
|
|
68
|
+
- types.gen.ts Generated types from the agent's Pydantic models
|
|
69
|
+
- client.gen.ts Type-safe client for calling your agent's API
|
|
70
|
+
- options-proxy.gen.ts TanStack Query hooks options for interacting with your agent
|
|
71
|
+
- project.json Targets added for client generation and watching for changes
|
|
72
|
+
- .gitignore The generated client files are ignored by default
|
|
73
|
+
|
|
74
|
+
</FileTree>
|
|
75
|
+
|
|
76
|
+
## How It Works
|
|
77
|
+
|
|
78
|
+
### OpenAPI Client Generation
|
|
79
|
+
|
|
80
|
+
At build time, the Python Agent's FastAPI app is introspected to generate an OpenAPI specification. This spec is then used to generate a type-safe TypeScript client with TanStack Query hooks, following the same pattern as the <Link path="guides/connection/react-fastapi">React to FastAPI connection</Link>.
|
|
81
|
+
|
|
82
|
+
Each agent gets its own scoped OpenAPI script (e.g., `scripts/agent_openapi.py`) so that projects with multiple agents can generate individual specs.
|
|
83
|
+
|
|
84
|
+
### Runtime Configuration
|
|
85
|
+
|
|
86
|
+
Running this connection generator also patches the agent's generated CDK/Terraform construct to publish its AgentCore runtime ARN to the website's `runtime-config.json` (under the `connection` namespace), so only agents you explicitly connect are exposed to the frontend. See <Link path="guides/runtime-config">Runtime Configuration</Link> for details.
|
|
87
|
+
|
|
88
|
+
### Authentication
|
|
89
|
+
|
|
90
|
+
The generated code handles authentication depending on your agent's configuration:
|
|
91
|
+
|
|
92
|
+
- **IAM** (default): Uses AWS SigV4 to sign HTTP requests. Credentials are obtained from the Cognito Identity Pool configured with your website's auth
|
|
93
|
+
- **Cognito**: Embeds the JWT access token in an Authorization header
|
|
94
|
+
- **None**: No authentication
|
|
95
|
+
|
|
96
|
+
## Infrastructure
|
|
97
|
+
|
|
98
|
+
<Snippet name="connection/react-agent-infrastructure" parentHeading="Infrastructure" />
|
|
99
|
+
|
|
100
|
+
## Using the Generated Code
|
|
101
|
+
|
|
102
|
+
### Using the API Hook
|
|
103
|
+
|
|
104
|
+
The `use<AgentName>` hook provides TanStack Query options for calling your agent's API endpoints:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { useState } from 'react';
|
|
108
|
+
import { useMutation } from '@tanstack/react-query';
|
|
109
|
+
import { useMyAgent } from '../hooks/useMyAgent';
|
|
110
|
+
import type { StreamChunk } from '../generated/my-agent/types.gen';
|
|
111
|
+
|
|
112
|
+
function ChatComponent() {
|
|
113
|
+
const api = useMyAgent();
|
|
114
|
+
const [chunks, setChunks] = useState<StreamChunk[]>([]);
|
|
115
|
+
|
|
116
|
+
const invoke = useMutation(api.invoke.mutationOptions({
|
|
117
|
+
onSuccess: async (stream) => {
|
|
118
|
+
setChunks([]);
|
|
119
|
+
for await (const chunk of stream) {
|
|
120
|
+
setChunks((prev) => [...prev, chunk]);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
const handleSend = (message: string) => {
|
|
126
|
+
invoke.mutate({
|
|
127
|
+
prompt: message,
|
|
128
|
+
sessionId: 'my-session',
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div>
|
|
134
|
+
<button onClick={() => handleSend('Hello!')}>Send</button>
|
|
135
|
+
{invoke.isPending && <p>Agent is thinking...</p>}
|
|
136
|
+
{chunks.map((chunk, i) => (
|
|
137
|
+
<span key={i}>{chunk.content}</span>
|
|
138
|
+
))}
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Using the Vanilla Client
|
|
145
|
+
|
|
146
|
+
The `use<AgentName>Client` hook provides direct access to the API client:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { useState } from 'react';
|
|
150
|
+
import { useMyAgentClient } from '../hooks/useMyAgentClient';
|
|
151
|
+
import type { StreamChunk } from '../generated/my-agent/types.gen';
|
|
152
|
+
|
|
153
|
+
function ChatComponent() {
|
|
154
|
+
const client = useMyAgentClient();
|
|
155
|
+
const [chunks, setChunks] = useState<StreamChunk[]>([]);
|
|
156
|
+
|
|
157
|
+
const handleSend = async (message: string) => {
|
|
158
|
+
setChunks([]);
|
|
159
|
+
for await (const chunk of client.invoke({
|
|
160
|
+
prompt: message,
|
|
161
|
+
sessionId: 'my-session',
|
|
162
|
+
})) {
|
|
163
|
+
setChunks((prev) => [...prev, chunk]);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div>
|
|
169
|
+
<button onClick={() => handleSend('Hello!')}>Send</button>
|
|
170
|
+
{chunks.map((chunk, i) => (
|
|
171
|
+
<span key={i}>{chunk.content}</span>
|
|
172
|
+
))}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Local Development
|
|
179
|
+
|
|
180
|
+
The connection generator automatically configures `serve-local` integration:
|
|
181
|
+
|
|
182
|
+
1. Running `nx serve-local <website>` will also start the agent's local FastAPI server
|
|
183
|
+
2. The runtime config is overridden to point to the local HTTP URL (e.g., `http://localhost:8081/`)
|
|
184
|
+
3. The TypeScript client is automatically regenerated when the agent's API changes
|
|
185
|
+
|
|
186
|
+
<NxCommands commands={['serve-local <WebsiteProject>']} />
|
|
187
|
+
|
|
188
|
+
:::tip[Hot Reloading]
|
|
189
|
+
The website and connected agent will hot-reload, enabling you to quickly iterate on both together without deploying to AWS.
|
|
190
|
+
:::
|
|
191
|
+
|
|
192
|
+
## More Information
|
|
193
|
+
|
|
194
|
+
For more information, please refer to:
|
|
195
|
+
|
|
196
|
+
- <Link path="guides/py-agent">Python Agent Guide</Link>
|
|
197
|
+
- <Link path="guides/connection/react-fastapi">React to FastAPI Connection Guide</Link>
|
|
198
|
+
- [TanStack Query Documentation](https://tanstack.com/query/v5)
|