-
Notifications
You must be signed in to change notification settings - Fork 55
AWS IAM MCP client with SigV4 auth #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9c07337
Add client
DennisTraub 1020886
Add client tests
DennisTraub cd7ab5f
Add usage examples for MCP client
DennisTraub 2cad69b
Update README
DennisTraub 549af1c
lint/format
DennisTraub 3e86f6a
Apply suggestions from code review
DennisTraub 6974fcf
Simplify aws_iam_mcp_client by returning streamablehttp_client directly
DennisTraub 0884f80
Simplify examples
DennisTraub 52666c3
Add example .env files
DennisTraub 430e841
Apply suggestions from arangatang's code review
DennisTraub 41a045a
Apply further suggestions from review
DennisTraub a2a0c4c
Fix linting issues
DennisTraub e97a47c
Add unit tests for client usage examples
DennisTraub 7148cac
Add license headers to examples
DennisTraub 6e82e27
Apply suggestions from code review
DennisTraub 8ad2f2e
chore: use uv workspaces for the examples
wzxxing be56338
Fix pyright errors
DennisTraub 8fea586
Rename to aws_iam_streamablehttp_client
DennisTraub 4a8c217
Update github workflow to build workspace
DennisTraub 82385bb
Add frozen flag in GH workflow
DennisTraub 0931e1d
Add return type to client signature
DennisTraub 699003c
Update docstring
DennisTraub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| *~ | ||
| *# | ||
| *.DS_Store | ||
| .claude | ||
| .clinerules | ||
| *-toolbag/ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # The URL of your MCP server | ||
| MCP_SERVER_URL="https://example-mcp-server.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp" | ||
| # The AWS service hosting the MCP server | ||
| MCP_SERVER_AWS_SERVICE="bedrock-agentcore" | ||
| # The AWS region where the MCP server is hosted | ||
| MCP_SERVER_REGION="us-west-2" | ||
|
|
||
| # Your OpenAI API key for the agent's language model | ||
| OPENAI_API_KEY="sk-..." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Example: Microsoft Agent Framework | ||
|
|
||
| This example demonstrates how to use `aws_iam_streamablehttp_client` from `mcp-proxy-for-aws` to connect a [Microsoft Agent Framework](https://learn.microsoft.com/en-us/agent-framework/) agent to an MCP server using AWS IAM authentication. | ||
|
|
||
| **Note:** Microsoft Agent Framework accepts a factory function that returns an MCP client. The `aws_iam_streamablehttp_client` is passed as a factory to the framework's `MCPStreamableHTTPTool`, which handles the connection lifecycle internally. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Python 3.10+](https://www.python.org/downloads) and [uv](https://docs.astral.sh/uv/getting-started/installation/) installed | ||
| - AWS credentials configured (via [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), environment variables, or IAM roles) | ||
| - An [OpenAI API key](https://platform.openai.com/api-keys) for the language model | ||
|
|
||
| ## Setup | ||
|
|
||
| Create a `.env` file or set the following environment variables: | ||
|
|
||
| ```bash | ||
| # 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-2 | ||
|
|
||
| # OpenAI API key for the agent's LLM | ||
| OPENAI_API_KEY=sk-... | ||
| ``` | ||
|
|
||
| All four environment variables are required. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the example: | ||
|
|
||
| ```bash | ||
| uv run main.py | ||
| ``` | ||
|
|
||
| The agent will connect to the MCP server and list its available tools. | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. **Loads configuration** from environment variables or `.env` file | ||
| 3. **Creates an AWS IAM-authenticated MCP client** using `aws_iam_streamablehttp_client()` | ||
| 4. **Integrates with Agent Framework** by configuring `MCPStreamableHTTPTool.get_mcp_client` | ||
| 5. **Creates an agent** with access to the MCP server tools | ||
| 6. **Runs the agent** to demonstrate tool discovery and usage | ||
|
|
||
| ## Example MCP Server URL Formats | ||
|
|
||
| **AgentCore Runtime URL:** | ||
|
|
||
| ```text | ||
| https://bedrock-agentcore.[AWS_REGION].amazonaws.com/runtimes/[RUNTIME_ID]/invocations?qualifier=DEFAULT&accountId=[AWS_ACCOUNT_ID] | ||
| ``` | ||
|
|
||
| **AgentCore Gateway URL:** | ||
|
|
||
| ```text | ||
| https://[GATEWAY_ID].gateway.bedrock-agentcore.[AWS_REGION].amazonaws.com/mcp | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| #### No AWS credentials available | ||
|
|
||
| - Verify AWS credentials are configured ([AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), environment variables, or IAM roles) | ||
| - Test with `aws sts get-caller-identity` | ||
|
|
||
| #### Missing environment variables | ||
|
|
||
| - Ensure all required variables are set: `MCP_SERVER_URL`, `MCP_SERVER_REGION`, `MCP_SERVER_AWS_SERVICE`, and `OPENAI_API_KEY` | ||
| - Check your `.env` file or environment variable configuration | ||
|
|
||
| #### Connection errors | ||
|
|
||
| - 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.