1750102136740_img

As AI development becomes more accessible, frameworks like Strands SDK are making it easier than ever to build capable AI agents. In this post, weโ€™ll explore how to create an agent that accesses AWS documentation and generates architecture diagrams using Amazon Q Developer CLI to assist us. โœจ

๐Ÿค” What is Strands SDK?

Strands SDK is a lightweight, code-first framework for building AI agents. It provides a simple but powerful way to create agents that can leverage different language models and tools while remaining production-ready.

Key features include:

  • ๐Ÿชถ Simple agent creation and customization
  • ๐Ÿ”„ Support for multiple model providers
  • ๐Ÿงฐ Built-in tools and capabilities
  • ๐Ÿ‘ฅ Multi-agent and autonomous agent support
  • ๐Ÿ”’ Focus on safety and security

๐Ÿ”Œ Understanding Model Context Protocol (MCP)

Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). This is crucial for our example because:

  • ๐Ÿงฉ MCP enables Strands agents to access external tools and services
  • ๐ŸŒ It creates a standardized way for models to communicate with specialized servers
  • ๐Ÿงฐ MCP servers provide additional functionality without requiring custom code

Important note: When working with MCP tools in Strands, all agent operations must be performed within the MCP clientโ€™s context manager (using a with statement). This ensures the MCP session remains active while the agent is using the tools.

# Correct way to use MCP tools
with mcp_client:
    agent = Agent(tools=mcp_client.list_tools_sync())
    response = agent("Your prompt here")

โš™๏ธ Setting Up Your Environment

First, letโ€™s set up our development environment:

In this example I used VS Code with Ubuntu WSL. There are plenty of other great IDEs out here to choose from.

  1. In your IDEโ€™s terminal, install the Strands SDK and required packages:
pip install strands-agents uv sarif-om

๐Ÿงฉ Make sure Amazon Q Developer CLI is available in your IDE. If you are new to Q Developer CLI, check out my blog post on this topic.

๐Ÿ› ๏ธ Creating an AWS Documentation & Diagram Agent

Letโ€™s create an agent that can access AWS documentation and create architecture diagrams. In VS Code, we can use Amazon Q Developer CLI to help us:

"Help me write a Strands agent that uses MCP to access AWS documentation and create architecture diagrams"

After getting guidance from Amazon Q Developer CLI, create a file named aws_docs_diagram_agent.py with the following code:

from mcp import StdioServerParameters, stdio_client
from strands import Agent
from strands.models import BedrockModel
from strands.tools.mcp import MCPClient

# Create client for AWS documentation MCP server
aws_docs_client = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="uvx", args=["awslabs.aws-documentation-mcp-server@latest"]
        )
    )
)

# Create client for AWS diagram MCP server
aws_diag_client = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="uvx", args=["awslabs.aws-diagram-mcp-server@latest"]
        )
    )
)

# Configure Bedrock model
bedrock_model = BedrockModel(
    model_id="us.anthropic.claude-3-5-haiku-20241022-v1:0",
    temperature=0.7,
)

# Define system prompt for the agent
SYSTEM_PROMPT = """
You are an expert AWS Solutions Architect with comprehensive knowledge of AWS services, architectures, and best practices. Your purpose is to assist customers in:

1. Understanding AWS architectural best practices aligned with the Well-Architected Framework
2. Designing optimal cloud solutions for their specific use cases
3. Resolving technical challenges in existing AWS implementations
4. Making informed decisions about AWS service selection and configuration

Capabilities:
- You can search and reference official AWS documentation to provide accurate, up-to-date information
- You can generate clear AWS architecture diagrams when requested
- When creating diagrams, always specify the complete file path so customers can easily locate them

Response Guidelines:
- Begin responses with a concise summary of your recommendation
- Provide sufficient technical detail while remaining accessible to varying technical backgrounds
- Reference specific AWS documentation when applicable
- Consider cost, performance, security, reliability, and operational excellence in your recommendations
- If information is insufficient to make a recommendation, ask clarifying questions

Maintain a professional, helpful tone while providing technically accurate guidance.
"""

# Initialize agent with MCP tools and model - MUST use with statement for MCP context
with aws_diag_client, aws_docs_client:  # Using context managers ensures MCP connections stay active
    all_tools = aws_docs_client.list_tools_sync() + aws_diag_client.list_tools_sync()
    agent = Agent(tools=all_tools, model=bedrock_model, system_prompt=SYSTEM_PROMPT)

    # Run the agent with a sample prompt
    response = agent(
        "Get the documentation for hosting a static website on S3 and CloudFront and then create a diagram of the services including a client desktop accessing the website"
    )

โ–ถ๏ธ Running Your Agent

To run the agent:

python aws_docs_diagram_agent.py

The agent will:

  1. ๐Ÿ“š Fetch AWS documentation on hosting static websites with S3 and CloudFront
  2. ๐Ÿ–ผ๏ธ Generate an architecture diagram showing how these services connect
  3. ๐Ÿ–ฅ๏ธ Include a client desktop accessing the website in the diagram
  4. ๐Ÿ“ Provide a detailed explanation along with the diagram

Here is a video of how I used Q Developer CLI and Strands SDK to explain and work with the above code.

๐Ÿ” How MCP Enhances Agent Capabilities

In our example, MCP enables our agent to:

  • ๐Ÿ“˜ Access and search official AWS documentation through the aws-documentation-mcp-server
  • ๐ŸŽจ Generate professional architecture diagrams via the aws-diagram-mcp-server
  • ๐Ÿ”„ Combine these capabilities seamlessly without writing custom integration code

The real power comes from combining multiple MCP servers to create agents with diverse capabilities. You can add additional MCP servers for cost estimation, security analysis, and more!

โœ… How Amazon Q Developer CLI Enhances Development

Amazon Q Developer CLI can help at various stages:

  • ๐Ÿ” Find examples: โ€œShow me examples of using MCP clients in Strandsโ€
  • ๐Ÿ› Debug issues: โ€œExplain error in MCPClient initializationโ€
  • ๐Ÿ’ก Optimize code: โ€œHow can I make my Strands agent more efficient?โ€
  • ๐Ÿ“š AWS documentation: โ€œHow do I set up CloudFront with S3?โ€

๐Ÿ”„ Customizing Your Agent

Need to adjust your agent? Ask Amazon Q Developer CLI:

 "Show me how to add another MCP server to my Strands agent"

Or to get help with MCP context managers:

"Explain best practices for working with multiple MCP clients in Strands"

๐Ÿ”ฎ Next Steps

From here, you can:

  1. ๐Ÿงฉ Add more MCP servers for different capabilities
  2. ๐Ÿ”„ Create interactive agents that can have conversations about architecture
  3. ๐Ÿ“Š Generate reports with diagrams and cost estimates
  4. ๐ŸŒ Extend to multi-cloud architecture planning

๐Ÿ Conclusion

Strands SDK combined with MCP tools and Amazon Q Developer CLI creates a powerful platform for building AWS architecture assistants. The standardized MCP protocol allows your agent to leverage specialized servers for documentation and diagrams while maintaining a clean, simple codebase. ๐ŸŒŸ

For more information:

  • ๐Ÿ“˜ Strands SDK Documentation
  • ๐Ÿค– Amazon Q Developer Documentation
  • โ˜๏ธ AWS MCP Servers Repository
  • ๐Ÿ”Œ MCP Protocol Specification

This example demonstrates just one possibility with Strands SDK - the combination of multiple specialized MCP servers opens up endless possibilities for creating powerful, knowledgeable agents! ๐Ÿš€๐Ÿค–โœจ


<
Previous Post
๐Ÿค– Amazon Q Developer CLI: Your AI Coding Assistant in the Terminal! ๐Ÿš€
>
Next Post
Hello, MCP! ๐Ÿค–๐Ÿ”Œ