1- """
2- Example: Using MCP Proxy for AWS as a client for Microsoft Agent Framework integration
1+ """Example: Using MCP Proxy for AWS as a client for Microsoft Agent Framework integration.
32
43This example demonstrates how to use the aws_iam_mcp_client with the Microsoft Agent Framework
54to connect an AI agent to an MCP server using AWS IAM authentication.
2524import asyncio
2625import dotenv
2726import os
28- from contextlib import asynccontextmanager
29-
3027from agent_framework import ChatAgent
31- from agent_framework .openai import OpenAIChatClient
3228from agent_framework ._mcp import MCPStreamableHTTPTool
33-
29+ from agent_framework .openai import OpenAIChatClient
30+ from contextlib import asynccontextmanager
3431from mcp_proxy_for_aws .client import aws_iam_mcp_client
3532
3633
5148
5249@asynccontextmanager
5350async def create_agent ():
54- """
55- Create an Agent Framework agent with AWS IAM-authenticated MCP server access.
51+ """Create an Agent Framework agent with AWS IAM-authenticated MCP server access.
5652
5753 This function demonstrates the key integration pattern:
58- 1. Configure an aws_iam_mcp_client factory with the MCP server details
54+ 1. Define an aws_iam_mcp_client factory function with the MCP server details
5955 2. Initialize an MCPStreamableHTTPTool and add the client factory
6056 3. Create an agent with access to the tools provided by the MCP server
6157 4. Return a callable interface to communicate with the agent
6258 """
63- # Configure the MCP client with AWS IAM authentication
64- mcp_client_factory = lambda : aws_iam_mcp_client (
65- endpoint = MCP_URL , aws_region = MCP_REGION , aws_service = MCP_SERVICE
66- )
59+
60+ # Define MCP client factory function for AWS IAM authentication
61+ def mcp_client_factory ():
62+ return aws_iam_mcp_client ( endpoint = MCP_URL , aws_region = MCP_REGION , aws_service = MCP_SERVICE )
6763
6864 # Create an Agent Framework MCP and add the client
6965 mcp_tools = MCPStreamableHTTPTool (name = 'MCP Tools' , url = MCP_URL )
@@ -87,7 +83,6 @@ async def agent_callable(user_input: str) -> str:
8783
8884async def main ():
8985 """Run the agent example by asking it to list its available tools."""
90-
9186 # Validate required environment variables
9287 if not MCP_URL or not MCP_REGION or not MCP_SERVICE or not OPENAI_API_KEY :
9388 raise ValueError (
0 commit comments