Series: Once Upon Agentic AI.
Despite their new powers and fearless hearts, our heroes had not defeated all the foes. A greater monster was waiting for them, mightier than anything they had faced. This time, our heroes would need more than their own strength to prevail.
The series follows the adventure in three parts:
- Part 1: Create your first agent, equip it with a Vended tool, then write a tool of your own.
- This article: MCP (Model Context Protocol) explored via the MCP Inspector and Strands Agents Harness SDK.
- Part 3: RAG (Retrieval-Augmented Generation), A2A (Agent2Agent) and Structured output with an orchestrator agent leading specialized agents.
You need Python, uv, a terminal, and AWS credentials with access to Amazon Bedrock.
The code lives in aws-samples/sample-once-upon-agentic-ai. The main branch contains skeletons with # TODO markers. Let's Learn and Be Curious together!
Use the same setup as Part 1:
git clone https://github.com/aws-samples/sample-once-upon-agentic-ai.git ~/sample-once-upon-agentic-ai
cd ~/sample-once-upon-agentic-ai
uv sync
export AWS_PROFILE=YOUR_AWS_PROFILE AWS_REGION=YOUR_AWS_REGION
No AWS profile yet? The Strands Agents Amazon Bedrock model provider guide shows how to set up AWS credentials (with aws configure, environment variables, a boto3 session, or aws login) and lists the IAM permissions your agent needs to invoke a model. Strands picks those credentials up on its own.
What is MCP?
In Part 1, the whole agent loop ran inside one Python process: the model read the tool specification, decided to call roll_dice, Strands ran the function, and the model read the result. MCP (Model Context Protocol) is an open standard that lets an agent use capabilities living in another program. Tools are one of them, and a server can also share data and reusable prompts, as the table below shows. In this post, we move the dice tool into a server. The agent loop stays as it is: the model still decides which tool to call, and only the place where the function runs changes.
Who talks to whom? MCP uses a client/server architecture: think HTTP, but for AI agents. A web browser sends requests to a web server and reads its responses; an MCP client does the same with an MCP server, which answers with its tools and their results. The host is the AI application, which here is a Strands agent. For every server it uses, the host creates one client that keeps a dedicated connection to that server. That client is TheWitcherish's green orb. The server is the program that offers capabilities: it lists its tools when the client asks with tools/list, and runs one when the client sends tools/call. Between those two requests, the agent loop runs exactly as in Part 1.
What can a server offer? A server has three primitives, grouped by who controls their use:
| Primitive | Controlled by | Example |
|---|---|---|
| Prompts | User | System prompts, few-shot examples |
| Resources | Application | File contents, database schemas, API responses |
| Tools | Model | An API call, a database write |
How are messages written? Every MCP message is JSON-RPC 2.0, a small standard for calling another program with JSON. A request carries an id, a method and params, and its response repeats the same id with either a result or an error. A notification has no id, because it expects no reply. Here is a tool call:
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search","arguments":{"q":"otters"}}}
How do messages travel? MCP defines two transports. With stdio, the client starts the server as a child process and exchanges messages through its standard input and output. It is the simplest option, with no network port and no authentication, but only that one client can use the server. With Streamable HTTP, the server runs as its own process and receives HTTP POST requests at one endpoint. Many clients can share it, on your machine or across a network, but it opens a port, and a server shared beyond your machine needs the authorization described in the MCP specification.
If you would like to Dive Deep, you can find the MCP specification right here.
Step 1: Is an MCP server just a tool in another program?
Almost. A server can offer any of the three MCP primitives we saw earlier: tools, resources and prompts. In our heroes' quest, we focus on tools. The green orb needs something to talk to, so TheWitcherish, Amagash and Tagazok build the server it will reach. They move Lady Luck's dice out of the agent and into their own file, dice_roll_mcp_server.py. They create the server with FastMCP(port=8002), put @mcp.tool() above the same roll_dice function from Part 1, and end the file with the line that starts the server:
import random
import logging
from mcp.server import FastMCP
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
mcp = FastMCP(port=8002)
@mcp.tool()
def roll_dice(faces: int = 6) -> int:
"""Roll one die with a given number of faces and return the result.
...
"""
if faces < 1:
raise ValueError("Dice must have at least 1 face")
result = random.randint(1, faces)
logging.info(f"... DICE ROLL: d{faces} = {result}")
return result
if __name__ == "__main__":
mcp.run(transport="streamable-http")
FastMCP comes from the official MCP Python SDK. Like Part 1's @tool, @mcp.tool() turns the docstring and type hints into a tool description and input schema. The function stays familiar, and only its home changes. Each roll now lands in the server's own log, giving us evidence outside the agent.
Then comes the question of how the orb will reach their server:
"Do we talk over stdio?"
"SSE?"
"I know, Streamable HTTP!"
They choose Streamable HTTP, which the server starts with transport="streamable-http".
Start the server in one terminal and leave it running:
cd ~/sample-once-upon-agentic-ai/4_mcp_integration
uv run python dice_roll_mcp_server.py
INFO - StreamableHTTP session manager started
INFO: Uvicorn running on http://127.0.0.1:8002 (Press CTRL+C to quit)
It listens on 127.0.0.1, FastMCP's default host, so only your machine can reach it. No model lives here. The server waits for clients.
Step 2: Does the server answer before any agent calls it?
This step uses Node.js to run the MCP Inspector. If node --version doesn't print a version in your terminal, install Node.js from the Node.js download page first.
Test the server first. If an agent misbehaves, you want to know whether the server or the model is to blame, so check the server alone before any model joins in. The MCP Inspector is the reference tool for testing and debugging MCP servers. It is an MCP client with no model behind it, so it shows you exactly what an agent would receive. With your MCP dice server up and running, open a second terminal.
npx @modelcontextprotocol/inspector opens the web interface, where you add the server URL http://127.0.0.1:8002/mcp with the Streamable HTTP transport. The same tool also has a command-line mode, which prints each answer as text, so the traces below come from it. First, shake hands with the server:
npx @modelcontextprotocol/inspector --cli http://127.0.0.1:8002/mcp --transport http --method initialize
{
"serverInfo": {
"name": "FastMCP",
"version": "1.30.0"
},
"protocolVersion": "2025-11-25",
"capabilities": {
...
"tools": {
"listChanged": false
}
}
}
The server announces itself, the protocol revision it speaks, and the capabilities it offers. "protocolVersion": "2025-11-25" is the revision this version of the MCP Python SDK speaks. Now ask what an agent would ask during startup, tools/list:
npx @modelcontextprotocol/inspector --cli http://127.0.0.1:8002/mcp --transport http --method tools/list
{
"tools": [
{
"name": "roll_dice",
"description": "Roll one die with a given number of faces and return the result.\n\n...faces: Number of faces on the die, 1 or more. ...",
"inputSchema": {
"type": "object",
"properties": {
"faces": {
"default": 6,
"title": "Faces",
"type": "integer"
}
},
"title": "roll_diceArguments"
},
"outputSchema": {
...
"properties": {
"result": {
"title": "Result",
"type": "integer"
}
},
...
}
}
]
}
This is the same comparison as Part 1's tool_spec, now read over the wire. The docstring became the description, the type hint became "type": "integer", and the default became "default": 6. The server also sends an outputSchema, which Part 1's local tool did not have. Look for the bound, though: "1 or more" appears only in the description text. The schema has no minimum, so the model learns the bound by reading, and the function enforces it. Call the tool once with a good value and once with a bad one:
npx @modelcontextprotocol/inspector --cli http://127.0.0.1:8002/mcp --transport http --method tools/call --tool-name roll_dice --tool-arg faces=20
npx @modelcontextprotocol/inspector --cli http://127.0.0.1:8002/mcp --transport http --method tools/call --tool-name roll_dice --tool-arg faces=0
{
"content": [
{
"type": "text",
"text": "19"
}
],
"structuredContent": {
"result": 19
},
"isError": false
}
{
"content": [
{
"type": "text",
"text": "Error executing tool roll_dice: Dice must have at least 1 face"
}
],
"isError": true
}
The dice server's terminal records both visits, and the good roll matches:
2026-11-11 15:44:58,566 - INFO - Processing request of type ListToolsRequest
2026-11-11 15:44:58,570 - INFO - Processing request of type CallToolRequest
2026-11-11 15:44:58,570 - INFO - ... DICE ROLL: d20 = 19
...
2026-11-11 15:44:59,836 - INFO - Processing request of type ListToolsRequest
2026-11-11 15:44:59,839 - INFO - Processing request of type CallToolRequest
The Inspector read the tool list before each call, the same way an agent does. faces=0 passed the schema and stopped at the if faces < 1 check, so the server returned an error result with "isError": true rather than crashing, and the Inspector exited with code 5. Write your bounds into the docstring so the model reads them, and check them in the function so the server keeps them. The server answers. Now it is time for an agent to call it.
Step 3: Does the agent need the tool's code?
No. The server address is enough. gamemaster_mcp_client.py defines an agent called gamemaster that speaks as Lady Luck, and it contains no dice implementation:
from strands import Agent
from strands.tools.mcp import MCPClient
mcp_dice_client = MCPClient(url="http://localhost:8002/mcp")
gamemaster = Agent(
system_prompt="""You are Lady Luck, the mystical keeper of dice and fortune in fantasy role-playing adventures.
...""",
tools=[mcp_dice_client]
)
gamemaster("Help me create a new fantasy character! Roll the strength, wisdom, charisma and intelligence abilities scores using 4d6 drop lowest method.")
Give MCPClient the server's url, then add it to tools. For Strands, an MCP tool is just a tool. MCPClient is a tool provider: when the agent starts, the client sends the same tools/list you just ran with the Inspector, and each tool it receives joins the agent's tool list with its name, description and input schema, exactly like a Part 1 @tool function. The model picks roll_dice, and Strands forwards the call to the server.
Of the three primitives, only tools reach the model. A server's prompts and resources stay available to your own code through the same client, with list_prompts_sync(), get_prompt_sync(), list_resources_sync() and read_resource_sync(), so you decide when to use them.
Time to roll Lady Luck's dice!
Make sure your MCP dice server is still running in its terminal. Then open another terminal and cast from there. This time the agent calls a model on Amazon Bedrock, so that terminal needs valid AWS credentials: export the same AWS_PROFILE and AWS_REGION as in the setup, and check them with aws sts get-caller-identity before you run the client:
cd ~/sample-once-upon-agentic-ai/4_mcp_integration
export AWS_PROFILE=YOUR_AWS_PROFILE AWS_REGION=YOUR_AWS_REGION
aws sts get-caller-identity
uv run python gamemaster_mcp_client.py
If aws sts get-caller-identity returns an error instead of your account and role, refresh your credentials first; otherwise the client stops at its first model call with NoCredentialsError or an expired-token error.
To see what the SDK does, reuse the logging line from the dice server at the top of gamemaster_mcp_client.py, with DEBUG instead of INFO:
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
DEBUG on the root logger also prints the AWS SDK's own requests and responses, so the output is long: search it for mcp and stop_reason. The trace follows the SDK step by step:
2026-11-12 13:41:13,578 - DEBUG - [...] transport connection established
2026-11-12 13:41:13,584 - DEBUG - [...] session initialized successfully
2026-11-12 13:41:13,591 - DEBUG - [...] received 1 tools from MCP server
2026-11-12 13:41:13,591 - DEBUG - tool_name=<roll_dice> | creating mcp agent tool
...
2026-11-12 13:41:16,639 - DEBUG - stop_reason=<tool_use> | model call succeeded, resetting retry state
...
Tool #1: roll_dice
Tool #2: roll_dice
...
Tool #16: roll_dice
The client connects, receives one tool, and wraps it as an agent tool. The model stops with stop_reason=<tool_use> and asks for sixteen rolls in one turn: four dice for each of four abilities. Lady Luck reports the first ability score, trimmed:
STRENGTH
Rolls: 3, 6, 4,2→ 3 + 6 + 4 = 13
The server log follows the same path:
INFO - Created new transport with session ID: 6b20ac77014340f8b57cbd4fa3443214
INFO - Processing request of type ListToolsRequest
INFO - Processing request of type CallToolRequest
INFO - ... DICE ROLL: d6 = 3
INFO - Processing request of type CallToolRequest
INFO - ... DICE ROLL: d6 = 6
INFO - Processing request of type CallToolRequest
INFO - ... DICE ROLL: d6 = 4
INFO - Processing request of type CallToolRequest
INFO - ... DICE ROLL: d6 = 2
...
ListToolsRequest is tools/list; each CallToolRequest is one tools/call. Before roll_dice runs, FastMCP checks the arguments against the tool's input schema with Pydantic. That is the tower's "Request Validated".
Now place the two sides next to each other. The server logged sixteen rolls. The model's next request carried sixteen tool results:
| Rolls 1 to 16 | |
|---|---|
| Server log | 3 6 4 2 · 2 1 2 4 · 5 4 1 3 · 5 4 5 6 |
| Model received | 3 6 4 2 · 2 1 4 2 · 5 4 1 3 · 5 4 5 6 |
The same sixteen values appear on both sides. Rolls 7 and 8 swapped places because Strands runs one turn's tool calls concurrently. Neighbouring results can therefore return in a different order than the server logged them.
So every number existed in the timestamped server log before the model saw it. The model retold the result; it never rolled. When its reply and the server log disagree, trust the log.
Now you try: ask Lady Luck to roll dexterity and constitution too. Then count the new DICE ROLL lines in the server log. You should find eight more.
Follow the adventurers
In Part 3, the orchestrator agent consults the Rules of our Role-Playing Game, because Tagazok may not be allowed to wield a very specific power, while Amagash learns to give her tools a shape with Structured output.
Until then, keep two habits:
- Test your MCP server before your agent does. The MCP Inspector shows what an agent will receive, with no model in the way.
- Write bounds where both sides see them. The docstring tells the model, and the check in the function holds the line.
The comic book illustrations in this blog post were created and produced by Holy Bird, based on the AWS workshop.
All rights reserved.


Top comments (1)
Would you add per-call correlation to the sixteen-roll comparison? Repeated d6 values can hide a duplicated or misassigned result. Mapping each host tool-use ID to its MCP request ID in the client trace would let the test check which call produced each result, rather than only matching the collection of numbers.