Description
agentcore add tool --type agentcore_gateway --gateway <name> fails with Gateway '<name>' not found in deployed state. Deploy it first or use --gateway-arn. even when the gateway is confirmed deployed via agentcore status.
This is the same root cause as #1658 (fixed in #1663 for PolicyPrimitive.ts), but the fix was not applied to src/cli/commands/add/tool-action.ts. The automated reviewer on #1663 flagged this file explicitly as a remaining instance.
Note this was found via Step 5 in Lab 2 of the "Best Practices for Agentic AI with AgentCore in Financial Services" workshop
Steps to Reproduce
Note this was appears via Step 5 in Lab 2 of the "Best Practices for Agentic AI with AgentCore in Financial Services" workshop
-
Create a project with a gateway (HTTP / protocolType: "None"):
agentcore add gateway --name my-gateway \
--authorizer-type CUSTOM_JWT \
--discovery-url $COGNITO_DISCOVERY_URL \
--allowed-clients $COGNITO_CLIENT_ID \
--allowed-scopes $COGNITO_SCOPE
-
Add gateway targets and deploy:
agentcore add gateway-target --type lambda-function-arn --name MyTool \
--lambda-arn $LAMBDA_ARN --tool-schema-file schema.json --gateway my-gateway
agentcore deploy -y
-
Confirm the gateway is deployed:
agentcore status
# Output:
# Gateways
# my-gateway: Deployed (1 target) (projectname-my-gateway-xxxxxxxx)
-
Attempt to add the gateway as a tool to a harness:
agentcore add tool --harness MyHarness \
--type agentcore_gateway \
--name my-gateway \
--gateway my-gateway \
--outbound-auth oauth \
--provider-arn $CRED_ARN \
--scopes $SCOPE \
--grant-type CLIENT_CREDENTIALS
-
Observe error:
Gateway 'my-gateway' not found in deployed state. Deploy it first or use --gateway-arn.
Expected Behavior
The CLI should resolve the gateway name from deployed state (searching both resources.mcp.gateways and resources.gateways) and proceed.
Actual Behavior
The CLI only checks resources.mcp.gateways, missing HTTP gateways stored under resources.gateways.
CLI Version
1.0.0-preview.19
Operating System
Linux
Additional Context
Root Cause
In src/cli/commands/add/tool-action.ts (~line 165):
const gatewayState = targetState?.resources?.mcp?.gateways?.[options.gateway];
This only searches the MCP gateway map. The findDeployedGateway() helper introduced in #1663 (in src/cli/primitives/deployed-gateways.ts) correctly merges both maps but is not used here.
Suggested Fix
Replace the manual lookup with the existing helper:
- const targetState = deployedState.targets[targetNames[0]!];
- const gatewayState = targetState?.resources?.mcp?.gateways?.[options.gateway];
+ import { findDeployedGateway } from '../../primitives/deployed-gateways';
+ const gatewayState = findDeployedGateway(deployedState, options.gateway);
This also fixes a secondary issue: the current code only searches targetNames[0] (the first target), while findDeployedGateway searches across all targets.
Workaround
Use --gateway-arn with the full ARN instead of --gateway with the local name:
agentcore add tool --harness MyHarness \
--type agentcore_gateway \
--name my-gateway \
--gateway-arn arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/projectname-my-gateway-xxxxxxxx \
--outbound-auth oauth \
--provider-arn $CRED_ARN \
--scopes $SCOPE \
--grant-type CLIENT_CREDENTIALS
Environment
- CLI version: 0.21.1
- OS: Amazon Linux 2023 (EC2)
- Node: 20.x
Related
Description
agentcore add tool --type agentcore_gateway --gateway <name>fails withGateway '<name>' not found in deployed state. Deploy it first or use --gateway-arn.even when the gateway is confirmed deployed viaagentcore status.This is the same root cause as #1658 (fixed in #1663 for
PolicyPrimitive.ts), but the fix was not applied tosrc/cli/commands/add/tool-action.ts. The automated reviewer on #1663 flagged this file explicitly as a remaining instance.Note this was found via Step 5 in Lab 2 of the "Best Practices for Agentic AI with AgentCore in Financial Services" workshop
Steps to Reproduce
Note this was appears via Step 5 in Lab 2 of the "Best Practices for Agentic AI with AgentCore in Financial Services" workshop
Create a project with a gateway (HTTP /
protocolType: "None"):Add gateway targets and deploy:
agentcore add gateway-target --type lambda-function-arn --name MyTool \ --lambda-arn $LAMBDA_ARN --tool-schema-file schema.json --gateway my-gateway agentcore deploy -yConfirm the gateway is deployed:
Attempt to add the gateway as a tool to a harness:
Observe error:
Expected Behavior
The CLI should resolve the gateway name from deployed state (searching both
resources.mcp.gatewaysandresources.gateways) and proceed.Actual Behavior
The CLI only checks
resources.mcp.gateways, missing HTTP gateways stored underresources.gateways.CLI Version
1.0.0-preview.19
Operating System
Linux
Additional Context
Root Cause
In
src/cli/commands/add/tool-action.ts(~line 165):This only searches the MCP gateway map. The
findDeployedGateway()helper introduced in #1663 (insrc/cli/primitives/deployed-gateways.ts) correctly merges both maps but is not used here.Suggested Fix
Replace the manual lookup with the existing helper:
This also fixes a secondary issue: the current code only searches
targetNames[0](the first target), whilefindDeployedGatewaysearches across all targets.Workaround
Use
--gateway-arnwith the full ARN instead of--gatewaywith the local name:Environment
Related
--generateflag fails to find gateway in deployed state #1658 — same bug pattern inPolicyPrimitive.ts(fixed)--generateflag fails to find gateway in deployed state #1658; automated reviewer flaggedtool-action.ts:165as an unfixed instance