From 40a75cfe32110fdc116eb9cbc7a788a78e5b6b4f Mon Sep 17 00:00:00 2001 From: Kiro Agent <244629292+kiro-agent@users.noreply.github.com> Date: Tue, 16 Dec 2025 17:17:01 +0000 Subject: [PATCH 1/3] Refactor cloud_engineer_agent.py to simplify redundant conditional checks --- cloud_engineer_agent.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud_engineer_agent.py b/cloud_engineer_agent.py index fa05cb0..aa3a928 100644 --- a/cloud_engineer_agent.py +++ b/cloud_engineer_agent.py @@ -113,8 +113,8 @@ aws_diagram_mcp_client = None # 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 [] +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( @@ -155,14 +155,14 @@ # Register cleanup handler for MCP clients def cleanup(): - if mcp_initialized and aws_docs_mcp_client: + 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}") - if mcp_initialized and aws_diagram_mcp_client: + if mcp_initialized: try: aws_diagram_mcp_client.stop() print("AWS Diagram MCP client stopped") From d882e001aa0af6d19ee206183ba64fd79f897806 Mon Sep 17 00:00:00 2001 From: "amazon-q-developer[bot]" <208079219+amazon-q-developer[bot]@users.noreply.github.com> Date: Tue, 16 Dec 2025 18:06:45 +0000 Subject: [PATCH 2/3] [skip ci] Restore defensive null checks for MCP clients Add back null checks for aws_docs_mcp_client and aws_diagram_mcp_client to prevent potential AttributeError crashes if initialization logic changes. This maintains defensive programming practices as suggested in code review. --- cloud_engineer_agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud_engineer_agent.py b/cloud_engineer_agent.py index aa3a928..8a20169 100644 --- a/cloud_engineer_agent.py +++ b/cloud_engineer_agent.py @@ -113,8 +113,8 @@ aws_diagram_mcp_client = None # 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 [] +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 [] # Create a BedrockModel with system inference profile bedrock_model = BedrockModel( From 8db684e7cedabf3628bafc29813710c6cc7ce181 Mon Sep 17 00:00:00 2001 From: Kiro Agent <244629292+kiro-agent@users.noreply.github.com> Date: Tue, 16 Dec 2025 18:37:56 +0000 Subject: [PATCH 3/3] Add explicit null checks (is not None) for MCP clients - Add 'is not None' checks in tool loading logic to prevent AttributeError - Add 'is not None' checks in cleanup function for safer resource cleanup - Ensures defensive programming against potential MCP client initialization issues --- cloud_engineer_agent.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud_engineer_agent.py b/cloud_engineer_agent.py index 8a20169..9392ce3 100644 --- a/cloud_engineer_agent.py +++ b/cloud_engineer_agent.py @@ -113,8 +113,8 @@ aws_diagram_mcp_client = None # 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 [] +docs_tools = aws_docs_mcp_client.list_tools_sync() if mcp_initialized and aws_docs_mcp_client is not None else [] +diagram_tools = aws_diagram_mcp_client.list_tools_sync() if mcp_initialized and aws_diagram_mcp_client is not None else [] # Create a BedrockModel with system inference profile bedrock_model = BedrockModel( @@ -155,14 +155,14 @@ # Register cleanup handler for MCP clients def cleanup(): - if mcp_initialized: + if mcp_initialized and aws_docs_mcp_client is not None: 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: + if mcp_initialized and aws_diagram_mcp_client is not None: try: aws_diagram_mcp_client.stop() print("AWS Diagram MCP client stopped")