$npx -y skills add aws/agent-toolkit-for-aws --skill agents-connectUse when connecting your agent to external APIs, tools, or services via Gateway, or restricting tool access with Cedar policies. Handles gateway setup, target types, outbound auth (OAuth, API key, IAM), credentials, and Cedar policy authoring. Triggers on: "connect to API", "add
| 1 | # connect |
| 2 | |
| 3 | Give your AgentCore agent access to external APIs, tools, and services via the AgentCore Gateway — and control what it can access with Cedar policies. |
| 4 | |
| 5 | ## When to use |
| 6 | |
| 7 | - You want your agent to call an external API or MCP server |
| 8 | - You want to expose Lambda functions as agent tools |
| 9 | - You have an OpenAPI spec you want to turn into agent tools |
| 10 | - Your agent needs credentials to call an external service |
| 11 | - You want to restrict which tools your agent can call (Cedar policies) |
| 12 | - You want role-based or amount-based access control on tool calls |
| 13 | - A gateway connection, tool call, or policy authorization is failing |
| 14 | |
| 15 | For adding Cedar policies to control tool access, load [`references/policy.md`](references/policy.md). |
| 16 | |
| 17 | ## Input |
| 18 | |
| 19 | `$ARGUMENTS` is optional: |
| 20 | |
| 21 | ``` |
| 22 | /connect # interactive — asks what you're connecting to |
| 23 | /connect mcp # MCP server setup |
| 24 | /connect lambda # Lambda function as tools |
| 25 | /connect openapi # OpenAPI schema as tools |
| 26 | /connect credential # Add a credential for outbound auth |
| 27 | ``` |
| 28 | |
| 29 | ## Process |
| 30 | |
| 31 | ### Step 0: Verify CLI version |
| 32 | |
| 33 | Run `agentcore --version`. This skill requires v0.9.0 or later. If the version is older, tell the developer to run `agentcore update` before proceeding. |
| 34 | |
| 35 | ### Step 1: Read the project |
| 36 | |
| 37 | Read `agentcore/agentcore.json` to understand: |
| 38 | |
| 39 | - What framework the project uses |
| 40 | - What gateways and targets are already configured (in the `agentCoreGateways` array) |
| 41 | |
| 42 | **If no project context:** Ask what they're trying to connect to and proceed with the appropriate pattern. |
| 43 | |
| 44 | ### Step 2: Identify what they're connecting to |
| 45 | |
| 46 | Ask (or infer from `$ARGUMENTS`): |
| 47 | |
| 48 | > "What are you connecting your agent to? |
| 49 | > |
| 50 | > 1. An external MCP server (e.g., a third-party tool provider) |
| 51 | > 2. A Lambda function you've written |
| 52 | > 3. An API with an OpenAPI spec |
| 53 | > 4. An AWS API Gateway REST API |
| 54 | > 5. An external service with no OpenAPI spec, MCP server, or Lambda in front of it — and you can't add one" |
| 55 | |
| 56 | **Options 1–4 front the service as a Gateway target.** This is the default path: the gateway handles outbound auth via its credential providers (so the agent code never sees the secret), the tool becomes discoverable over MCP, and policy engines can authorize or deny calls at the edge. Pick the target type that matches the service. |
| 57 | |
| 58 | **Option 5 is Path D** — register a credential and call the API directly from agent code. This is the fallback when fronting isn't practical; the skill walks through when it's appropriate and when it isn't. |
| 59 | |
| 60 | --- |
| 61 | |
| 62 | ## Default: prefer a Gateway target over direct API calls in code |
| 63 | |
| 64 | Before jumping into paths, set expectations. Most "my agent needs to call X" requests land on a Gateway target — not on `httpx` inside the entrypoint. |
| 65 | |
| 66 | **Why Gateway is the default:** |
| 67 | |
| 68 | - **Credential injection at the edge.** Gateway's credential providers (OAuth, API key, IAM) attach auth to the outbound request. The agent code calls `session.call_tool(...)` — it never touches the secret. Agent code that does `client = openai.OpenAI(api_key=...)` is one leaked prompt / log line / traceback away from exfiltrating the key. |
| 69 | - **Discoverable tool catalog.** Tools are listed by the MCP server; the framework (Strands, LangGraph, etc.) binds them automatically. Adding a tool is an `agentcore add gateway-target` + redeploy, not a code change. |
| 70 | - **Policy enforcement.** Cedar policies can authorize or deny tool calls per principal, per tool, per argument value. This is impossible when tool calls are buried in `httpx.post(...)` inside agent code. |
| 71 | - **Semantic search.** Once the catalog has 20+ tools, `x_amz_bedrock_agentcore_search` selects the relevant ones per turn. |
| 72 | |
| 73 | **When a direct API call in agent code is the right answer:** |
| 74 | |
| 75 | | Situation | Why Gateway isn't right | What to do | |
| 76 | |---|---|---| |
| 77 | | Streaming/bidirectional protocol (SSE with live output, WebSockets, |