Google ADK
Build a Google ADK agent with Scalekit-authenticated Gmail tools. Scalekit returns native ADK tool objects; no schema reshaping needed.
Build a Google ADK agent that reads a user’s Gmail inbox. Scalekit handles OAuth, token storage, and returns tools as native ADK tool objects compatible with any ADK agent.
Full code on GitHubBefore you start
Section titled “Before you start”- Create a Gmail connection in AgentKit > Connections. The samples use the connection name
gmail, so change it if yours differs. See Set up a connection. - Have the
.envfile from the Quickstart, and add your Gemini API key asGOOGLE_API_KEYto it. - The samples load
.envwithload_dotenv()frompython-dotenv.
Install
Section titled “Install”pip install scalekit-sdk-python python-dotenv "google-adk>=2,<3"Initialize
Section titled “Initialize”import osimport asyncioimport scalekit.clientfrom dotenv import load_dotenv
load_dotenv()
scalekit_client = scalekit.client.ScalekitClient( client_id=os.getenv("SCALEKIT_CLIENT_ID"), client_secret=os.getenv("SCALEKIT_CLIENT_SECRET"), env_url=os.getenv("SCALEKIT_ENVIRONMENT_URL"),)actions = scalekit_client.actionsConnect the user to Gmail
Section titled “Connect the user to Gmail”# Connect the user's Gmail account, and wait until it's ACTIVE before calling toolsconnection_name = "gmail"identifier = "user_123" # your app's unique user ID
response = actions.get_or_create_connected_account( connection_name=connection_name, identifier=identifier)if response.connected_account.status != "ACTIVE": link = actions.get_authorization_link( connection_name=connection_name, identifier=identifier ) print("Authorize Gmail:", link.link) input("Press Enter after authorizing...") # Fetch the account again to pick up the new status response = actions.get_or_create_connected_account( connection_name=connection_name, identifier=identifier )
if response.connected_account.status != "ACTIVE": raise RuntimeError( f"Gmail is {response.connected_account.status}, not ACTIVE. Authorize it and run again." )See Authorize a user for production auth handling.
Build and run the agent
Section titled “Build and run the agent”actions.google.get_tools() returns native ADK tool objects. Pass them directly to a Google ADK Agent:
from google.adk.agents import Agentfrom google.adk.runners import Runnerfrom google.adk.sessions import InMemorySessionServicefrom google.genai import types
tools = actions.google.get_tools( identifier="user_123", connection_names=["gmail"], page_size=100, # avoid missing tools when a connector has more than the default page)
agent = Agent( name="gmail_assistant", model="gemini-2.0-flash", instruction="You are a helpful Gmail assistant.", tools=tools,)
async def main(): session_service = InMemorySessionService() runner = Runner(agent=agent, app_name="gmail_app", session_service=session_service) session = await session_service.create_session(app_name="gmail_app", user_id="user_123")
message = types.Content( role="user", parts=[types.Part(text="Fetch my last 5 unread emails and summarize them")], ) async for event in runner.run_async( user_id="user_123", session_id=session.id, new_message=message, ): if event.is_final_response() and event.content and event.content.parts: print(event.content.parts[0].text)
asyncio.run(main())Use MCP instead
Section titled “Use MCP instead”Google ADK connects to MCP servers with McpToolset. Pass the Virtual MCP server URL and a session token for this user:
import osfrom datetime import timedeltafrom google.adk.agents import Agentfrom google.adk.tools.mcp_tool import McpToolset, StreamableHTTPConnectionParams
# Returned by create_config when you created the Virtual MCP serverconfig_id = os.environ["SCALEKIT_MCP_CONFIG_ID"]mcp_url = os.environ["SCALEKIT_MCP_SERVER_URL"]
# Mint a fresh session token for this user before each agent runmcp_token = actions.mcp.create_session_token( mcp_config_id=config_id, identifier="user_123", expiry=timedelta(hours=1),).token
agent = Agent( name="gmail_assistant", model="gemini-2.0-flash", instruction="You are a helpful Gmail assistant.", tools=[ McpToolset( connection_params=StreamableHTTPConnectionParams( url=mcp_url, headers={"Authorization": f"Bearer {mcp_token}"}, ) ) ],)Run this agent with the same Runner loop as above. See Create a Virtual MCP server and Mint session tokens to create the server, check the user’s connections and mint a token.
API reference
The endpoints this page's code calls, with every field and the SDK method for each: