Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions cloud_engineer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@
print("2. Check your network connection")
print("3. Try running the Streamlit app instead: streamlit run app.py")

# Re-raise the exception to maintain the original behavior
raise
# Continue with limited functionality instead of raising exception
# This allows the module to be imported even if MCP initialization fails
print("\nContinuing with limited functionality (MCP tools disabled)...")
aws_docs_mcp_client = None
aws_diagram_mcp_client = None

# Get tools from MCP clients
docs_tools = aws_docs_mcp_client.list_tools_sync()
diagram_tools = aws_diagram_mcp_client.list_tools_sync()
# Get tools from MCP clients (if initialized)
docs_tools = aws_docs_mcp_client.list_tools_sync() if mcp_initialized and aws_docs_mcp_client else []
diagram_tools = aws_diagram_mcp_client.list_tools_sync() if mcp_initialized and aws_diagram_mcp_client else []
Comment on lines +116 to +117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional check mcp_initialized and aws_docs_mcp_client is redundant since aws_docs_mcp_client is already set to None when mcp_initialized is False. The check can be simplified to just mcp_initialized.

Suggested change
docs_tools = aws_docs_mcp_client.list_tools_sync() if mcp_initialized and aws_docs_mcp_client else []
diagram_tools = aws_diagram_mcp_client.list_tools_sync() if mcp_initialized and aws_diagram_mcp_client else []
# Get tools from MCP clients (if initialized)
docs_tools = aws_docs_mcp_client.list_tools_sync() if mcp_initialized else []
diagram_tools = aws_diagram_mcp_client.list_tools_sync() if mcp_initialized else []


# Create a BedrockModel with system inference profile
bedrock_model = BedrockModel(
Expand Down Expand Up @@ -152,17 +155,19 @@

# Register cleanup handler for MCP clients
def cleanup():
try:
aws_docs_mcp_client.stop()
print("AWS Documentation MCP client stopped")
except Exception as e:
print(f"Error stopping AWS Documentation MCP client: {e}")
if mcp_initialized:
try:
aws_docs_mcp_client.stop()
print("AWS Documentation MCP client stopped")
except Exception as e:
print(f"Error stopping AWS Documentation MCP client: {e}")

try:
aws_diagram_mcp_client.stop()
print("AWS Diagram MCP client stopped")
except Exception as e:
print(f"Error stopping AWS Diagram MCP client: {e}")
if mcp_initialized:
try:
aws_diagram_mcp_client.stop()
print("AWS Diagram MCP client stopped")
except Exception as e:
print(f"Error stopping AWS Diagram MCP client: {e}")

atexit.register(cleanup)

Expand Down