22import logging
33import os
44from typing import Any
5+ from contextlib import ExitStack
56
67from botocore .config import Config
78from strands import Agent
@@ -41,22 +42,26 @@ def main() -> None:
4142
4243 # Add stdio servers
4344 for name , srv_config in server_config .get ("stdioServers" , {}).items ():
44- mcp_clients .append (create_stdio_client (name , srv_config ))
45+ client = create_stdio_client (name , srv_config )
46+ mcp_clients .append ((name , client ))
4547 logging .info (f"Added stdio server: { name } " )
4648
4749 # Add lambda function servers
4850 for name , srv_config in server_config .get ("lambdaFunctionServers" , {}).items ():
49- mcp_clients .append (create_lambda_function_client (name , srv_config ))
51+ client = create_lambda_function_client (name , srv_config )
52+ mcp_clients .append ((name , client ))
5053 logging .info (f"Added lambda function server: { name } " )
5154
5255 # Add lambda function URL servers
5356 for name , srv_config in server_config .get ("lambdaFunctionUrls" , {}).items ():
54- mcp_clients .append (create_lambda_function_url_client (name , srv_config ))
57+ client = create_lambda_function_url_client (name , srv_config )
58+ mcp_clients .append ((name , client ))
5559 logging .info (f"Added lambda function URL server: { name } " )
5660
5761 # Add OAuth servers
5862 for name , srv_config in server_config .get ("oAuthServers" , {}).items ():
59- mcp_clients .append (create_automated_oauth_client (name , srv_config ))
63+ client = create_automated_oauth_client (name , srv_config )
64+ mcp_clients .append ((name , client ))
6065 logging .info (f"Added OAuth server: { name } " )
6166
6267 if not mcp_clients :
@@ -78,13 +83,18 @@ def main() -> None:
7883 boto_client_config = retry_config ,
7984 )
8085
81- # Create agent with MCP tools
86+ # Create agent with MCP tools (agent will start them)
8287 agent = Agent (
8388 model = bedrock_model ,
84- tools = mcp_clients ,
85- system_prompt = "You are a helpful assistant. Always retry on tool errors, to recover from transient failures ." ,
89+ tools = [ client for _ , client in mcp_clients ] ,
90+ system_prompt = "You are a helpful assistant. Always retry tool call failures to recover from issues like transient network errors ." ,
8691 )
8792
93+ # List tools from each MCP client
94+ for name , client in mcp_clients :
95+ tools = client .list_tools_sync ()
96+ logging .info (f"Tools from { name } : { [t .tool_name for t in tools ]} " )
97+
8898 # Run test utterances
8999 for i , user_input in enumerate (user_utterances ):
90100 print (f"\n You: { user_input } " )
0 commit comments