Skip to content

Comments

feat: set gateway env vars in agentcore dev for local testing#428

Open
aidandaly24 wants to merge 6 commits intoaws:feat/gateway-integrationfrom
aidandaly24:feat/batch-5-invoke-gateway-env
Open

feat: set gateway env vars in agentcore dev for local testing#428
aidandaly24 wants to merge 6 commits intoaws:feat/gateway-integrationfrom
aidandaly24:feat/batch-5-invoke-gateway-env

Conversation

@aidandaly24
Copy link
Contributor

Description

Enable agentcore dev to connect to deployed gateways by setting gateway environment variables in the local agent runtime.

When agents are deployed, CDK sets AGENTCORE_GATEWAY_{NAME}_URL and AGENTCORE_GATEWAY_{NAME}_AUTH_TYPE env vars automatically. For local development with agentcore dev, these env vars were missing — agents would log "gateway URL not set" warnings and run without gateway tools.

This PR reads gateway URLs from deployed-state.json (populated during agentcore deploy) and auth types from mcp.json, then sets the corresponding env vars when starting the local dev server. Values from .env.local take precedence, allowing manual overrides.

Changes:

  • New gateway-env.ts helper that reads deployed state and builds gateway env vars
  • Integrated in both CLI dev command and TUI dev hook
  • parseGatewayOutputs fixed to parse all three CDK output types (Id, Arn, Url) separately instead of only matching URL outputs
  • GatewayDeployedStateSchema extended with optional gatewayUrl field (backward compatible)
  • Graceful fallback when deployed state doesn't exist (agent runs without gateway tools)

Companion CDK PR adds the gateway URL to CloudFormation outputs.

Related Issue

Part of the MCP Gateway Phase 1 integration (gateway-integration branch). Task 16b.

Type of Change

  • New feature

Testing

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

@github-actions github-actions bot added the size/l PR size: L label Feb 24, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-invoke-gateway-env branch from 33bad00 to 5a7265a Compare February 24, 2026 22:54
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Feb 24, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-invoke-gateway-env branch from 5a7265a to 53c561c Compare February 24, 2026 22:59
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Feb 24, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-invoke-gateway-env branch from 53c561c to b00e92c Compare February 25, 2026 03:13
@github-actions github-actions bot added size/m PR size: M and removed size/l PR size: L labels Feb 25, 2026
Add SigV4 authentication to MCP client templates so agents can
authenticate with AWS_IAM gateways. Each framework's client.py
uses Handlebars conditionals to include auth when gateways exist.

SigV4HTTPXAuth class signs HTTP requests using botocore SigV4Auth,
passed to the MCP client via httpx.AsyncClient. Templates read
gateway URLs from AGENTCORE_GATEWAY_{NAME}_URL env vars and handle
missing vars gracefully (warn, don't crash).

Updated all 5 frameworks: Strands, LangChain, OpenAI Agents,
Google ADK, AutoGen. Schema mapper reads mcp.json to populate
gateway config for template rendering. All gateways are auto-
included when creating an agent.
Replace single-gateway [0] indexing with {{#each gatewayProviders}}
loops. Each gateway gets its own client function (Strands) or entry
in the servers dict (LangChain/OpenAI/AutoGen/ADK).

Add snakeCase Handlebars helper for gateway function names.
Add gatewayAuthTypes array for conditional SigV4 imports.
Fix @index parse error by using plain variable names.
All 5 framework main.py files now use Handlebars conditionals to
import the correct MCP client function based on hasGateway flag.
Fix snakeCase helper to handle all special characters.
…way support

Replace custom SigV4HTTPXAuth class with official mcp-proxy-for-aws package:
- Strands: aws_iam_streamablehttp_client factory pattern
- LangChain: SigV4HTTPXAuth via auth param in MultiServerMCPClient config
- OpenAI Agents: SigV4HTTPXAuth via httpx_client_factory param
- Google ADK: SigV4HTTPXAuth via httpx_client_factory in StreamableHTTPConnectionParams

Revert AutoGen to original upstream — SDK doesn't support custom
httpx auth (no httpx_client_factory param).
Read deployed-state.json for gateway URLs and mcp.json for auth types,
then set AGENTCORE_GATEWAY_{NAME}_URL and AGENTCORE_GATEWAY_{NAME}_AUTH_TYPE
env vars when running agentcore dev locally.

- New gateway-env.ts helper iterates all deployment targets
- Integrated in both CLI dev command and TUI dev hook
- .env.local values take precedence over gateway env vars
- Graceful fallback when no deployed state exists
- Fixed parseGatewayOutputs to parse Id, Arn, and Url outputs separately
- Added gatewayUrl field to deployed-state schema (optional, backward compat)
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-invoke-gateway-env branch from b00e92c to 41e0411 Compare February 25, 2026 05:59
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant