@aws/nx-plugin 1.0.0-rc.17 → 1.0.0-rc.19
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/generators.json +9 -1
- package/package.json +1 -1
- package/src/agentcore-gateway/attach-upstream.d.ts +33 -0
- package/src/agentcore-gateway/attach-upstream.js +41 -0
- package/src/agentcore-gateway/attach-upstream.js.map +1 -0
- package/src/agentcore-gateway/files/project/serve-local.ts.template +3 -2
- package/src/agentcore-gateway/gateway-connection/generator.d.ts +21 -0
- package/src/agentcore-gateway/gateway-connection/generator.js +102 -0
- package/src/agentcore-gateway/gateway-connection/generator.js.map +1 -0
- package/src/agentcore-gateway/gateway-connection/schema.d.ts +12 -0
- package/src/agentcore-gateway/gateway-connection/schema.json +26 -0
- package/src/agentcore-gateway/mcp-connection/generator.js +8 -24
- package/src/agentcore-gateway/mcp-connection/generator.js.map +1 -1
- package/src/connection/generator.js +66 -63
- package/src/connection/generator.js.map +1 -1
- package/src/license/generator.js +8 -19
- package/src/license/generator.js.map +1 -1
- package/src/license/known-exceptions.d.ts +0 -1
- package/src/license/known-exceptions.js +1 -8
- package/src/license/known-exceptions.js.map +1 -1
- package/src/py/agent/__snapshots__/generator.spec.ts.snap +15 -6
- package/src/py/agent/a2a-connection/__snapshots__/generator.spec.ts.snap +201 -0
- package/src/py/agent/a2a-connection/files/agent-connection/app/{__targetAgentSnakeCase___client.py.template → __targetAgentSnakeCase___client_strands.py.template} +7 -5
- package/src/py/agent/a2a-connection/generator.js +6 -5
- package/src/py/agent/a2a-connection/generator.js.map +1 -1
- package/src/py/agent/files/http/main.py.template +2 -2
- package/src/py/agent/gateway-connection/__snapshots__/generator.spec.ts.snap +197 -0
- package/src/py/agent/gateway-connection/files/agent-connection/app/{__gatewaySnakeCase___client.py.template → __gatewaySnakeCase___client_strands.py.template} +6 -6
- package/src/py/agent/gateway-connection/generator.js +5 -5
- package/src/py/agent/gateway-connection/generator.js.map +1 -1
- package/src/py/agent/generator.js +3 -5
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/agent/mcp-connection/__snapshots__/generator.spec.ts.snap +157 -79
- package/src/py/agent/mcp-connection/files/agent-connection/app/{__mcpServerSnakeCase___client.py.template → __mcpServerSnakeCase___client_strands.py.template} +7 -5
- package/src/py/agent/mcp-connection/generator.js +5 -5
- package/src/py/agent/mcp-connection/generator.js.map +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +37 -3
- package/src/py/fast-api/files/app/__name__/main.py.template +4 -1
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +13 -4
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/smithy/project/files/src/operations/echo.smithy.template +1 -0
- package/src/terraform/project/files/application/src/main.tf.template +6 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +35 -4
- package/src/trpc/backend/files/src/procedures/echo.ts.template +1 -1
- package/src/trpc/backend/files/src/schema/echo.ts.template +2 -2
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +14 -5
- package/src/ts/agent/a2a-connection/__snapshots__/generator.spec.ts.snap +256 -0
- package/src/ts/agent/a2a-connection/files/agent-connection/app/{__targetAgentKebabCase__-client.ts.template → __targetAgentKebabCase__-client-strands.ts.template} +5 -5
- package/src/ts/agent/a2a-connection/generator.js +3 -3
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/http/router.ts.template +1 -1
- package/src/ts/agent/gateway-connection/__snapshots__/generator.spec.ts.snap +220 -0
- package/src/ts/agent/gateway-connection/files/agent-connection/app/{__gatewayKebabCase__-client.ts.template → __gatewayKebabCase__-client-strands.ts.template} +5 -5
- package/src/ts/agent/gateway-connection/generator.js +3 -3
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +3 -0
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/__snapshots__/generator.spec.ts.snap +183 -110
- package/src/ts/agent/mcp-connection/files/agent-connection/app/{__mcpServerKebabCase__-client.ts.template → __mcpServerKebabCase__-client-strands.ts.template} +5 -5
- package/src/ts/agent/mcp-connection/generator.js +3 -3
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +13 -4
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +64 -24
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +13 -4
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +9 -3
- package/src/utils/agent-connection/agent-connection.d.ts +50 -24
- package/src/utils/agent-connection/agent-connection.js +137 -45
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +93 -0
- package/src/utils/agent-connection/files/core-auth/agentcore-endpoints.ts.template +37 -0
- package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +54 -0
- package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +41 -0
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +70 -0
- package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +39 -0
- package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +61 -0
- package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +26 -0
- package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +27 -0
- package/src/utils/agent-connection/files/py-core-a2a/agentcore_a2a_client_config.py.template +43 -0
- package/src/utils/agent-connection/files/py-core-auth/agentcore_endpoints.py.template +47 -0
- package/src/utils/agent-connection/files/py-core-auth/auth/session.py.template +51 -0
- package/src/utils/agent-connection/files/py-core-gateway/agentcore_gateway_mcp_transport.py.template +28 -0
- package/src/utils/agent-connection/files/py-core-mcp/agentcore_mcp_transport.py.template +34 -0
- package/src/utils/agent-connection/files/py-core-shared/agentcore_transport.py.template +40 -0
- package/src/utils/agent-connection/files/py-core-strands/a2a/agentcore_a2a_client_strands.py.template +66 -0
- package/src/utils/agent-connection/files/py-core-strands/gateway/agentcore_gateway_mcp_client_strands.py.template +22 -0
- package/src/utils/agent-connection/files/py-core-strands/mcp/agentcore_mcp_client_strands.py.template +30 -0
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +3 -0
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +110 -28
- package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +95 -2
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +13 -4
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +9 -0
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +23 -1
- package/src/utils/files/terraform/src/core/runtime-config/appconfig-deployment/appconfig-deployment.tf.template +9 -3
- package/src/utils/files/terraform/src/core/runtime-config/read/read.tf.template +7 -2
- package/src/utils/identity-constructs/files/terraform/core/user-identity/add-callback-url/add-callback-url.tf.template +9 -3
- package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +22 -8
- package/src/utils/rdb-constructs/files/terraform/core/rdb/aurora/aurora.tf.template +10 -4
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +13 -4
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client.ts.template +0 -123
- package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-client.ts.template +0 -78
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-client.ts.template +0 -128
- package/src/utils/agent-connection/files/py-core-a2a/agentcore_a2a_client.py.template +0 -120
- package/src/utils/agent-connection/files/py-core-gateway/agentcore_gateway_mcp_client.py.template +0 -78
- package/src/utils/agent-connection/files/py-core-mcp/agentcore_mcp_client.py.template +0 -89
- /package/src/utils/agent-connection/files/{core-runtime-config/model-errors.ts.template → core-strands/base/model-errors-strands.ts.template} +0 -0
- /package/src/utils/agent-connection/files/{core-runtime-config/with-session-id.ts.template → core-strands/base/with-session-id-strands.ts.template} +0 -0
- /package/src/utils/agent-connection/files/{py-core-runtime-config/model_errors.py.template → py-core-strands/base/model_errors_strands.py.template} +0 -0
- /package/src/utils/agent-connection/files/{py-core-runtime-config/with_session_id.py.template → py-core-strands/base/with_session_id_strands.py.template} +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`py#agent#gateway-connection generator > should match snapshot for agent-connection core files > agentcore_gateway_mcp_client_strands.py 1`] = `
|
|
4
|
+
"from strands.tools.mcp.mcp_client import MCPClient
|
|
5
|
+
|
|
6
|
+
from .agentcore_gateway_mcp_transport import AgentCoreGatewayMCPTransport
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AgentCoreGatewayMCPClientStrands:
|
|
10
|
+
"""Factory for Strands MCP clients that connect to an AgentCore Gateway."""
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def with_iam_auth(
|
|
14
|
+
gateway_url: str,
|
|
15
|
+
region: str | None = None,
|
|
16
|
+
) -> MCPClient:
|
|
17
|
+
"""Create a gateway MCP client authenticated with IAM SigV4."""
|
|
18
|
+
return MCPClient(
|
|
19
|
+
AgentCoreGatewayMCPTransport.with_iam_auth(gateway_url, region)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def without_auth(gateway_url: str) -> MCPClient:
|
|
24
|
+
"""Plain-HTTP gateway client, for the local gateway started by serve-local."""
|
|
25
|
+
return MCPClient(AgentCoreGatewayMCPTransport.without_auth(gateway_url))
|
|
26
|
+
"
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`py#agent#gateway-connection generator > should match snapshot for agent-connection core files > agentcore_gateway_mcp_transport.py 1`] = `
|
|
30
|
+
"from .agentcore_endpoints import region_from_gateway_url
|
|
31
|
+
from .agentcore_transport import (
|
|
32
|
+
TransportFactory,
|
|
33
|
+
no_auth_transport,
|
|
34
|
+
sigv4_transport,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class AgentCoreGatewayMCPTransport:
|
|
39
|
+
"""Factory for MCP transport factories that connect to an AgentCore Gateway.
|
|
40
|
+
Forwards the current async-context session via the AgentCore session header,
|
|
41
|
+
which the gateway propagates to downstream MCP server targets.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def with_iam_auth(
|
|
46
|
+
gateway_url: str,
|
|
47
|
+
region: str | None = None,
|
|
48
|
+
) -> TransportFactory:
|
|
49
|
+
"""Create a gateway MCP transport authenticated with IAM SigV4."""
|
|
50
|
+
return sigv4_transport(
|
|
51
|
+
gateway_url, region or region_from_gateway_url(gateway_url)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def without_auth(gateway_url: str) -> TransportFactory:
|
|
56
|
+
"""Plain-HTTP gateway transport, for the local gateway started by serve-local."""
|
|
57
|
+
return no_auth_transport(gateway_url)
|
|
58
|
+
"
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
exports[`py#agent#gateway-connection generator > should match snapshot for agent-connection core files > agentcore_transport.py 1`] = `
|
|
62
|
+
"from collections.abc import Callable
|
|
63
|
+
from typing import Any
|
|
64
|
+
|
|
65
|
+
import boto3
|
|
66
|
+
|
|
67
|
+
from mcp.client.streamable_http import streamablehttp_client
|
|
68
|
+
|
|
69
|
+
from .auth.session import jwt_auth, plain_auth, sigv4_auth
|
|
70
|
+
|
|
71
|
+
# Agent frameworks wrap a transport *factory* — a no-arg callable returning a
|
|
72
|
+
# streamable-HTTP transport context manager. Typed as \`\`Any\`\` so this layer
|
|
73
|
+
# stays free of any framework-specific transport type.
|
|
74
|
+
TransportFactory = Callable[[], Any]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _factory(url: str, auth) -> TransportFactory:
|
|
78
|
+
return lambda: streamablehttp_client(
|
|
79
|
+
url,
|
|
80
|
+
auth=auth,
|
|
81
|
+
timeout=120,
|
|
82
|
+
terminate_on_close=False,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def sigv4_transport(url: str, region: str) -> TransportFactory:
|
|
87
|
+
"""SigV4-signed transport factory for a resolved AgentCore endpoint."""
|
|
88
|
+
credentials = boto3.Session(region_name=region).get_credentials()
|
|
89
|
+
return _factory(url, sigv4_auth(credentials, region))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def jwt_transport(
|
|
93
|
+
url: str, access_token_provider: Callable[[], str]
|
|
94
|
+
) -> TransportFactory:
|
|
95
|
+
"""Bearer-token transport factory for a resolved AgentCore endpoint."""
|
|
96
|
+
return _factory(url, jwt_auth(access_token_provider))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def no_auth_transport(url: str) -> TransportFactory:
|
|
100
|
+
"""Plain-HTTP transport factory — for local dev."""
|
|
101
|
+
return _factory(url, plain_auth())
|
|
102
|
+
"
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
exports[`py#agent#gateway-connection generator > should match snapshot for agent-connection core files > my_gateway_client_strands.py 1`] = `
|
|
106
|
+
"import os
|
|
107
|
+
|
|
108
|
+
from strands.tools.mcp.mcp_client import MCPClient
|
|
109
|
+
|
|
110
|
+
from proj_agent_connection.core.agentcore_gateway_mcp_client_strands import (
|
|
111
|
+
AgentCoreGatewayMCPClientStrands,
|
|
112
|
+
)
|
|
113
|
+
from proj_agent_connection.core.runtime_config import (
|
|
114
|
+
get_agentcore_runtime_config,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class MyGatewayClientStrands:
|
|
119
|
+
"""Strands client for the MyGateway AgentCore Gateway.
|
|
120
|
+
|
|
121
|
+
Deployed: a SigV4-signed MCP client pointing at the gateway URL.
|
|
122
|
+
Local (\`\`SERVE_LOCAL=true\`\`): a plain-HTTP client pointing at the local
|
|
123
|
+
gateway started by the gateway project's serve-local target. The local
|
|
124
|
+
gateway aggregates every attached MCP server but does not evaluate
|
|
125
|
+
Cedar policies.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
@staticmethod
|
|
129
|
+
def create() -> MCPClient:
|
|
130
|
+
if os.environ.get("SERVE_LOCAL") == "true":
|
|
131
|
+
return AgentCoreGatewayMCPClientStrands.without_auth(
|
|
132
|
+
gateway_url="http://localhost:8100/mcp"
|
|
133
|
+
)
|
|
134
|
+
config = get_agentcore_runtime_config()
|
|
135
|
+
gateway_url = config.get("gateways", {}).get("MyGateway")
|
|
136
|
+
if not gateway_url:
|
|
137
|
+
raise RuntimeError(
|
|
138
|
+
"No connected gateway named 'MyGateway' found in runtime configuration."
|
|
139
|
+
)
|
|
140
|
+
return AgentCoreGatewayMCPClientStrands.with_iam_auth(gateway_url=gateway_url)
|
|
141
|
+
"
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
exports[`py#agent#gateway-connection generator > should match snapshot for agent-connection core files > session.py 1`] = `
|
|
145
|
+
"from collections.abc import Callable
|
|
146
|
+
|
|
147
|
+
import httpx
|
|
148
|
+
|
|
149
|
+
from ..session_context import get_current_session_id
|
|
150
|
+
from .sigv4 import SigV4HTTPXAuth
|
|
151
|
+
|
|
152
|
+
SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class SessionHeaderAuth(httpx.Auth):
|
|
156
|
+
"""Stamps the AgentCore session header from the current async context,
|
|
157
|
+
then delegates to an optional inner auth (e.g. SigV4)."""
|
|
158
|
+
|
|
159
|
+
requires_request_body = True
|
|
160
|
+
requires_response_body = True
|
|
161
|
+
|
|
162
|
+
def __init__(self, inner: httpx.Auth | None = None):
|
|
163
|
+
self._inner = inner
|
|
164
|
+
|
|
165
|
+
def auth_flow(self, request: httpx.Request): # type: ignore[override]
|
|
166
|
+
sid = get_current_session_id()
|
|
167
|
+
if sid:
|
|
168
|
+
request.headers[SESSION_HEADER] = sid
|
|
169
|
+
if self._inner is None:
|
|
170
|
+
yield request
|
|
171
|
+
return
|
|
172
|
+
yield from self._inner.auth_flow(request)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def sigv4_auth(
|
|
176
|
+
credentials, region: str, service: str = "bedrock-agentcore"
|
|
177
|
+
) -> httpx.Auth:
|
|
178
|
+
"""Session-forwarding SigV4 auth (per-request, body-aware)."""
|
|
179
|
+
return SessionHeaderAuth(SigV4HTTPXAuth(credentials, service, region))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def jwt_auth(access_token_provider: Callable[[], str]) -> httpx.Auth:
|
|
183
|
+
"""Session-forwarding bearer-token auth."""
|
|
184
|
+
|
|
185
|
+
class _Bearer(httpx.Auth):
|
|
186
|
+
def auth_flow(self, request: httpx.Request):
|
|
187
|
+
request.headers["Authorization"] = f"Bearer {access_token_provider()}"
|
|
188
|
+
yield request
|
|
189
|
+
|
|
190
|
+
return SessionHeaderAuth(_Bearer())
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def plain_auth() -> httpx.Auth:
|
|
194
|
+
"""Session-forwarding plain auth — for local dev."""
|
|
195
|
+
return SessionHeaderAuth()
|
|
196
|
+
"
|
|
197
|
+
`;
|
|
@@ -2,16 +2,16 @@ import os
|
|
|
2
2
|
|
|
3
3
|
from strands.tools.mcp.mcp_client import MCPClient
|
|
4
4
|
|
|
5
|
-
from <%- agentConnectionModuleName %>.core.
|
|
6
|
-
|
|
5
|
+
from <%- agentConnectionModuleName %>.core.agentcore_gateway_mcp_client_strands import (
|
|
6
|
+
AgentCoreGatewayMCPClientStrands,
|
|
7
7
|
)
|
|
8
8
|
from <%- agentConnectionModuleName %>.core.runtime_config import (
|
|
9
9
|
get_agentcore_runtime_config,
|
|
10
10
|
)
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
class <%- gatewayClassName %>
|
|
14
|
-
"""
|
|
13
|
+
class <%- gatewayClassName %>ClientStrands:
|
|
14
|
+
"""Strands client for the <%- gatewayClassName %> AgentCore Gateway.
|
|
15
15
|
|
|
16
16
|
Deployed: a SigV4-signed MCP client pointing at the gateway URL.
|
|
17
17
|
Local (``SERVE_LOCAL=true``): a plain-HTTP client pointing at the local
|
|
@@ -23,7 +23,7 @@ class <%- gatewayClassName %>Client:
|
|
|
23
23
|
@staticmethod
|
|
24
24
|
def create() -> MCPClient:
|
|
25
25
|
if os.environ.get("SERVE_LOCAL") == "true":
|
|
26
|
-
return
|
|
26
|
+
return AgentCoreGatewayMCPClientStrands.without_auth(
|
|
27
27
|
gateway_url="http://localhost:<%- gatewayPort %>/mcp"
|
|
28
28
|
)
|
|
29
29
|
config = get_agentcore_runtime_config()
|
|
@@ -32,4 +32,4 @@ class <%- gatewayClassName %>Client:
|
|
|
32
32
|
raise RuntimeError(
|
|
33
33
|
"No connected gateway named '<%- gatewayClassName %>' found in runtime configuration."
|
|
34
34
|
)
|
|
35
|
-
return
|
|
35
|
+
return AgentCoreGatewayMCPClientStrands.with_iam_auth(gateway_url=gateway_url)
|
|
@@ -38,16 +38,16 @@ const pyAgentGatewayConnectionGenerator = async (tree, options) => {
|
|
|
38
38
|
const gatewayServeTargetName = `${gatewayKebabCase}-serve`;
|
|
39
39
|
const gatewayServeLocalTargetName = `${gatewayKebabCase}-serve-local`;
|
|
40
40
|
await (0, agent_connection_1.ensurePythonAgentConnectionProject)(tree);
|
|
41
|
-
(0, agent_connection_1.addPythonCoreClient)(tree, '
|
|
42
|
-
(0, agent_connection_1.addPythonCoreClient)(tree, 'gateway');
|
|
41
|
+
await (0, agent_connection_1.addPythonCoreClient)(tree, 'gateway');
|
|
43
42
|
const agentConnectionProjectDir = (0, agent_connection_1.getPythonAgentConnectionProjectDir)(tree);
|
|
44
43
|
const agentConnectionModuleName = (0, agent_connection_1.getPythonAgentConnectionModuleName)(tree);
|
|
45
44
|
const agentConnectionPackageName = (0, agent_connection_1.getPythonAgentConnectionPackageName)(tree);
|
|
45
|
+
// Layer 0/1 deps for the MCP transport + signed httpx auth. The framework's
|
|
46
|
+
// own dependency (strands-agents) is added by addPythonCoreClient.
|
|
46
47
|
(0, py_1.addDependenciesToPyProjectToml)(tree, agentConnectionProjectDir, [
|
|
47
48
|
'boto3',
|
|
48
49
|
'httpx',
|
|
49
50
|
'mcp',
|
|
50
|
-
'strands-agents',
|
|
51
51
|
]);
|
|
52
52
|
const appDir = (0, devkit_1.joinPathFragments)(agentConnectionProjectDir, agentConnectionModuleName, 'app');
|
|
53
53
|
// Local mode points at the gateway project's local gateway port.
|
|
@@ -62,11 +62,11 @@ const pyAgentGatewayConnectionGenerator = async (tree, options) => {
|
|
|
62
62
|
tree.write(appInitPath, '');
|
|
63
63
|
}
|
|
64
64
|
const moduleInitPath = (0, devkit_1.joinPathFragments)(agentConnectionProjectDir, agentConnectionModuleName, '__init__.py');
|
|
65
|
-
await (0, agent_connection_1.addPythonReExport)(tree, moduleInitPath, `.app.${gatewaySnakeCase}
|
|
65
|
+
await (0, agent_connection_1.addPythonReExport)(tree, moduleInitPath, `.app.${gatewaySnakeCase}_client_strands`, `${gatewayClassName}ClientStrands`);
|
|
66
66
|
const agentSourceDir = (0, devkit_1.joinPathFragments)(sourceProject.root, agentComponent.path ?? 'src');
|
|
67
67
|
const agentFilePath = (0, devkit_1.joinPathFragments)(agentSourceDir, 'agent.py');
|
|
68
68
|
if (tree.exists(agentFilePath)) {
|
|
69
|
-
const clientClassName = `${gatewayClassName}
|
|
69
|
+
const clientClassName = `${gatewayClassName}ClientStrands`;
|
|
70
70
|
const clientVarName = gatewaySnakeCase;
|
|
71
71
|
await (0, ast_1.addPythonDestructuredImport)(tree, agentFilePath, [clientClassName], agentConnectionModuleName);
|
|
72
72
|
await (0, agent_connection_1.addPythonClientToAgent)(tree, agentFilePath, clientClassName, clientVarName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/py/agent/gateway-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAQoB;AACpB,oEAAoF;AACpF,uFAQ0D;AAC1D,4CAAiE;AACjE,kDAA6D;AAC7D,oDAAyE;AACzE,gDAAiD;AACjD,0CAK2B;AAC3B,0CAG2B;AAGd,QAAA,0CAA0C,GACrD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,iCAAiC,GAAG,KAAK,EACpD,IAAU,EACV,OAAgD,EACpB,EAAE;IAC9B,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAC/C,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,IAAA,wCAA4B,EAAC,aAAa,CAAC,CAAC;IAE5D,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,YAAY,OAAO,CAAC,IAAI,mBAAmB,OAAO,CAAC,QAAQ,8CAA8C,CAC1G,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,YAAY,OAAO,CAAC,IAAI,gBAAgB,OAAO,CAAC,IAAI,yDAAyD,CAC9G,CAAC;IACJ,CAAC;IACD,IAAI,cAAc,CAAC,IAAI,IAAI,cAAc,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CACb,UAAU,cAAc,CAAC,IAAI,gBAAgB,cAAc,CAAC,IAAI,+DAA+D,CAChI,CAAC;IACJ,CAAC;IAED,MAAM,gBAAgB,GAAG,OAAO,CAAC,EAAE,CAAC;IACpC,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,gBAAgB,CAAC,CAAC;IACrD,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7D,MAAM,sBAAsB,GAAG,GAAG,gBAAgB,QAAQ,CAAC;IAC3D,MAAM,2BAA2B,GAAG,GAAG,gBAAgB,cAAc,CAAC;IAEtE,MAAM,IAAA,qDAAkC,EAAC,IAAI,CAAC,CAAC;IAC/C,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/py/agent/gateway-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAQoB;AACpB,oEAAoF;AACpF,uFAQ0D;AAC1D,4CAAiE;AACjE,kDAA6D;AAC7D,oDAAyE;AACzE,gDAAiD;AACjD,0CAK2B;AAC3B,0CAG2B;AAGd,QAAA,0CAA0C,GACrD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,iCAAiC,GAAG,KAAK,EACpD,IAAU,EACV,OAAgD,EACpB,EAAE;IAC9B,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAC/C,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,IAA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AAI,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC,CAAC;AA1JW,QAAA,iCAAiC,qCA0J5C;AAEF,kBAAe,yCAAiC,CAAC"}
|
|
@@ -6,8 +6,6 @@ exports.pyAgentGenerator = exports.PY_AGENT_GENERATOR_INFO = void 0;
|
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
|
9
|
-
const config_1 = require("../../license/config");
|
|
10
|
-
const known_exceptions_1 = require("../../license/known-exceptions");
|
|
11
9
|
const agent_chat_1 = require("../../utils/agent-chat/agent-chat");
|
|
12
10
|
const agent_connection_1 = require("../../utils/agent-connection/agent-connection");
|
|
13
11
|
const agent_core_constructs_1 = require("../../utils/agent-core-constructs/agent-core-constructs");
|
|
@@ -58,6 +56,9 @@ const pyAgentGenerator = async (tree, options) => {
|
|
|
58
56
|
// session ID to any downstream MCP / A2A clients a later connection
|
|
59
57
|
// generator wires into this agent.
|
|
60
58
|
await (0, agent_connection_1.ensurePythonAgentConnectionProject)(tree);
|
|
59
|
+
// The agent server imports the framework base helpers (session cache + model
|
|
60
|
+
// error logging) regardless of whether a connection client is wired in.
|
|
61
|
+
await (0, agent_connection_1.addPythonFrameworkBase)(tree);
|
|
61
62
|
const agentConnectionModuleName = (0, agent_connection_1.getPythonAgentConnectionModuleName)(tree);
|
|
62
63
|
const agentConnectionPackageName = (0, agent_connection_1.getPythonAgentConnectionPackageName)(tree);
|
|
63
64
|
(0, py_1.addWorkspaceDependencyToPyProject)(tree, project.root, agentConnectionPackageName);
|
|
@@ -284,9 +285,6 @@ const pyAgentGenerator = async (tree, options) => {
|
|
|
284
285
|
protocol,
|
|
285
286
|
});
|
|
286
287
|
await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [exports.PY_AGENT_GENERATOR_INFO]);
|
|
287
|
-
if (protocol === 'ag-ui') {
|
|
288
|
-
await (0, config_1.ensureLicenseExceptions)(tree, known_exceptions_1.AG_UI_STRANDS_EXCEPTIONS);
|
|
289
|
-
}
|
|
290
288
|
await (0, format_1.formatFilesInSubtree)(tree);
|
|
291
289
|
return async () => {
|
|
292
290
|
(0, devkit_1.installPackagesTask)(tree);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/py/agent/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AACpB,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/py/agent/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AACpB,kEAAwE;AACxE,oFAKuD;AACvD,mGAAwF;AACxF,sDAAkE;AAClE,uDAA2D;AAC3D,+CAA0D;AAC1D,uCAA4C;AAC5C,yCAAkD;AAClD,yCAA6C;AAC7C,iDAAsE;AACtE,6CAAwE;AACxE,qDAAoD;AACpD,uCAMwB;AACxB,yDAA6D;AAC7D,+CAAoD;AACpD,6CAA0D;AAC1D,2CAA8C;AAC9C,uCAIwB;AACxB,qEAA0E;AAC1E,mDAAoD;AAGvC,QAAA,uBAAuB,GAClC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,gBAAgB,GAAG,KAAK,EACnC,IAAU,EACV,OAA+B,EACH,EAAE;IAC9B,MAAM,OAAO,GAAG,IAAA,wCAAmC,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,MAAM,aAAa,GAAG,IAAA,0BAAiB,EAAC,OAAO,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAExE,iDAAiD;IACjD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,uBAAuB,OAAO,CAAC,OAAO,qDAAqD,CAC5F,CAAC;IACJ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ACtB,IAAI;QACJ,QAAQ;KACT,CACF,CAAC;IAEF,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE,CAAC,+BAAuB,CAAC,CAAC,CAAC;IAEvE,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,IAAI,EAAE;QAChB,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,IAAI,wBAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,oBAAM,EAAE,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC,CAAC;AAnXW,QAAA,gBAAgB,oBAmX3B;AAEF,kBAAe,wBAAgB,CAAC"}
|
|
@@ -5,12 +5,12 @@ exports[`py#agent#mcp-connection generator > should match snapshot for generated
|
|
|
5
5
|
|
|
6
6
|
from .core.session_context import get_current_session_id, session_id_context
|
|
7
7
|
|
|
8
|
-
from .app.
|
|
8
|
+
from .app.inventory_mcp_client_strands import InventoryMcpClientStrands
|
|
9
9
|
|
|
10
|
-
from .core.
|
|
10
|
+
from .core.model_errors_strands import log_model_errors
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
from .core.
|
|
13
|
+
from .core.with_session_id_strands import with_session_id
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
__all__ = [
|
|
@@ -18,134 +18,212 @@ __all__ = [
|
|
|
18
18
|
"session_id_context",
|
|
19
19
|
"with_session_id",
|
|
20
20
|
"log_model_errors",
|
|
21
|
-
"
|
|
21
|
+
"InventoryMcpClientStrands",
|
|
22
22
|
]
|
|
23
23
|
"
|
|
24
24
|
`;
|
|
25
25
|
|
|
26
|
-
exports[`py#agent#mcp-connection generator > should match snapshot for generated files >
|
|
26
|
+
exports[`py#agent#mcp-connection generator > should match snapshot for generated files > agentcore_mcp_client_strands.py 1`] = `
|
|
27
27
|
"from collections.abc import Callable
|
|
28
28
|
|
|
29
|
-
import boto3
|
|
30
|
-
import httpx
|
|
31
|
-
from mcp.client.streamable_http import streamablehttp_client
|
|
32
29
|
from strands.tools.mcp.mcp_client import MCPClient
|
|
33
30
|
|
|
34
|
-
from .
|
|
35
|
-
from .session_context import get_current_session_id
|
|
36
|
-
|
|
37
|
-
SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class _SessionHeaderAuth(httpx.Auth):
|
|
41
|
-
"""Stamps the AgentCore session header from the current async context."""
|
|
42
|
-
|
|
43
|
-
requires_request_body = True
|
|
44
|
-
requires_response_body = True
|
|
45
|
-
|
|
46
|
-
def __init__(self, inner: httpx.Auth | None = None):
|
|
47
|
-
self._inner = inner
|
|
48
|
-
|
|
49
|
-
def auth_flow(self, request: httpx.Request): # type: ignore[override]
|
|
50
|
-
sid = get_current_session_id()
|
|
51
|
-
if sid:
|
|
52
|
-
request.headers[SESSION_HEADER] = sid
|
|
53
|
-
if self._inner is None:
|
|
54
|
-
yield request
|
|
55
|
-
return
|
|
56
|
-
yield from self._inner.auth_flow(request)
|
|
57
|
-
|
|
31
|
+
from .agentcore_mcp_transport import AgentCoreMCPTransport
|
|
58
32
|
|
|
59
|
-
class AgentCoreMCPClient:
|
|
60
|
-
"""Factory for MCP clients that forward the current async-context session."""
|
|
61
33
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"""Extract region from ARN and construct the invocation URL.
|
|
65
|
-
|
|
66
|
-
ARN format: arn:partition:service:region:account-id:resource
|
|
67
|
-
"""
|
|
68
|
-
region = agent_runtime_arn.split(":")[3]
|
|
69
|
-
encoded_arn = agent_runtime_arn.replace(":", "%3A").replace("/", "%2F")
|
|
70
|
-
url = (
|
|
71
|
-
f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/"
|
|
72
|
-
f"{encoded_arn}/invocations?qualifier=DEFAULT"
|
|
73
|
-
)
|
|
74
|
-
return region, url
|
|
75
|
-
|
|
76
|
-
@staticmethod
|
|
77
|
-
def _create(url: str, auth: httpx.Auth | None = None) -> MCPClient:
|
|
78
|
-
return MCPClient(
|
|
79
|
-
lambda: streamablehttp_client(
|
|
80
|
-
url,
|
|
81
|
-
auth=_SessionHeaderAuth(auth),
|
|
82
|
-
timeout=120,
|
|
83
|
-
terminate_on_close=False,
|
|
84
|
-
)
|
|
85
|
-
)
|
|
34
|
+
class AgentCoreMCPClientStrands:
|
|
35
|
+
"""Factory for Strands MCP clients that connect to an AgentCore runtime."""
|
|
86
36
|
|
|
87
37
|
@staticmethod
|
|
88
38
|
def with_iam_auth(agent_runtime_arn: str) -> MCPClient:
|
|
89
39
|
"""SigV4-authenticated client for a Bedrock AgentCore runtime."""
|
|
90
|
-
|
|
91
|
-
credentials = boto3.Session(region_name=region).get_credentials()
|
|
92
|
-
return AgentCoreMCPClient._create(
|
|
93
|
-
url, SigV4HTTPXAuth(credentials, "bedrock-agentcore", region)
|
|
94
|
-
)
|
|
40
|
+
return MCPClient(AgentCoreMCPTransport.with_iam_auth(agent_runtime_arn))
|
|
95
41
|
|
|
96
42
|
@staticmethod
|
|
97
43
|
def with_jwt_auth(
|
|
98
44
|
agent_runtime_arn: str, access_token_provider: Callable[[], str]
|
|
99
45
|
) -> MCPClient:
|
|
100
46
|
"""Bearer-authenticated client for a Bedrock AgentCore runtime."""
|
|
101
|
-
_, url = AgentCoreMCPClient._build_url(agent_runtime_arn)
|
|
102
47
|
return MCPClient(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
auth=_SessionHeaderAuth(),
|
|
106
|
-
headers={"Authorization": f"Bearer {access_token_provider()}"},
|
|
107
|
-
timeout=120,
|
|
108
|
-
terminate_on_close=False,
|
|
48
|
+
AgentCoreMCPTransport.with_jwt_auth(
|
|
49
|
+
agent_runtime_arn, access_token_provider
|
|
109
50
|
)
|
|
110
51
|
)
|
|
111
52
|
|
|
112
53
|
@staticmethod
|
|
113
54
|
def without_auth(url: str) -> MCPClient:
|
|
114
55
|
"""Plain-HTTP client — for local dev."""
|
|
115
|
-
return
|
|
56
|
+
return MCPClient(AgentCoreMCPTransport.without_auth(url))
|
|
57
|
+
"
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
exports[`py#agent#mcp-connection generator > should match snapshot for generated files > agentcore_mcp_transport.py 1`] = `
|
|
61
|
+
"from collections.abc import Callable
|
|
62
|
+
|
|
63
|
+
from .agentcore_endpoints import mcp_url_from_arn, region_from_arn
|
|
64
|
+
from .agentcore_transport import (
|
|
65
|
+
TransportFactory,
|
|
66
|
+
jwt_transport,
|
|
67
|
+
no_auth_transport,
|
|
68
|
+
sigv4_transport,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class AgentCoreMCPTransport:
|
|
73
|
+
"""Factory for MCP transport factories that connect to an AgentCore runtime."""
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def with_iam_auth(agent_runtime_arn: str) -> TransportFactory:
|
|
77
|
+
"""SigV4-authenticated transport for a Bedrock AgentCore runtime."""
|
|
78
|
+
return sigv4_transport(
|
|
79
|
+
mcp_url_from_arn(agent_runtime_arn), region_from_arn(agent_runtime_arn)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def with_jwt_auth(
|
|
84
|
+
agent_runtime_arn: str, access_token_provider: Callable[[], str]
|
|
85
|
+
) -> TransportFactory:
|
|
86
|
+
"""Bearer-authenticated transport for a Bedrock AgentCore runtime."""
|
|
87
|
+
return jwt_transport(mcp_url_from_arn(agent_runtime_arn), access_token_provider)
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def without_auth(url: str) -> TransportFactory:
|
|
91
|
+
"""Plain-HTTP transport — for local dev."""
|
|
92
|
+
return no_auth_transport(url)
|
|
93
|
+
"
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
exports[`py#agent#mcp-connection generator > should match snapshot for generated files > agentcore_transport.py 1`] = `
|
|
97
|
+
"from collections.abc import Callable
|
|
98
|
+
from typing import Any
|
|
99
|
+
|
|
100
|
+
import boto3
|
|
101
|
+
|
|
102
|
+
from mcp.client.streamable_http import streamablehttp_client
|
|
103
|
+
|
|
104
|
+
from .auth.session import jwt_auth, plain_auth, sigv4_auth
|
|
105
|
+
|
|
106
|
+
# Agent frameworks wrap a transport *factory* — a no-arg callable returning a
|
|
107
|
+
# streamable-HTTP transport context manager. Typed as \`\`Any\`\` so this layer
|
|
108
|
+
# stays free of any framework-specific transport type.
|
|
109
|
+
TransportFactory = Callable[[], Any]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _factory(url: str, auth) -> TransportFactory:
|
|
113
|
+
return lambda: streamablehttp_client(
|
|
114
|
+
url,
|
|
115
|
+
auth=auth,
|
|
116
|
+
timeout=120,
|
|
117
|
+
terminate_on_close=False,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def sigv4_transport(url: str, region: str) -> TransportFactory:
|
|
122
|
+
"""SigV4-signed transport factory for a resolved AgentCore endpoint."""
|
|
123
|
+
credentials = boto3.Session(region_name=region).get_credentials()
|
|
124
|
+
return _factory(url, sigv4_auth(credentials, region))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def jwt_transport(
|
|
128
|
+
url: str, access_token_provider: Callable[[], str]
|
|
129
|
+
) -> TransportFactory:
|
|
130
|
+
"""Bearer-token transport factory for a resolved AgentCore endpoint."""
|
|
131
|
+
return _factory(url, jwt_auth(access_token_provider))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def no_auth_transport(url: str) -> TransportFactory:
|
|
135
|
+
"""Plain-HTTP transport factory — for local dev."""
|
|
136
|
+
return _factory(url, plain_auth())
|
|
116
137
|
"
|
|
117
138
|
`;
|
|
118
139
|
|
|
119
|
-
exports[`py#agent#mcp-connection generator > should match snapshot for generated files >
|
|
140
|
+
exports[`py#agent#mcp-connection generator > should match snapshot for generated files > inventory_mcp_client_strands.py 1`] = `
|
|
120
141
|
"import os
|
|
121
142
|
|
|
122
143
|
from strands.tools.mcp.mcp_client import MCPClient
|
|
123
144
|
|
|
124
|
-
from proj_agent_connection.core.
|
|
145
|
+
from proj_agent_connection.core.agentcore_mcp_client_strands import (
|
|
146
|
+
AgentCoreMCPClientStrands,
|
|
147
|
+
)
|
|
125
148
|
from proj_agent_connection.core.runtime_config import (
|
|
126
149
|
get_agentcore_runtime_config,
|
|
127
150
|
)
|
|
128
151
|
|
|
129
152
|
|
|
130
|
-
class
|
|
131
|
-
"""
|
|
153
|
+
class InventoryMcpClientStrands:
|
|
154
|
+
"""Strands client for the InventoryMcp MCP server."""
|
|
132
155
|
|
|
133
156
|
@staticmethod
|
|
134
157
|
def create() -> MCPClient:
|
|
135
158
|
if os.environ.get("SERVE_LOCAL") == "true":
|
|
136
|
-
return
|
|
159
|
+
return AgentCoreMCPClientStrands.without_auth("http://localhost:8082/mcp")
|
|
137
160
|
config = get_agentcore_runtime_config()
|
|
138
161
|
agent_runtime_arn = config.get("agentRuntimes", {}).get("InventoryMcp")
|
|
139
162
|
if not agent_runtime_arn:
|
|
140
163
|
raise RuntimeError(
|
|
141
164
|
"No connected MCP server runtime named 'InventoryMcp' found in runtime configuration."
|
|
142
165
|
)
|
|
143
|
-
return
|
|
166
|
+
return AgentCoreMCPClientStrands.with_iam_auth(agent_runtime_arn)
|
|
167
|
+
"
|
|
168
|
+
`;
|
|
169
|
+
|
|
170
|
+
exports[`py#agent#mcp-connection generator > should match snapshot for generated files > session.py 1`] = `
|
|
171
|
+
"from collections.abc import Callable
|
|
172
|
+
|
|
173
|
+
import httpx
|
|
174
|
+
|
|
175
|
+
from ..session_context import get_current_session_id
|
|
176
|
+
from .sigv4 import SigV4HTTPXAuth
|
|
177
|
+
|
|
178
|
+
SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class SessionHeaderAuth(httpx.Auth):
|
|
182
|
+
"""Stamps the AgentCore session header from the current async context,
|
|
183
|
+
then delegates to an optional inner auth (e.g. SigV4)."""
|
|
184
|
+
|
|
185
|
+
requires_request_body = True
|
|
186
|
+
requires_response_body = True
|
|
187
|
+
|
|
188
|
+
def __init__(self, inner: httpx.Auth | None = None):
|
|
189
|
+
self._inner = inner
|
|
190
|
+
|
|
191
|
+
def auth_flow(self, request: httpx.Request): # type: ignore[override]
|
|
192
|
+
sid = get_current_session_id()
|
|
193
|
+
if sid:
|
|
194
|
+
request.headers[SESSION_HEADER] = sid
|
|
195
|
+
if self._inner is None:
|
|
196
|
+
yield request
|
|
197
|
+
return
|
|
198
|
+
yield from self._inner.auth_flow(request)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def sigv4_auth(
|
|
202
|
+
credentials, region: str, service: str = "bedrock-agentcore"
|
|
203
|
+
) -> httpx.Auth:
|
|
204
|
+
"""Session-forwarding SigV4 auth (per-request, body-aware)."""
|
|
205
|
+
return SessionHeaderAuth(SigV4HTTPXAuth(credentials, service, region))
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def jwt_auth(access_token_provider: Callable[[], str]) -> httpx.Auth:
|
|
209
|
+
"""Session-forwarding bearer-token auth."""
|
|
210
|
+
|
|
211
|
+
class _Bearer(httpx.Auth):
|
|
212
|
+
def auth_flow(self, request: httpx.Request):
|
|
213
|
+
request.headers["Authorization"] = f"Bearer {access_token_provider()}"
|
|
214
|
+
yield request
|
|
215
|
+
|
|
216
|
+
return SessionHeaderAuth(_Bearer())
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def plain_auth() -> httpx.Auth:
|
|
220
|
+
"""Session-forwarding plain auth — for local dev."""
|
|
221
|
+
return SessionHeaderAuth()
|
|
144
222
|
"
|
|
145
223
|
`;
|
|
146
224
|
|
|
147
225
|
exports[`py#agent#mcp-connection generator > should match snapshot for generated files > transformed-agent.py 1`] = `
|
|
148
|
-
"from proj_agent_connection import
|
|
226
|
+
"from proj_agent_connection import InventoryMcpClientStrands
|
|
149
227
|
from contextlib import contextmanager
|
|
150
228
|
|
|
151
229
|
from strands import Agent, tool
|
|
@@ -160,7 +238,7 @@ def subtract(a: int, b: int) -> int:
|
|
|
160
238
|
|
|
161
239
|
@contextmanager
|
|
162
240
|
def get_agent(session_id: str):
|
|
163
|
-
inventory_mcp =
|
|
241
|
+
inventory_mcp = InventoryMcpClientStrands.create()
|
|
164
242
|
with (
|
|
165
243
|
inventory_mcp,
|
|
166
244
|
):
|