In this section, you’ll learn how to set up an AI Agent on your development machine. You will then connect your MCP server running on the Raspberry Pi 5 to it.
These commands were tested on a Linux Arm development machine.
uv
on your development machine:
curl -LsSf https://astral.sh/uv/install.sh | sh
mkdir mcp-agent && cd mcp-agent
uv
:
uv init
This command adds:
uv add openai-agents python-dotenv
.env
file to securely store your OpenAI API key:
echo -n "OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>" > .env
Use a file editor of your choice and replace the content of the sample main.py
with the content shown below:
import asyncio, os
from dotenv import load_dotenv
# disable Agents SDK tracing for cleaner output
os.environ["OPENAI_AGENTS_DISABLE_TRACING"] = "1"
load_dotenv()
from agents import Agent, Runner, set_default_openai_key
from agents.mcp import MCPServerSse
from agents.model_settings import ModelSettings
async def run(mcp_server: list[MCPServerSse]):
set_default_openai_key(os.getenv("OPENAI_API_KEY"))
agent = Agent(
model="gpt-4.1-2025-04-14",
name="Assistant",
instructions="Use the tools to answer the user's query",
mcp_servers=mcp_server,
model_settings=ModelSettings(tool_choice="required"),
)
for message in ["What is the CPU temperature?", "How is the weather in Cambridge?"]:
print(f"Running: {message}")
result = await Runner.run(starting_agent=agent, input=message)
print(f"Response: {result.final_output}")
async def main():
# replace URL with your ngrok-generated endpoint
url = "<YOUR_NGROK_URL>/sse"
async with MCPServerSse(
name="RPI5 MCP Server",
params={"url": url},
client_session_timeout_seconds=60,
) as server1:
await run([server1])
if __name__ == "__main__":
asyncio.run(main())
You’re now ready to run the AI Agent and test its connection to your running MCP server on the Raspberry Pi 5.
Run the main.py
Python script:
uv run main.py
The output should look something like this:
Running: What is the CPU temperature?
Response: The current CPU temperature is 48.8°C.
Running: How is the weather in Cambridge?
The weather in Cambridge is currently partly cloudy with a temperature of around 10°C. The wind is blowing at approximately 17 km/h. Visibility is good at 10 km, and there is no precipitation expected at the moment. The weather should be pleasant throughout the day with temperatures rising to about 15°C by midday.
Congratulations! Your local AI Agent just called the MCP server on your Raspberry Pi and fetched the CPU temperature and the weather information.
This lightweight protocol isn’t just a game-changer for LLM developers—it also empowers IoT engineers to transform real-world data streams and give AI direct, reliable control over any connected device.
Expand Your Toolset
@mcp.tool()
functions for Pi peripherals (such as GPIO pins, camera, and I²C sensors).Integrate with IoT Platforms
You’ve now built and run an AI agent on your development machine that connects to an MCP server on your Raspberry Pi 5. Your agent can now interact with real-world data sources in real time — a complete edge-to-cloud loop powered by OpenAI’s Agent SDK and the MCP protocol.