This example demonstrates how to use aws_iam_streamablehttp_client from mcp-proxy-for-aws to connect a LangChain AI agent to an MCP server using AWS IAM authentication.
Note: LangChain requires direct access to MCP sessions. The aws_iam_streamablehttp_client provides the authenticated transport streams, which are then used to create an MCP ClientSession.
- Python 3.10+ and uv installed
- AWS credentials configured (via AWS CLI, environment variables, or IAM roles)
- Access to Anthropic Claude on Amazon Bedrock
Create a .env file or set the following environment variables:
# MCP server details
MCP_SERVER_URL=https://example.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp
MCP_SERVER_AWS_SERVICE=bedrock-agentcore
MCP_SERVER_REGION=us-west-2All three environment variables are required.
Run the example:
uv run main.pyThe agent will connect to the MCP server and list its available tools.
- Loads configuration from environment variables or
.envfile - Creates an AWS IAM-authenticated MCP client using
aws_iam_streamablehttp_client() - Extracts transport streams from the client context manager
- Creates an MCP ClientSession with the authenticated transport streams
- Loads MCP tools using LangChain's MCP tools adapter
- Creates an agent with access to the MCP server tools
- Runs the agent to demonstrate tool discovery and usage
AgentCore Runtime URL:
https://bedrock-agentcore.[AWS_REGION].amazonaws.com/runtimes/[RUNTIME_ID]/invocations?qualifier=DEFAULT&accountId=[AWS_ACCOUNT_ID]
AgentCore Gateway URL:
https://[GATEWAY_ID].gateway.bedrock-agentcore.[AWS_REGION].amazonaws.com/mcp
- Verify AWS credentials are configured (AWS CLI, environment variables, or IAM roles)
- Test with
aws sts get-caller-identity
- Ensure all required variables are set:
MCP_SERVER_URL,MCP_SERVER_REGION, andMCP_SERVER_AWS_SERVICE - Check your
.envfile or environment variable configuration
- Verify your MCP server details are correct
- Ensure the MCP server is running and accessible
- Verify your AWS credentials have the necessary permissions to access the MCP server