> ## Documentation Index
> Fetch the complete documentation index at: https://docs.callintel.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Gmail Integration

> Integrate Gmail with CallIntel agents using the Model Context Protocol (MCP). The Gmail integration allows your AI agents to interact with Gmail accounts. It is built as a Model Context Protocol (MCP) server, enabling agents to send emails and manage authentication.

## Features

* **Send Emails**: Agents can send emails on behalf of the user.
* **Organization Support**: Support for organization-wide email accounts.
* **Multi-Agent Support**: Multiple agents can be authenticated with different Gmail accounts.
* **Authentication**: Secure OAuth2 authentication with Google.

## Setup

### Prerequisites

1. **Google Cloud Project**: You need a Google Cloud Project with the Gmail API enabled.
2. **Credentials**: Create OAuth 2.0 credentials (Client ID and Client Secret) and download the `credentials.json` file.
3. **Environment Variables**: Ensure the `Environment` variable is set correctly (`production` or `local`).

### Installation

The Gmail MCP server is located in `integrations/mcp_gmail`.

1. Place your `credentials.json` file in the `integrations/mcp_gmail` directory.
2. Install dependencies (if not already installed):
   ```bash theme={null}
   pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client
   ```

## Usage

### Authentication

Agents need to be authenticated before they can send emails.

1. **Agent Authentication**:
   Navigate to the dashboard (default: `http://localhost:8101/`) or use the authentication URL:
   ```
   /auth/google?agent_id={agent_id}
   ```
   Replace `{agent_id}` with the ID of the agent you want to authenticate.

2. **Organization Authentication**:
   For organization-wide access:
   ```
   /auth/google/org?org_id={org_id}
   ```

### Available Tools

The MCP server exposes the following tools to the agents:

#### `send_email`

Sends an email from the authenticated agent's account.

* **Arguments**:
  * `agent_id` (string): The ID of the agent sending the email.
  * `to` (string): The recipient's email address.
  * `subject` (string): The subject of the email.
  * `body` (string): The body of the email.

#### `send_email_org`

Sends an HTML email from the authenticated organization's account.

* **Arguments**:
  * `org_id` (string): The ID of the organization.
  * `to` (string): The recipient's email address.
  * `subject` (string): The subject of the email.
  * `body` (string): The HTML body of the email.

#### `get_agent_status`

Checks the authentication status of an agent.

* **Arguments**:
  * `agent_id` (string): The ID of the agent.

### Dashboard

The Gmail MCP server provides a web dashboard for managing authentications.

* **URL**: `http://localhost:8101/` (or your deployed URL)
* **Features**:
  * List registered agents and their status.
  * Authenticate new agents.
  * Test MCP connection.
  * Delete agent credentials.

## Architecture

The integration uses the `fastmcp` library to expose tools. It manages Google OAuth2 tokens, refreshing them automatically when expired. Credentials and tokens are stored in Supabase via the `McpService`.

### Key Files

* `mcp_server.py`: The main server file containing tool definitions and OAuth logic.
* `mcp_client.py`: Client for testing or interacting with the server.
* `credentials.json`: Google OAuth credentials.
