> **Building with AI coding agents?** If you're using an AI coding agent, install the official Scalekit plugin. It gives your agent full awareness of the Scalekit API — reducing hallucinations and enabling faster, more accurate code generation.
>
> - **Claude Code**: `claude plugin marketplace add scalekit-inc/claude-code-authstack && claude plugin install <auth-type>@scalekit-auth-stack`
> - **GitHub Copilot CLI**: `copilot plugin marketplace add scalekit-inc/github-copilot-authstack` then `copilot plugin install <auth-type>@scalekit-auth-stack`
> - **Codex**: run the bash installer, restart, then open Plugin Directory and enable `<auth-type>`
> - **Skills CLI** (Windsurf, Cline, 40+ agents): `npx skills add scalekit-inc/skills --list` then `--skill <skill-name>`
>
> `<auth-type>` / `<skill-name>`: `agentkit`, `full-stack-auth`, `mcp-auth`, `modular-sso`, `modular-scim` — [Full setup guide](https://docs.scalekit.com/dev-kit/build-with-ai/)

---

# 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.

Full code on GitHub

## Install

```sh
pip install crewai crewai-tools scalekit-sdk-python python-dotenv
```

## Initialize

```python

from 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.actions
```

## Connect the user to Gmail

```python
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](/agentkit/tools/authorize/) for production auth handling.

## 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:

```python
from crewai import Agent, Crew, LLM, Task
from 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)
```

> note: Nullable schema fields
>
> Some Scalekit tool schemas include nullable types (`{"type": ["string", "null"]}`) that CrewAI's schema converter doesn't handle out of the box. If you see a `TypeError` during tool parsing, apply the [schema patch](https://github.com/scalekit-developers/crewai-scalekit-example/blob/main/agent.py#L28-L43) at the top of your script.

## 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](/cookbooks/crewai-agentkit-email-triage/).

## 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](/agentkit/mcp/generate-user-urls/) for details.


---

## More Scalekit documentation

| Resource | What it contains | When to use it |
|----------|-----------------|----------------|
| [/llms.txt](/llms.txt) | Structured index with routing hints per product area | Start here — find which documentation set covers your topic before loading full content |
| [/llms-full.txt](/llms-full.txt) | Complete documentation for all Scalekit products in one file | Use when you need exhaustive context across multiple products or when the topic spans several areas |
| [sitemap-0.xml](https://docs.scalekit.com/sitemap-0.xml) | Full URL list of every documentation page | Use to discover specific page URLs you can fetch for targeted, page-level answers |
