Skip to main content
Google ADK and Klavis Integration - Build AI agents with MCP tools
You can find the complete example code in Klavis GitHub repository here ->

Prerequisites

Before we begin, you’ll need: Google API key and Klavis API key.

Installation

First, install the required packages:
pip install google-adk klavis

Setup Environment Variables

import os
from dotenv import load_dotenv

load_dotenv()

os.environ["KLAVIS_API_KEY"] = "YOUR_KLAVIS_API_KEY"  # Replace

Step 1 - Create an Agent Project

Run the ADK create command to start a new agent project:
adk create my_agent
This will create the following project structure:
my_agent/
    agent.py      # main agent code
    .env          # API keys or project IDs
    __init__.py

Step 2 - Configure Agent with Klavis MCP

The agent.py file contains a root_agent definition which is the only required element of an ADK agent. Update your agent.py to integrate Klavis MCP servers:
import os
import webbrowser

from google.adk.agents.llm_agent import Agent
from google.adk.tools.mcp_tool import StreamableHTTPConnectionParams
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
from klavis import Klavis
from klavis.types import McpServerName

from dotenv import load_dotenv
load_dotenv()

KLAVIS_API_KEY = os.getenv("KLAVIS_API_KEY")

# Initialize Klavis and set up Strata server
klavis_client = Klavis(api_key=KLAVIS_API_KEY)

user_id = "user_123"

# Create Strata server with multiple MCP servers
strata_response = klavis_client.mcp_server.create_strata_server(
    servers=[McpServerName.GMAIL, McpServerName.SLACK],
    user_id=user_id
)

# Handle OAuth authentication
if strata_response.oauth_urls:
    for server_name, oauth_url in strata_response.oauth_urls.items():
        user_integration_auth = klavis_client.user.get_user_auth(
            user_id=user_id,
            server_name=server_name
        )
        if not user_integration_auth.is_authenticated:
            print(f"🔐 Opening OAuth for {server_name}...")
            webbrowser.open(oauth_url)
            input(f"Press Enter after completing {server_name} OAuth authorization...")

mcp_server_url = strata_response.strata_server_url

# Create AI agent with MCP toolset (exposed at module level for ADK)
root_agent = Agent(
    name="my_agent",
    model="gemini-2.5-flash",
    description="An agent with access to tools through Klavis MCP",
    instruction="You are a helpful assistant with access to MCP tools.",
    tools=[
        McpToolset(
            connection_params=StreamableHTTPConnectionParams(
                url=mcp_server_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 3 - Run Your Agent

Launch the web interface to interact with your agent:
adk web
This will start a local web server where you can chat with your agent and watch it use the Gmail and Slack MCP tools.
Perfect! You’ve integrated Google ADK with Klavis MCP servers.

Next Steps

Useful Resources

Happy building! 🚀
I