-
Notifications
You must be signed in to change notification settings - Fork 5
Fix MCP initialization error handling and enable graceful degradation #6
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
awsdataarchitect
merged 2 commits into
main
from
cloudeng-strands-agent-20251216-161232
Dec 16, 2025
Merged
Changes from 1 commit
Commits
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create a BedrockModel with system inference profile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bedrock_model = BedrockModel( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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 and aws_docs_mcp_client: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 and aws_diagram_mcp_client: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the tool loading logic, the conditional check
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| atexit.register(cleanup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
There was a problem hiding this comment.
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_clientis redundant sinceaws_docs_mcp_clientis already set toNonewhenmcp_initializedisFalse. The check can be simplified to justmcp_initialized.