DEV Community

Cover image for # 🚀 Lab 05: Connecting to an MCP Server with STDIO Transport | Strands Agentic AI
Jamal
Jamal

Posted on

# 🚀 Lab 05: Connecting to an MCP Server with STDIO Transport | Strands Agentic AI

In the previous lab, we learned what Model Context Protocol (MCP) is and why it is becoming the standard way for AI agents to access tools and external systems.

Now it's time to build a real MCP-powered agent.

In this lab, you'll connect a Strands Agent to the AWS Documentation MCP Server using STDIO transport and allow the agent to retrieve information directly from AWS documentation.

By the end of this tutorial, you'll have an AWS Documentation Assistant capable of answering AWS questions using MCP-provided tools.


📚 Strands Agentic AI Lab Series

⬅️ Previous: Lab 05: Introduction to MCP

📍 Current: Lab 06: Connecting to an MCP Server with STDIO Transport

➡️ Next: Lab 07: Exploring MCP Tools and Capabilities


🚀 What You'll Learn

In this lab, you'll learn:

  • What STDIO transport is
  • How MCP clients communicate with MCP servers
  • How to connect to an AWS Documentation MCP Server
  • How to discover available tools dynamically
  • How to build an AI assistant powered by MCP tools

🤖 Why STDIO Transport?

MCP supports multiple communication methods.

The simplest is STDIO.

Agent
  ↓
STDIO
  ↓
MCP Server
Enter fullscreen mode Exit fullscreen mode

Instead of communicating over a network, the agent and MCP server communicate through standard input and output streams.

Benefits:

  • Simple setup
  • Fast local development
  • No network configuration
  • Great for experimentation

Think of STDIO as two applications having a direct private conversation.


🛠️ Prerequisites

Before starting, make sure you have:

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

Install dependencies:

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

📜 The Script

Let's start with 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 the building blocks for MCP communication.

MCPClient

Creates a bridge between Strands and the MCP server.

stdio_client

Handles communication over standard input and output.

StdioServerParameters

Defines how the MCP server should start.


⚙️ Step 2: Configure the Bedrock Model

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

This model performs:

  • Reasoning
  • Tool selection
  • Response generation

The MCP server provides tools.

The LLM decides how to use them.


⚙️ Step 3: Configure the MCP Server

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

This launches the AWS Documentation MCP Server.

Architecture:

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

The MCP server automatically exposes tools to the agent.


⚙️ Step 4: Platform Differences

macOS/Linux

command="uvx"
args=[
    "awslabs.aws-documentation-mcp-server@latest"
]
Enter fullscreen mode Exit fullscreen mode

Windows

command="uvx"
args=[
    "--from",
    "awslabs.aws-documentation-mcp-server@latest",
    "awslabs.aws-documentation-mcp-server.exe"
]
Enter fullscreen mode Exit fullscreen mode

The server package is the same.

Only the launch syntax changes.


⚙️ Step 5: Start the MCP Session

with stdio_mcp_client:
Enter fullscreen mode Exit fullscreen mode

This starts the MCP server session.

Once inside the context:

  • Server launches
  • Connection is established
  • Tools become available

When execution completes, resources are cleaned up automatically.


⚙️ Step 6: Discover Available Tools

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

This is where MCP becomes powerful.

Instead of manually creating tools:

@tool
def search_docs():
    ...
Enter fullscreen mode Exit fullscreen mode

You can simply discover tools provided by the server.

Connect
    ↓
Discover
    ↓
Use
Enter fullscreen mode Exit fullscreen mode

No custom tool implementation 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:

tools=tools
Enter fullscreen mode Exit fullscreen mode

These tools come directly from the MCP server.

The agent now has access to AWS documentation capabilities without any additional coding.


⚙️ Step 8: Ask a Question

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

Workflow:

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

The agent uses official AWS documentation instead of relying only on model memory.


▶️ Run the Agent

Execute:

python agent.py
Enter fullscreen mode Exit fullscreen mode

Or:

uv run labs/06-mcp-stdio-client/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 Results
       ↓
Generate Answer
Enter fullscreen mode Exit fullscreen mode

Response

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

Lambda automatically scales your application and charges only for the compute time used.
Enter fullscreen mode Exit fullscreen mode

🔍 What Happened Behind the Scenes?

When the question was asked:

  1. The LLM analyzed the request.
  2. It discovered documentation tools.
  3. It selected the most relevant tool.
  4. The MCP server retrieved AWS documentation.
  5. Results were returned to the model.
  6. The model generated the final answer.

The agent never needed a custom Python function.

The MCP server supplied everything.


💡 Why Developers Love MCP

Without MCP:

❌ Build custom integrations

❌ Maintain tools manually

❌ Write wrappers for every service

With MCP:

✅ Connect once

✅ Discover tools automatically

✅ Reuse existing integrations

✅ Build agents faster

MCP turns integrations into plug-and-play components.


🎯 Key Takeaways

  • STDIO is the simplest MCP transport
  • MCP servers expose tools dynamically
  • Agents can discover tools automatically
  • AWS Documentation MCP Server provides factual AWS information
  • MCP dramatically reduces integration effort
  • Strands Agents integrate seamlessly with MCP

📚 Source Code

GitHub Repository:

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


🔗 Continue Learning

⬅️ Previous Lab

Lab 05: Introduction to MCP

➡️ Next Lab

Lab 07: Exploring MCP Tools and Capabilities


🚀 Next Lab

In the next tutorial, we'll inspect the tools exposed by an MCP server, understand their schemas, and learn how agents choose the right tool for a given task.

Top comments (0)