CrewAI
Build a CrewAI agent with Scalekit-authenticated Gmail tools via MCP. CrewAI's MCPServerAdapter connects to a Scalekit MCP URL for automatic tool discovery.
Build a CrewAI agent that reads a user’s Gmail inbox. Scalekit handles OAuth, token storage, and exposes tools over MCP. CrewAI’s MCPServerAdapter discovers the tools automatically — no manual schema conversion needed.
Install
Section titled “Install”pip install crewai crewai-tools scalekit-sdk-python python-dotenvInitialize
Section titled “Initialize”import osimport scalekit.clientfrom dotenv import find_dotenv, load_dotenv
load_dotenv(find_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_ENV_URL"),)actions = scalekit_client.actionsConnect the user to Gmail
Section titled “Connect the user to Gmail”response = actions.get_or_create_connected_account( connection_name="gmail", identifier="user_123",)if response.connected_account.status != "ACTIVE": link = actions.get_authorization_link(connection_name="gmail", identifier="user_123") print("Authorize Gmail:", link.link) input("Press Enter after authorizing...")See Authorize a user for production auth handling.
Build and run the agent
Section titled “Build and run the agent”Generate a per-user MCP URL, then pass it to MCPServerAdapter. CrewAI discovers all available Gmail tools from the MCP server:
from crewai import Agent, Crew, LLM, Taskfrom crewai_tools import MCPServerAdapter
inst_response = actions.mcp.ensure_instance( config_name=os.getenv("SCALEKIT_MCP_CONFIG_NAME", "gmail-user-tools"), user_identifier="user_123",)mcp_url = inst_response.instance.url
with MCPServerAdapter({"url": mcp_url, "transport": "streamable-http"}) as tools: agent = Agent( role="Email Assistant", goal="Fetch and summarize the user's unread emails", backstory="You are a helpful assistant with access to the user's Gmail inbox.", tools=tools, llm=LLM( model=os.getenv("LLM_MODEL", "gpt-4o"), base_url=os.getenv("OPENAI_BASE_URL"), api_key=os.getenv("OPENAI_API_KEY"), ), verbose=True, )
task = Task( description="Fetch the last 5 unread emails and provide a brief summary of each.", expected_output="A list of 5 unread emails with subject, sender, and a one-sentence summary.", agent=agent, )
result = Crew(agents=[agent], tasks=[task]).kickoff() print(result)Multi-agent crew
Section titled “Multi-agent crew”CrewAI’s real strength is multi-agent orchestration. For a full example that splits email triage across three specialized agents (scanner, prioritizer, drafter), see the CrewAI email triage cookbook.
Generate the MCP URL
Section titled “Generate the MCP URL”The ensure_instance call above requires an MCP config that includes Gmail tools. Create one in the Scalekit Dashboard under AgentKit → MCP Configs. See Generate user MCP URLs for details.