Skip to main content

Prerequisites

Before we begin, you’ll need:

OpenAI API Key

Get your API key from OpenAI Console

Klavis AI API Key

Get your API key from Klavis AI

Installation

First, install the required packages:
pip install openai klavis agno
npm install @agno/sdk klavis

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
import Anthropic from '@anthropic-ai/sdk';
import { KlavisClient, Klavis } from 'klavis';

// Set environment variables
process.env.OPENAI_API_KEY = "YOUR_OPENAI_API_KEY";  // Replace with your actual OpenAI API key
process.env.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}")
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });

const response = await klavisClient.mcpServer.createStrataServer({
    servers: [Klavis.McpServerName.Gmail, Klavis.McpServerName.Slack],
    userId: "1234"
});

// Handle OAuth authorization for each services
if (response.oauthUrls) {
    for (const [serverName, oauthUrl] of Object.entries(response.oauthUrls)) {
        window.open(oauthUrl);
        // Wait for user to complete OAuth
        await new Promise(resolve => {
            const input = prompt(`Press OK after completing ${serverName} OAuth authorization...`);
            resolve(input);
        });
    }
}

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
import { Agent } from '@agno/sdk';
import { OpenAI } from '@agno/sdk/models/openai';
import { MCPTools } from '@agno/sdk/tools/mcp';


async function agnoWithMcpServer(mcpServerUrl: string, userQuery: string): Promise<string> {
    const mcpTools = new MCPTools({
        transport: "streamable-http",
        url: mcpServerUrl
    });

    const agent = new Agent({
        model: new OpenAI({
            id: "gpt-4o",
            apiKey: process.env.OPENAI_API_KEY
        }),
        instructions: "You are a helpful AI assistant.",
        tools: [mcpTools],
        markdown: true
    });

    const response = await agent.run(userQuery);
    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())
async function main() {
    const result = await agnoWithMcpServer(
        response.strataServerUrl,
        "Check my latest 5 emails and summarize them in a Slack message to #general"
    );
    console.log(`\nFinal Response: ${result}`);
}

main().catch(console.error);
Perfect! You’ve integrated Agno with Klavis MCP servers.

Next Steps

Integrations

Explore available MCP servers

API Reference

REST endpoints and schemas

Useful Resources

Happy building! 🚀