Client
Launch a local FastMCP server by command and connect an agent to it with MCPTools.
"""
Client
=============================
Demonstrates client.
"""
import asyncio
from agno.agent import Agent
from agno.models.groq import Groq
from agno.tools.mcp import MCPTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
async def run_agent(message: str) -> None:
# Initialize the MCP server
async with (
MCPTools(
"fastmcp run cookbook/91_tools/mcp/local_server/server.py", # Supply the command to run the MCP server
) as mcp_tools,
):
agent = Agent(
model=Groq(id="openai/gpt-oss-120b"),
tools=[mcp_tools],
markdown=True,
)
await agent.aprint_response(message, stream=True)
# Example usage
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
asyncio.run(run_agent("What is the weather in San Francisco?"))Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[mcp]" groqExport your Groq API key
export GROQ_API_KEY="your_groq_api_key_here"Save the sibling server
Open the sibling Server example and save its code as server.py beside client.py. In the saved client, replace fastmcp run cookbook/91_tools/mcp/local_server/server.py with fastmcp run server.py.
Run the client from that directory. It starts and closes the stdio server itself; no separate server terminal is needed. The weather tools return fixed demonstration responses.
Run the example
Save the code above as client.py, then run:
python client.pyFull source: cookbook/91_tools/mcp/local_server/client.py