Integrating a Simple MCP Weather Server with Llama Stack
Goal
In this module, you’ll use a simple weather MCP server and integrate it with Llama Stack. This exercise demonstrates how to expose custom services that can be invoked by agents inside the Llama Stack environment. By the end of this module, you’ll understand how to register an MCP server and make agentic calls to retrieve real-time weather information.
Prerequisites
-
Llama Stack server running (see: Llama-stack Helloworld)
-
Python 3.10+ installed on your local machine
-
Python virtual environment setup and activated (see: Llama-stack Helloworld)
Step 1: Run a simple weather MCP server
We’ll use Podman to run a pre-built Weather MCP server container.
This launches the Weather MCP server and makes it available at http://localhost:3001/sse.
Step 2: Register the MCP Server in Llama Stack
To allow Llama Stack to interact with the weather server, register it as a toolgroup:
curl -X POST -H "Content-Type: application/json"
--data
'{ "provider_id" : "model-context-protocol", "toolgroup_id" : "mcp::weather", "mcp_endpoint" : { "uri" : "http://localhost:3001/sse"}}'
http://localhost:8321/v1/toolgroups
curl -X POST -H "Content-Type: application/json"
--data
'{ "provider_id" : "model-context-protocol", "toolgroup_id" : "mcp::weather", "mcp_endpoint" : { "uri" : "http://host.containers.internal:3001/sse"}}'
http://localhost:8321/v1/toolgroups
This step tells Llama Stack that your local weather server is available under the toolgroup ID mcp::weather.
Step 3: Query the Weather Tool via Llama Stack
Now, test the integration by creating a Python script that uses the Llama Stack client SDK to ask for the weather.
Run this command to create a file called test_weather.py:
cat << 'EOF' > test_weather.py
from llama_stack_client.lib.agents.event_logger import EventLogger
base_url = "http://localhost:8321"
from llama_stack_client import LlamaStackClient
client = LlamaStackClient(
base_url=base_url
)
model = "meta-llama/Llama-3.2-3B-Instruct"
# System prompt configures the assistant behavior
sys_prompt1 = """You are a helpful assistant. Use tools to answer. When you use a tool always respond with a summary of the result."""
from llama_stack_client import Agent
# Create an agent that will use the weather toolgroup
agent = Agent(
client,
model=model,
instructions=sys_prompt1,
tools=["mcp::weather"], # Use the toolgroup we registered earlier
tool_config={"tool_choice": "auto"},
)
user_prompts = ["What's the weather in Seattle?"]
session_id = agent.create_session(session_name="weather_demo")
for prompt in user_prompts:
turn_response = agent.create_turn(
messages=[
{
"role": "user",
"content": prompt
}
],
session_id=session_id,
stream=True,
)
for log in EventLogger().log(turn_response):
log.print()
EOF
This script sets up a Llama Stack agent with access to the weather toolgroup and submits the prompt, “What’s the weather in New York?”
Step 4: Run the Test
Install the Llama Stack Client SDK:
pip install llama-stack-client==0.2.2
Then run the script:
python test_weather.py
Expected output (example):
inference> [getforecast(latitude='47.6067', longitude='-122.3321')]
tool_execution> Tool:getforecast Args:{'latitude': '47.6067', 'longitude': '-122.3321'}
tool_execution> Tool:getforecast Response:{"type":"text","text":"Forecast for 47.6067, -122.3321:\n\nOvernight:\nTemperature: 45°F\nWind: 1 mph NNE\nPartly Cloudy\n---\nFriday:\nTemperature: 68°F\nWind: 1 to 6 mph NNW\nPartly Sunny\n---\nFriday Night:\nTemperature: 50°F\nWind: 2 to 6 mph NE\nMostly Cloudy\n---\nSaturday:\nTemperature: 64°F\nWind: 2 to 6 mph S\nMostly Cloudy\n---\nSaturday Night:\nTemperature: 48°F\nWind: 6 mph SSW\nMostly Cloudy then Chance Rain Showers\n---\nSunday:\nTemperature: 63°F\nWind: 6 mph SSW\nChance Rain Showers\n---\nSunday Night:\nTemperature: 48°F\nWind: 2 to 6 mph SSW\nChance Rain Showers\n---\nMonday:\nTemperature: 61°F\nWind: 5 mph WSW\nChance Rain Showers\n---\nMonday Night:\nTemperature: 49°F\nWind: 5 mph SSW\nMostly Cloudy\n---\nTuesday:\nTemperature: 65°F\nWind: 7 mph S\nPartly Sunny\n---\nTuesday Night:\nTemperature: 50°F\nWind: 7 mph SSW\nMostly Cloudy\n---\nWednesday:\nTemperature: 63°F\nWind: 6 mph SSW\nMostly Cloudy\n---\nWednesday Night:\nTemperature: 49°F\nWind: 6 mph SSW\nMostly Cloudy\n---\nThursday:\nTemperature: 63°F\nWind: 5 mph SSW\nPartly Sunny\n---","annotations":null}
inference> The current weather in Seattle is partly cloudy with a temperature of 45°F overnight, and it's expected to be mostly sunny on Tuesday with a high of 65°F. There's also a chance of rain showers on Sunday and Monday.
Summary
In this module, you:
Deployed a Weather MCP server using Podman
Registered it in Llama Stack as a toolgroup
Queried the tool using a natural language prompt in a Python agent
This setup enables you to expose real-world data to AI agents with minimal effort, demonstrating tool use using MCP and Llama Stack.