Skip to content

Comments

feat: add gateway auth and multi-gateway support to agent templates#427

Open
aidandaly24 wants to merge 5 commits intoaws:feat/gateway-integrationfrom
aidandaly24:feat/batch-5-agent-gateway-auth
Open

feat: add gateway auth and multi-gateway support to agent templates#427
aidandaly24 wants to merge 5 commits intoaws:feat/gateway-integrationfrom
aidandaly24:feat/batch-5-agent-gateway-auth

Conversation

@aidandaly24
Copy link
Contributor

@aidandaly24 aidandaly24 commented Feb 24, 2026

Description

Add gateway authentication and multi-gateway support to agent templates so agents can connect to MCP gateways.

SigV4 Authentication

Each framework's mcp_client/client.py includes a SigV4HTTPXAuth class that signs HTTP requests using botocore's SigV4Auth, passed to the MCP client via httpx.AsyncClient(auth=...). This enables agents to authenticate with AWS_IAM gateways (Lambda function URLs).

Multi-Gateway Support

Templates use {{#each gatewayProviders}} loops to generate per-gateway client functions. Each gateway gets its own env var (AGENTCORE_GATEWAY_{NAME}_URL) and auth configuration. A convenience function collects clients from all gateways.

Template System Changes

  • AgentRenderConfig extended with hasGateway, gatewayProviders, and gatewayAuthTypes
  • Schema mapper reads mcp.json to populate gateway config for rendering
  • Added snakeCase Handlebars helper for Python function names
  • All main.py files use {{#if hasGateway}} conditionals for correct imports
  • Missing env vars log a warning and return None instead of crashing
  • All 5 frameworks updated: Strands, LangChain, OpenAI Agents, Google ADK, AutoGen
  • All gateways are auto-included when creating an agent

Related Issue

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

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 size/m PR size: M and removed size/m PR size: M labels Feb 24, 2026
@aidandaly24 aidandaly24 changed the title feat: add gateway auth support to agent templates feat: add gateway auth and multi-gateway support to agent templates Feb 24, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-agent-gateway-auth branch from 10d415a to 1c74bb4 Compare February 24, 2026 22:53
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 24, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-agent-gateway-auth branch from 1c74bb4 to d9b90be Compare February 24, 2026 22:59
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 24, 2026
Copy link
Contributor

@notgitika notgitika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, LGTM.

This is a great start and we can go ahead with my comments + @tejaskash 's in follow-up PRs

Comment on lines +48 to +50
mcp_tools = []
if mcp_client:
mcp_tools = await mcp_client.get_tools()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultiServerMCPClient is normally used as async with. Calling .get_tools() without entering the context manager may not initialize connections.

logger.warning("{{envVarName}} not set — {{name}} gateway tools unavailable")
return None
{{#if (eq authType "AWS_IAM")}}
http_client = httpx.AsyncClient(auth=SigV4HTTPXAuth())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This client is never closed, which leaks connections. Should be managed with async with or closed on shutdown.

Comment on lines +11 to +13
Handlebars.registerHelper('snakeCase', (str: string) => {
return str.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produces double underscores (My--GW → my__gateway) and invalid Python identifiers for digit-leading names. Collapse consecutive _ and handle leading digits.

try:
async with mcp_server as server:
active_servers = [server] if server else []
{{#if hasGateway}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gateway and non-gateway branches duplicate a lot of lines of agent creation. We could factor out the shared logic

@notgitika
Copy link
Contributor

Can we also add tests in this PR around mapMcpGatewaysToGatewayProviders?

@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 25, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-agent-gateway-auth branch from 2b7b91d to d9b90be Compare February 25, 2026 02:12
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M 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).
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-agent-gateway-auth branch from 12af7bf to 1f153bc 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.

2 participants