Create an agent that uses your AgentCore gateway - Amazon Bedrock AgentCore

Amazon Bedrock AgentCore is in preview release and is subject to change.

Create an agent that uses your AgentCore gateway

After creating and testing your gateway, you can create and connect AI agents to your gateway. An agent connected to your gateway is able to call the tools in the gateway and use a Amazon Bedrock model to respond to queries.

To learn how to create an agent, connect it to a gateway, and invoke it to answer queries, select one of the following methods:

Strands
from strands import Agent from strands.tools.mcp import MCPClient from mcp.client.streamable_http import streamablehttp_client # Replace with actual values and the Amazon Bedrock model of your choice gateway_url = "${GatewayUrl}" access_token = "${AccessToken}" model_id = "us.anthropic.claude-3-7-sonnet-20250219-v1:0" # Create an MCP Client that points to the gateway gateway_client = MCPClient(lambda: streamablehttp_client(gateway_url, headers={"Authorization": f"Bearer {access_token}"})) # Create an Agent that uses a Amazon Bedrock model and the gateway to answer def product_agent(question: str): with gateway_client: tools = gateway_client.list_tools_sync() agent = Agent( model=model_id, tools=tools, system_prompt="try to answer the user's question using the tools available", callback_handler=None ) return agent(question) # Send a query to the agent. The agent has access to the tools in the gateway to help answer the query print(product_agent("what types of shoes does Amazon sell?").message["content"])
LangGraph
from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client from langgraph.prebuilt import create_react_agent from langchain_mcp_adapters.tools import load_mcp_tools # Replace with actual values and the Amazon Bedrock model of your choice gateway_url = "${GatewayUrl}" access_token = "${AccessToken}" model_id = "openai:gpt-4.1" async with streamablehttp_client(gateway_url, headers={"Authorization": f"Bearer {access_token}"}) as (read, write, _): async with ClientSession(read, write) as session: # Initialize the connection await session.initialize() # Get tools tools = await load_mcp_tools(session) agent = create_react_agent(model_id, tools) math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"})
Claude Code
#!/bin/bash # Script to add MCP server to Claude # Server configuration SERVER_NAME=${ServerName} # Write your server name GATEWAY_MCP_SERVER_URL=${GatewayUrl} # The gateway MCP URL AUTH_TOKEN=${AuthToken} # Claude authentication token echo "Adding MCP server to Claude..." echo "Server Name: $SERVER_NAME" echo "Server URL: $SERVER_URL" echo "" # Add the MCP server claude mcp add "$SERVER_NAME" "$GATEWAY_MCP_SERVER_URL" \ --transport http \ --header "Authorization: Bearer $AUTH_TOKEN" # Check if the command was successful if [ $? -eq 0 ]; then echo "MCP server added successfully!" echo "" echo "You can now use the server with: claude --mcp-server $SERVER_NAME" else echo "Failed to add MCP server" exit 1 fi
Q Dev CLI

Integration with Q Dev CLI is available through MCP protocol support.

# Configure Q Dev CLI to use your gateway q config set mcp-server-url https://${GatewayId}.gateway.bedrock-agentcore.${Region}.amazonaws.com/mcp q config set mcp-auth-token ${AccessToken}