Prerequisites
Before we begin, you’ll need:
Installation
First, install the required packages:
pip install openai klavis agno
Setup Environment Variables
import os
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY" # Replace with your actual OpenAI API key
os.environ["KLAVIS_API_KEY"] = "YOUR_KLAVIS_API_KEY" # Replace with your actual Klavis API key
Step 1 - Create Strata MCP Server with Gmail and Slack
import webbrowser
from klavis import Klavis
from klavis.types import McpServerName, ToolFormat
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
response = klavis_client.mcp_server.create_strata_server(
servers=[McpServerName.GMAIL, McpServerName.SLACK],
user_id="1234"
)
# Handle OAuth authorization for each services
if response.oauth_urls:
for server_name, oauth_url in response.oauth_urls.items():
webbrowser.open(oauth_url)
print(f"Or please open this URL to complete {server_name} OAuth authorization: {oauth_url}")
OAuth Authorization Required: The code above will open browser windows for each service. Click through the OAuth flow to authorize access to your accounts.
Step 2 - Create method to use MCP Server with Claude
This method handles multiple rounds of tool calls until a final response is ready.
import json
import asyncio
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mcp import MCPTools
async def agno_with_mcp_server(mcp_server_url: str, user_query: str):
"""Run an Agno agent with Klavis MCP server tools."""
async with MCPTools(transport="streamable-http", url=mcp_server_url) as mcp_tools:
agent = Agent(
model=OpenAIChat(
id="gpt-4o",
api_key=os.getenv("OPENAI_API_KEY")
),
instructions="You are a helpful AI assistant.",
tools=[mcp_tools],
markdown=True,
)
response = await agent.arun(user_query)
return response.content
Step 3 - Run!
async def main():
result = await agno_with_mcp_server(
mcp_server_url=response.strata_server_url,
user_query="Check my latest 5 emails and summarize them in a Slack message to #general"
)
print(f"\nFinal Response: {result}")
if __name__ == "__main__":
asyncio.run(main())
Perfect! You’ve integrated Agno with Klavis MCP servers.
Next Steps
Useful Resources
Happy building! 🚀