DEV Community

Cover image for # 🔌 Lab 05: Using MCP (Model Context Protocol) with Strands Agents | Strands Agentic AI
Jamal
Jamal

Posted on

# 🔌 Lab 05: Using MCP (Model Context Protocol) with Strands Agents | Strands Agentic AI

So far in this series, we've built custom tools and taught agents how to interact with the outside world.

But what if someone else has already built the tools you need?

Instead of writing every integration yourself, you can connect your AI agent to an MCP Server.

Model Context Protocol (MCP) is an open standard that allows AI agents to discover and use tools provided by external systems.

In this lab, you'll connect a Strands Agent to the AWS Documentation MCP Server and allow the agent to retrieve factual AWS documentation directly from official sources.

By the end of this lab, you'll have an AWS Documentation Assistant powered by MCP.


🚀 What You'll Learn

In this lab, you'll learn:

  • What MCP (Model Context Protocol) is
  • Why MCP is becoming important in Agentic AI
  • How to connect to an MCP server
  • How to use STDIO transport
  • How agents automatically discover MCP tools
  • How to build an AWS Documentation Assistant

🤖 What is MCP?

Model Context Protocol (MCP) is an open protocol that allows AI models and agents to connect to external tools and data sources.

Think of MCP as:

USB for AI Agents
Enter fullscreen mode Exit fullscreen mode

Just as USB allows computers to connect to keyboards, printers, and storage devices, MCP allows AI agents to connect to:

  • Documentation systems
  • Databases
  • APIs
  • Search engines
  • Internal tools
  • Enterprise applications

Without MCP:

Agent
  ↓
Custom Tool
  ↓
External System
Enter fullscreen mode Exit fullscreen mode

With MCP:

Agent
  ↓
MCP Server
  ↓
Many Tools
Enter fullscreen mode Exit fullscreen mode

One connection can expose dozens of tools instantly.


🛠️ Prerequisites

Before starting, make sure you have:

  • Python 3.10+
  • AWS Account
  • Amazon Bedrock access
  • AWS credentials configured
  • uv installed
  • MCP SDK installed
  • Strands SDK installed

Install dependencies:

pip install strands-agents
pip install mcp
Enter fullscreen mode Exit fullscreen mode

🌟 Why MCP Matters

Imagine you're building an AWS assistant.

Without MCP:

Build Tool #1
Build Tool #2
Build Tool #3
Build Tool #4
...
Enter fullscreen mode Exit fullscreen mode

You must create and maintain every integration yourself.

With MCP:

Connect MCP Server
Discover Tools
Start Using Them
Enter fullscreen mode Exit fullscreen mode

The MCP server handles the heavy lifting.

Your agent simply consumes the available tools.

This dramatically reduces development effort.


📜 The Script

Let's start by looking at the complete example.

from strands import Agent, tool
from strands.models.bedrock import BedrockModel

from strands.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters

# Bedrock
bedrock_model = BedrockModel(
    model_id="<YOUR_MODEL_ID>",
    region_name="eu-west-2",
    temperature=0.3,
)

# Connect to an MCP server using stdio transport
stdio_mcp_client = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="uvx",
            args=["awslabs.aws-documentation-mcp-server@latest"]
        )
    )
)

with stdio_mcp_client:
    tools = stdio_mcp_client.list_tools_sync()

    agent = Agent(
        system_prompt="""
        You are an AWS Documentation expert.
        Use the tools that are available to provide factual information.
        """,
        model=bedrock_model,
        tools=tools
    )

    agent("What is AWS Lambda?")
Enter fullscreen mode Exit fullscreen mode

Now let's break it down.


⚙️ Step 1: Import MCP Components

from strands.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
Enter fullscreen mode Exit fullscreen mode

These imports provide everything required to communicate with an MCP server.

Components

Component Purpose
MCPClient Connects Strands to MCP
stdio_client Uses standard input/output transport
StdioServerParameters Configures the MCP server

⚙️ Step 2: Configure Amazon Bedrock

bedrock_model = BedrockModel(
    model_id="<YOUR_MODEL_ID>",
    region_name="eu-west-2",
    temperature=0.3,
)
Enter fullscreen mode Exit fullscreen mode

This is the reasoning engine behind our agent.

The model decides:

  • Which tool to use
  • What information to retrieve
  • How to respond

⚙️ Step 3: Create the MCP Connection

stdio_mcp_client = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="uvx",
            args=[
                "awslabs.aws-documentation-mcp-server@latest"
            ]
        )
    )
)
Enter fullscreen mode Exit fullscreen mode

This establishes a connection to the AWS Documentation MCP Server.

Think of it as:

Agent
  ↓
MCP Client
  ↓
AWS Documentation MCP Server
Enter fullscreen mode Exit fullscreen mode

The server exposes AWS documentation tools automatically.


⚙️ Step 4: Understanding STDIO Transport

This lab uses STDIO transport.

Agent Process
      ⇅
Standard Input/Output
      ⇅
MCP Server Process
Enter fullscreen mode Exit fullscreen mode

STDIO is ideal for:

  • Local development
  • Local testing
  • Lightweight integrations

Because communication happens through process streams, no network setup is required.


⚙️ Step 5: Start the MCP Session

with stdio_mcp_client:
Enter fullscreen mode Exit fullscreen mode

This opens a connection to the MCP server.

Once inside the context manager:

  • Server starts
  • Tools become available
  • Agent can access them

When execution finishes, the connection closes automatically.


⚙️ Step 6: Discover Available Tools

tools = stdio_mcp_client.list_tools_sync()
Enter fullscreen mode Exit fullscreen mode

This is one of the most powerful MCP features.

Instead of manually creating tools:

tools = stdio_mcp_client.list_tools_sync()
Enter fullscreen mode Exit fullscreen mode

The agent automatically discovers everything exposed by the MCP server.

Think of it like:

Connect
    ↓
Discover Tools
    ↓
Use Tools
Enter fullscreen mode Exit fullscreen mode

No additional coding required.


⚙️ Step 7: Create the Agent

agent = Agent(
    system_prompt="""
    You are an AWS Documentation expert.
    Use the tools that are available to provide factual information.
    """,
    model=bedrock_model,
    tools=tools
)
Enter fullscreen mode Exit fullscreen mode

Notice something interesting.

We aren't manually registering tools.

Instead:

tools=tools
Enter fullscreen mode Exit fullscreen mode

contains every tool discovered from the MCP server.

The agent now has access to AWS documentation capabilities.


⚙️ Step 8: Ask a Question

agent("What is AWS Lambda?")
Enter fullscreen mode Exit fullscreen mode

The workflow becomes:

User Question
       ↓
Agent Analysis
       ↓
MCP Tool Selection
       ↓
AWS Documentation Search
       ↓
Documentation Retrieved
       ↓
Final Response
Enter fullscreen mode Exit fullscreen mode

The answer comes from official AWS documentation rather than relying solely on model memory.


▶️ Run the Agent

Execute the script:

python agent.py
Enter fullscreen mode Exit fullscreen mode

Or:

uv run labs/05-mcp-introduction/agent.py
Enter fullscreen mode Exit fullscreen mode

📊 Example Interaction

User

What is AWS Lambda?
Enter fullscreen mode Exit fullscreen mode

Agent Workflow

Question Received
       ↓
Discover Documentation Tool
       ↓
Query AWS Documentation
       ↓
Retrieve Information
       ↓
Generate Response
Enter fullscreen mode Exit fullscreen mode

Agent Response

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers.

You pay only for the compute time consumed and can automatically scale applications in response to demand.
Enter fullscreen mode Exit fullscreen mode

The exact response may vary depending on the documentation version and model.


🔍 What Makes MCP Different?

Traditional Tool Approach:

Build Tool
Register Tool
Maintain Tool
Update Tool
Enter fullscreen mode Exit fullscreen mode

MCP Approach:

Connect Server
Discover Tools
Use Tools
Enter fullscreen mode Exit fullscreen mode

The MCP server owns the implementation.

Your agent simply consumes capabilities.

This dramatically improves scalability.


💡 Real-World MCP Use Cases

MCP is useful for connecting agents to:

Documentation Systems

AWS Documentation
Azure Documentation
Internal Knowledge Bases
Enter fullscreen mode Exit fullscreen mode

Databases

PostgreSQL
MySQL
MongoDB
Enter fullscreen mode Exit fullscreen mode

Development Tools

GitHub
GitLab
Jira
Enter fullscreen mode Exit fullscreen mode

Cloud Services

AWS
Azure
Google Cloud
Enter fullscreen mode Exit fullscreen mode

Enterprise Systems

CRM
ERP
HR Systems
Enter fullscreen mode Exit fullscreen mode

The possibilities are nearly endless.


🧠 Why Developers Love MCP

Without MCP:

❌ Build every integration yourself

❌ Maintain tool definitions

❌ Handle protocol changes

❌ Create custom wrappers

With MCP:

✅ Discover tools automatically

✅ Reuse existing integrations

✅ Standardized communication

✅ Faster development

✅ Easier maintenance

MCP shifts focus from integration work to solving business problems.


🎯 Key Takeaways

  • MCP stands for Model Context Protocol
  • MCP allows agents to connect to external tool providers
  • STDIO transport is perfect for local development
  • Agents can automatically discover available tools
  • MCP significantly reduces integration effort
  • The AWS Documentation MCP Server provides direct access to official AWS information

📚 Source Code

GitHub Repository:

https://github.com/d3vjamal/strands-agents-labs


🚀 Next Lab

In the next lab, we'll explore remote MCP servers and learn how agents can connect to tools running on different machines and services across the network.


🔗 Continue Learning

⬅️ Previous Lab

Lab 04B: Building a Web Search Tool for AI Agents

➡️ Next Lab

Lab 06: Remote MCP Servers


Top comments (0)