# How to integrate Gmail MCP with Claude Code

```json
{
  "title": "How to integrate Gmail MCP with Claude Code",
  "toolkit": "Gmail",
  "toolkit_slug": "gmail",
  "framework": "Claude Code",
  "framework_slug": "claude-code",
  "url": "https://composio.dev/toolkits/gmail/framework/claude-code",
  "markdown_url": "https://composio.dev/toolkits/gmail/framework/claude-code.md",
  "updated_at": "2026-11-04T07:07:50.381Z"
}
```

## Introduction

Manage your Gmail directly from Claude Code with zero worries about OAuth hassles, API-breaking issues, or reliability and security concerns.
You can do this in two different ways:
- Via [Composio Connect](https://dashboard.composio.dev/login?cta_placement=toolkit-framework-claude-code-composio-connect&next=%2F~%2Forg%2Fconnect%2Fclients%2Fclaude-code) - Direct and easiest approach
- Via [Composio SDK](https://docs.composio.dev/docs?cta_placement=toolkit-framework-claude-code-composio-sdk) - Programmatic approach with more control
For exact tool slugs and parameter tables, see the [tool catalog in the Composio docs](https://docs.composio.dev/toolkits/gmail).

## Also integrate Gmail with

- [Cursor](https://composio.dev/toolkits/gmail/framework/cursor)
- [ChatGPT](https://composio.dev/toolkits/gmail/framework/chatgpt)
- [Claude Cowork](https://composio.dev/toolkits/gmail/framework/claude-cowork)
- [Antigravity](https://composio.dev/toolkits/gmail/framework/antigravity)
- [OpenAI Agents SDK](https://composio.dev/toolkits/gmail/framework/open-ai-agents-sdk)
- [Claude Agent SDK](https://composio.dev/toolkits/gmail/framework/claude-agents-sdk)
- [Grok Bot](https://composio.dev/toolkits/gmail/framework/grok-bot)
- [Muse](https://composio.dev/toolkits/gmail/framework/muse)
- [Codex](https://composio.dev/toolkits/gmail/framework/codex)
- [Kimi Code](https://composio.dev/toolkits/gmail/framework/kimi)
- [Grok Build](https://composio.dev/toolkits/gmail/framework/grok-build)
- [VS Code](https://composio.dev/toolkits/gmail/framework/vscode)
- [OpenCode](https://composio.dev/toolkits/gmail/framework/opencode)
- [OpenClaw](https://composio.dev/toolkits/gmail/framework/openclaw)
- [Hermes](https://composio.dev/toolkits/gmail/framework/hermes-agent)
- [Atomic Agent](https://composio.dev/toolkits/gmail/framework/atomic-agent)
- [Pi](https://composio.dev/toolkits/gmail/framework/pi-agent)
- [DeepSeek Harness](https://composio.dev/toolkits/gmail/framework/deepseek)
- [CLI](https://composio.dev/toolkits/gmail/framework/cli)
- [Google ADK](https://composio.dev/toolkits/gmail/framework/google-adk)
- [LangChain](https://composio.dev/toolkits/gmail/framework/langchain)
- [Vercel AI SDK](https://composio.dev/toolkits/gmail/framework/ai-sdk)
- [Mastra AI](https://composio.dev/toolkits/gmail/framework/mastra-ai)
- [LlamaIndex](https://composio.dev/toolkits/gmail/framework/llama-index)
- [CrewAI](https://composio.dev/toolkits/gmail/framework/crew-ai)
- [Pydantic AI](https://composio.dev/toolkits/gmail/framework/pydantic-ai)
- [AutoGen](https://composio.dev/toolkits/gmail/framework/autogen)

## TL;DR

- Only one MCP URL to connect multiple apps with Claude Code with zero auth hassles.
- Programmatic tool calling allows LLMs to write its code in a remote workbench to handle complex tool chaining. Reduces to-and-fro with LLMs for frequent tool calling.
- Handling Large tool responses out of LLM context to minimize context rot.
- Dynamic just-in-time access to 20,000 tools across 1700+ other Apps for cross-app workflows. It loads the tools you need, so LLMs aren't overwhelmed by tools you don't need.

## Connect Gmail to Claude Code

### Connecting Gmail to Claude Code using Composio
1. Add the Composio MCP to Claude

```bash
claude mcp add --scope user --transport http composio https://connect.composio.dev/mcp
```

## What is Claude Code?

Claude Code is Anthropic's command line developer tool that lets you use Claude directly inside your terminal. Instead of switching between your editor, browser, and chat, you can stay in your project folder and ask Claude to help you build, debug, refactor, and understand code right where you're working.
Key features include:
- Terminal-Native Experience: Work with Claude directly in your command line without switching contexts
- MCP Support: Built-in support for Model Context Protocol servers to extend Claude's capabilities
- Project Context: Claude understands your project structure and can read, write, and modify files
- Interactive Development: Ask questions, debug code, and get help in real-time while coding
- Multi-Platform: Works on macOS, Linux, WSL, and Windows

## What is the Gmail MCP server, and what's possible with it?

The Gmail MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Gmail account. It provides structured and secure access to your email, drafts, attachments, labels, and contacts, so your agent can read messages, send emails, manage drafts, organize your inbox, and handle conversations on your behalf.
- Email search and reading: Instruct your agent to find emails using filters, read complete messages, and retrieve specific attachments.
- Drafting and sending: Have your agent create, update, review, send, or delete drafts, and send new emails from your Gmail account.
- Replies and conversation management: Let the agent reply within existing email threads and move conversations to or from the trash.
- Inbox and label organization: Direct your agent to modify labels across multiple messages and update the properties of existing Gmail labels.
- Contact and account lookup: Have your agent search contacts by personal or workplace details and identify the connected Gmail account.

## Supported Tools

| Tool slug | Name | Description |
|---|---|---|
| `GMAIL_ADD_LABEL_TO_EMAIL` | Modify email labels | Adds and/or removes specified Gmail labels for a message; ensure `message_id` and all `label_ids` are valid (use 'listLabels' for custom label IDs). |
| `GMAIL_BATCH_DELETE_MESSAGES` | Batch delete Gmail messages | Permanently deletes multiple Gmail messages by ID, bypassing Trash. A successful request does not confirm individual messages existed or were deleted. |
| `GMAIL_BATCH_MODIFY_MESSAGES` | Batch modify Gmail messages | Adds or removes labels on up to 1,000 Gmail messages in one request, supporting operations such as archiving and marking messages read or unread. A successful response confirms request acceptance, not individual message status. |
| `GMAIL_CREATE_EMAIL_DRAFT` | Create email draft | Creates a Gmail draft with optional recipients, subject, plain or HTML body, attachments, and threading. When a requested thread cannot be fetched, the draft is created without threading; a provided subject is used instead of the thread subject. |
| `GMAIL_CREATE_FILTER` | Create Gmail filter | Tool to create a new Gmail filter with specified criteria and actions. Use when the user wants to automatically organize incoming messages based on sender, subject, size, or other criteria. Note: you can only create a maximum of 1,000 filters per account. |
| `GMAIL_CREATE_LABEL` | Create label | Creates a Gmail label and returns its label ID. For nested labels, it may create missing parent labels; on a name conflict it attempts to return the existing matching label. |
| `GMAIL_DELETE_DRAFT` | Delete Draft | Permanently deletes a specific Gmail draft using its ID with no recovery possible; verify the correct `draft_id` and obtain explicit user confirmation before calling. Ensure the draft exists and the user has necessary permissions for the given `user_id`. |
| `GMAIL_DELETE_FILTER` | Delete Gmail filter | Tool to permanently delete a Gmail filter by its ID. Use when you need to remove an existing email filtering rule. |
| `GMAIL_DELETE_LABEL` | Delete label from account (permanent) | Permanently DELETES a user-created Gmail label from the account (not from a message). WARNING: This action DELETES the label definition itself, removing it from all messages. System labels (INBOX, SENT, UNREAD, etc.) cannot be deleted. To add/remove labels from specific messages, use GMAIL_ADD_LABEL_TO_EMAIL action instead. |
| `GMAIL_DELETE_MESSAGE` | Delete message | Permanently deletes a specific email message by its ID from a Gmail mailbox; for `user_id`, use 'me' for the authenticated user or an email address to which the authenticated user has delegated access. |
| `GMAIL_DELETE_THREAD` | Delete thread | Tool to immediately and permanently delete a specified thread and all its messages. This operation cannot be undone. Use threads.trash instead for reversible deletion. |
| `GMAIL_FETCH_EMAILS` | Fetch emails | Lists Gmail messages with query and label filtering, pagination, and optional message details. Individual detail fetches returning 404, 429, or 503 are skipped, so a page can contain fewer messages than the list result. |
| `GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID` | Fetch message by message ID | Fetches a Gmail message by its message ID in the requested format and returns formatted message details. Available fields depend on the format. |
| `GMAIL_FETCH_MESSAGE_BY_THREAD_ID` | Fetch Message by Thread ID | Retrieves messages from an accessible Gmail thread by thread ID, returning thread details and a messages array. Message order is not guaranteed; use messageTimestamp to identify oldest or newest messages and labelIds to filter drafts. |
| `GMAIL_FORWARD_MESSAGE` | Forward email message | Forwards an existing Gmail message to specified recipients, with optional additional text. The tool copies original message parts into a new message, but may alter MIME structure and attachment metadata. |
| `GMAIL_GET_ATTACHMENT` | Get Gmail attachment | Retrieves a Gmail message attachment by message and attachment IDs and returns a downloadable file using the supplied filename. |
| `GMAIL_GET_AUTO_FORWARDING` | Get Auto-Forwarding Settings | Tool to get the auto-forwarding setting for the specified account. Use when you need to retrieve the current auto-forwarding configuration including enabled status, forwarding email address, and message disposition. |
| `GMAIL_GET_CONTACTS` | Get contacts | Lists saved Google contacts with selectable fields and pagination, optionally including Other Contacts. Other Contacts are fetched on the first page; endpoint failures can result in partial results, and contact records may be sparse. |
| `GMAIL_GET_DRAFT` | Get Draft | Retrieves a single Gmail draft by its ID. Use this to fetch and inspect draft content before sending via GMAIL_SEND_DRAFT. The format parameter controls the level of detail returned. |
| `GMAIL_GET_FILTER` | Get Gmail filter | Tool to retrieve a specific Gmail filter by its ID. Use when you need to inspect the criteria and actions of an existing filter. |
| `GMAIL_GET_LABEL` | Get label details | Gets details for a specified Gmail label. Use this to retrieve label information including name, type, visibility settings, message/thread counts, and color. |
| `GMAIL_GET_LANGUAGE_SETTINGS` | Get Language Settings | Tool to retrieve the language settings for a Gmail user. Use when you need to determine the display language preference for the authenticated user or a specific Gmail account. |
| `GMAIL_GET_PEOPLE` | Get People | Retrieves a person's details by resource name or lists the authenticated user's Other Contacts, using a field mask to select the information returned. Other Contacts can be paginated and queried using a sync token for changes since a previous sync. |
| `GMAIL_GET_PROFILE` | Get Profile | Retrieves Gmail profile information (email address, aggregate messagesTotal/threadsTotal, historyId) for a user. messagesTotal counts individual emails; threadsTotal counts conversations; neither is per-label — use GMAIL_FETCH_EMAILS with label filters for label-specific counts. The returned historyId seeds incremental sync via GMAIL_LIST_HISTORY; if historyIdTooOld is returned, rescan with GMAIL_FETCH_EMAILS before resuming. Response may be wrapped under a top-level data field; unwrap before reading fields. A successful call confirms mailbox connectivity but not full mailbox access if granted scopes are narrow. Use the returned email address to dynamically identify the authenticated account rather than hard-coding it. |
| `GMAIL_GET_VACATION_SETTINGS` | Get Vacation Settings | Tool to retrieve vacation responder settings for a Gmail user. Use when you need to check if out-of-office auto-replies are configured and view their content. |
| `GMAIL_IMPORT_MESSAGE` | Import message | Tool to import a message into the user's mailbox with standard email delivery scanning and classification. Use when you need to add an existing email to a Gmail account without sending it through SMTP. This method doesn't perform SPF checks, so it might not work for some spam messages. |
| `GMAIL_INSERT_MESSAGE` | Insert message into mailbox | Tool to insert a message into the user's mailbox similar to IMAP APPEND. Use when you need to add an email directly to a mailbox bypassing most scanning and classification. This does not send a message. |
| `GMAIL_LIST_CSE_IDENTITIES` | List CSE identities | Lists a page of client-side encrypted identities and their key-pair associations. A response indicating that CSE is not enabled is returned as an empty list. |
| `GMAIL_LIST_CSE_KEYPAIRS` | List CSE key pairs | Lists a page of client-side encryption key pairs, including public keys and enablement states. A response indicating that CSE is not enabled is returned as an empty list. |
| `GMAIL_LIST_DRAFTS` | List Drafts | Retrieves a paginated list of email drafts from a user's Gmail account. Use verbose=true to get full draft details including subject, body, sender, and timestamp. Draft ordering is non-guaranteed; iterate using page_token until it is absent to retrieve all drafts. Newly created drafts may not appear immediately. Rapid calls may trigger 403 userRateLimitExceeded or 429 errors; apply exponential backoff (1s, 2s, 4s) before retrying. |
| `GMAIL_LIST_FILTERS` | List Gmail filters | Tool to list all Gmail filters (rules) in the mailbox. Use for security audits to detect malicious filter rules or before creating new filters to avoid duplicates. |
| `GMAIL_LIST_FORWARDING_ADDRESSES` | List forwarding addresses | Tool to list all forwarding addresses for the specified Gmail account. Use when you need to retrieve the email addresses that are allowed to be used for forwarding messages. |
| `GMAIL_LIST_HISTORY` | List Gmail history | Lists Gmail mailbox change history since a known history ID for incremental sync, with optional label and history-type filters and pagination. An empty history list means no records matched the request, not necessarily that no mailbox changes occurred. |
| `GMAIL_LIST_LABELS` | List Gmail labels | Retrieves all system and user-created labels for a Gmail account in a single unpaginated response. Primary use: obtain internal label IDs (e.g., 'Label_123') required by other Gmail tools — display names cannot be used as label identifiers and cause silent failures or errors. System labels (INBOX, UNREAD, SPAM, TRASH, etc.) are case-sensitive and must be used exactly as returned; INBOX, SPAM, and TRASH are read-only and cannot be added/removed via label modification tools. The Gmail search 'label:' operator accepts display names, but label_ids parameters in tools like GMAIL_FETCH_EMAILS require internal IDs from this tool — mixing conventions yields zero results silently. Do not hardcode label IDs across sessions; refresh via this tool on conflict errors. |
| `GMAIL_LIST_SEND_AS` | List send-as aliases | Lists the send-as aliases for a Gmail account, including the primary address and custom 'from' aliases. Use when you need to retrieve available sending addresses for composing emails. |
| `GMAIL_LIST_SMIME_INFO` | List S/MIME configs | Lists S/MIME certificate configurations for a specified Gmail send-as alias. If Gmail reports that the feature is not enabled, returns an empty list with S/MIME marked disabled. |
| `GMAIL_LIST_THREADS` | List threads | Retrieves a list of email threads from a Gmail account, identified by `user_id` (email address or 'me'), supporting filtering and pagination. Spam and trash are excluded by default unless explicitly targeted via `label:spam` or `label:trash` in the query. |
| `GMAIL_MODIFY_THREAD_LABELS` | Modify thread labels | Adds or removes specified existing label IDs from a Gmail thread, affecting all its messages; ensure the thread ID is valid. To modify a single message only, use a message-level tool instead. |
| `GMAIL_MOVE_THREAD_TO_TRASH` | Trash thread | Moves the specified thread to the trash. Any messages that belong to the thread are also moved to the trash. |
| `GMAIL_MOVE_TO_TRASH` | Move to Trash | Moves an existing, non-deleted email message to the trash for the specified user. Trashed messages are recoverable and still count toward storage quota until purged. Prefer this over GMAIL_BATCH_DELETE_MESSAGES when recovery may be needed. For bulk operations, use GMAIL_BATCH_MODIFY_MESSAGES or GMAIL_BATCH_DELETE_MESSAGES instead of repeated calls to this tool. |
| `GMAIL_PATCH_LABEL` | Patch Label | Patches the specified user-created label. System labels (e.g., INBOX, SENT, SPAM) cannot be modified and will be rejected. |
| `GMAIL_PATCH_SEND_AS` | Patch send-as alias | Patches a Gmail send-as alias, including its display name, reply-to address, signature, default status, or SMTP configuration. This tool declares support for service-account OAuth, not standard OAuth. |
| `GMAIL_REPLY_TO_THREAD` | Reply to email thread | Sends a reply to a Gmail thread using its original subject and quoting the last returned message. Requires a thread ID and at least one recipient, and supports optional file attachments. |
| `GMAIL_SEARCH_PEOPLE` | Search People | Searches saved contacts and optionally Other Contacts by query, returning matching person records. When both sources are requested, results may be partial if one search fails. |
| `GMAIL_SEND_DRAFT` | Send Draft | Sends an existing Gmail draft immediately to the recipients already in its To, Cc, and Bcc headers. The draft's recipients and content cannot be changed by this action; confirm them before sending. |
| `GMAIL_SEND_EMAIL` | Send Email | Sends an email immediately through Gmail to specified To, Cc, or Bcc recipients, with a subject or body and optional attachments. Supports plain text or HTML and may append the configured Gmail signature; attachments are limited to 20 MiB in total before encoding. |
| `GMAIL_SETTINGS_GET_IMAP` | Get IMAP Settings | Retrieves the IMAP settings for a Gmail user account, including whether IMAP is enabled, auto-expunge behavior, expunge behavior, and maximum folder size. |
| `GMAIL_SETTINGS_GET_POP` | Get POP settings | Tool to retrieve POP settings for a Gmail account. Use when you need to check the current POP configuration including access window and message disposition. |
| `GMAIL_SETTINGS_SEND_AS_GET` | Get send-as alias | Tool to retrieve a specific send-as alias configuration for a Gmail user. Use when you need to get details about a send-as email address including display name, signature, SMTP settings, and verification status. Fails with HTTP 404 if the specified address is not a member of the send-as collection. |
| `GMAIL_STOP_WATCH` | Stop watch notifications | Tool to stop receiving push notifications for a Gmail mailbox. Use when you need to disable watch notifications previously set up via the watch endpoint. |
| `GMAIL_UNTRASH_MESSAGE` | Untrash Message | Tool to remove a message from trash in Gmail. Use when you need to restore a previously trashed email message. |
| `GMAIL_UNTRASH_THREAD` | Untrash thread | Tool to remove a thread from trash in Gmail. Use when you need to restore a deleted thread and its messages. |
| `GMAIL_UPDATE_CONTACT` | Update Google Contact | Replace selected fields on an existing saved Google contact. |
| `GMAIL_UPDATE_DRAFT` | Update draft | Updates a Gmail draft by ID by replacing its message. The tool reads the existing draft to preserve omitted recipients, subject and body where applicable, but existing attachments are not preserved unless supplied again. |
| `GMAIL_UPDATE_IMAP_SETTINGS` | Update IMAP settings | Tool to update IMAP settings for a Gmail account. Use when you need to modify IMAP configuration such as enabling/disabling IMAP, setting auto-expunge behavior, or configuring folder size limits. |
| `GMAIL_UPDATE_LABEL` | Update Label | Updates an existing Gmail label's name, visibility settings, or color to help organize the mailbox. Color is available for user labels and requires both a background and text color from Gmail's supported palette. |
| `GMAIL_UPDATE_LANGUAGE_SETTINGS` | Update Language Settings | Tool to update the language settings for a Gmail user. Use when you need to change the display language preference for the authenticated user or a specific Gmail account. The returned displayLanguage may differ from the requested value if Gmail selects a close variant. |
| `GMAIL_UPDATE_POP_SETTINGS` | Update POP settings | Tool to update POP settings for a Gmail account. Use when you need to configure POP access window or message disposition behavior. |
| `GMAIL_UPDATE_SEND_AS` | Update send-as alias | Updates a Gmail send-as alias, including its display name, signature, reply-to address, or SMTP settings; Gmail sanitizes HTML signatures before saving. The tool declares support for service-account OAuth, not standard OAuth; non-primary addresses require domain-wide delegation. |
| `GMAIL_UPDATE_VACATION_SETTINGS` | Update Vacation Settings | Tool to update vacation responder settings for a Gmail user. Use when you need to configure out-of-office auto-replies. |
| `GMAIL_WHO_AM_I` | Who Am I | Return the identity (email, name) of the connected Gmail account. |

## Supported Triggers

| Trigger slug | Name | Description |
|---|---|---|
| `GMAIL_EMAIL_SENT_TRIGGER` | Email Sent | Triggers when a Gmail message is sent by the authenticated user. It polls the 'SENT' label and emits metadata including sender, recipients, subject, timestamp, and thread ID. |
| `GMAIL_NEW_GMAIL_MESSAGE` | New Gmail Message Received Trigger | Triggers when a new message is received in Gmail. |

## Creating MCP Server - Stand-alone vs Composio SDK

The Gmail MCP server is an implementation of the Model Context Protocol that connects Claude Code (and other AI assistants like Claude and Cursor) directly to your Gmail account. It provides structured and secure access so Claude can perform Gmail operations on your behalf.
With Composio's managed implementation, you don't have to create your own developer app. For production, if you're building an end product, we recommend using your own credentials. The managed server helps you prototype fast and go from 0-1 faster.

## Step-by-step Guide

### 1. Prerequisites

Before starting, make sure you have:
- Claude Pro, Max, or API billing enabled Anthropic account
- Composio API Key
- A Gmail account
- Basic knowledge of Python or TypeScript

### 1. Install Claude Code

To install Claude Code, use one of the following methods based on your operating system:
```bash
# macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bash

# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

# Windows CMD
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
```

### 2. Set up Claude Code

Open a terminal, go to your project folder, and start Claude Code:
- Claude Code will open in your terminal
- Follow the prompts to sign in with your Anthropic account
- Complete the authentication flow
- Once authenticated, you can start using Claude Code
```bash
cd your-project-folder
claude
```

### 3. Set up environment variables

Create a .env file in your project root with the following variables:
- COMPOSIO_API_KEY authenticates with Composio (get it from [Composio dashboard](https://dashboard.composio.dev/login?cta_placement=toolkit-framework-claude-code-api-key&next=%2F~%2Forg%2Fconnect%2Fclients%2Fclaude-code))
- USER_ID identifies the user for session management (use any unique identifier)
```bash
COMPOSIO_API_KEY=your_composio_api_key_here
USER_ID=your_user_id_here
```

### 4. Install Composio library

No description provided.
```python
pip install composio-core python-dotenv
```

```typescript
npm install @composio/core dotenv
```

### 5. Generate Composio MCP URL

No description provided.
```python
import os
from composio import Composio
from dotenv import load_dotenv

load_dotenv()

COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
USER_ID = os.getenv("USER_ID")

composio_client = Composio(api_key=COMPOSIO_API_KEY)

composio_session = composio_client.create(
    user_id=USER_ID,
    toolkits=["gmail"],
)

COMPOSIO_MCP_URL = composio_session.mcp.url

print(f"MCP URL: {COMPOSIO_MCP_URL}")
print(f"\nUse this command to add to Claude Code:")
print(f'claude mcp add --transport http gmail-composio "{COMPOSIO_MCP_URL}" --headers "X-API-Key:{COMPOSIO_API_KEY}"')
```

```typescript
import 'dotenv/config';
import { Composio } from '@composio/core';

const { COMPOSIO_API_KEY, USER_ID } = process.env;

if (!COMPOSIO_API_KEY || !USER_ID) {
  throw new Error('COMPOSIO_API_KEY and USER_ID required in .env');
}

const composioClient = new Composio({ apiKey: COMPOSIO_API_KEY });

const composioSession = await composioClient.create(USER_ID, {
  toolkits: ['gmail'],
});

const composioMcpUrl = composioSession?.mcp.url;

console.log(`MCP URL: ${composioMcpUrl}`);
console.log(`\nUse this command to add to Claude Code:`);
console.log(`claude mcp add --transport http gmail-composio "${composioMcpUrl}" --headers "X-API-Key:${COMPOSIO_API_KEY}"`);
```

### 6. Run the script and copy the MCP URL

No description provided.
```python
python generate_mcp_url.py
```

```typescript
node --loader ts-node/esm generate_mcp_url.ts
# or if using tsx
tsx generate_mcp_url.ts
```

### 7. Add Gmail MCP to Claude Code

In your terminal, add the MCP server using the command from the previous step. The command format is:
- claude mcp add registers a new MCP server with Claude Code
- --transport http specifies that this is an HTTP-based MCP server
- The server name (gmail-composio) is how you'll reference it
- The URL points to your Composio Tool Router session
- --headers includes your Composio API key for authentication
After running the command, close the current Claude Code session and start a new one for the changes to take effect.
```bash
claude mcp add --transport http gmail-composio "YOUR_MCP_URL_HERE" --headers "X-API-Key:YOUR_COMPOSIO_API_KEY"

# Then restart Claude Code
exit
claude
```

### 8. Verify the installation

Check that your Gmail MCP server is properly configured.
- This command lists all MCP servers registered with Claude Code
- You should see your gmail-composio entry in the list
- This confirms that Claude Code can now access Gmail tools
If everything is wired up, you should see your gmail-composio entry listed:
```bash
claude mcp list
```

### 9. Authenticate Gmail

The first time you try to use Gmail tools, you'll be prompted to authenticate.
- Claude Code will detect that you need to authenticate with Gmail
- It will show you an authentication link
- Open the link in your browser (or copy/paste it)
- Complete the Gmail authorization flow
- Return to the terminal and start using Gmail through Claude Code
Once authenticated, you can ask Claude Code to perform Gmail operations in natural language. For example:
- "Summarize unread emails from this morning"
- "Create draft replies to urgent messages"
- "Fetch contact details for recent senders"

## Complete Code

```python
import os
from composio import Composio
from dotenv import load_dotenv

load_dotenv()

COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
USER_ID = os.getenv("USER_ID")

composio_client = Composio(api_key=COMPOSIO_API_KEY)

composio_session = composio_client.create(
    user_id=USER_ID,
    toolkits=["gmail"],
)

COMPOSIO_MCP_URL = composio_session.mcp.url

print(f"MCP URL: {COMPOSIO_MCP_URL}")
print(f"\nUse this command to add to Claude Code:")
print(f'claude mcp add --transport http gmail-composio "{COMPOSIO_MCP_URL}" --headers "X-API-Key:{COMPOSIO_API_KEY}"')
```

```typescript
import 'dotenv/config';
import { Composio } from '@composio/core';

const { COMPOSIO_API_KEY, USER_ID } = process.env;

if (!COMPOSIO_API_KEY || !USER_ID) {
  throw new Error('COMPOSIO_API_KEY and USER_ID required in .env');
}

const composioClient = new Composio({ apiKey: COMPOSIO_API_KEY });

const composioSession = await composioClient.create(USER_ID, {
  toolkits: ['gmail'],
});

const composioMcpUrl = composioSession?.mcp.url;

console.log(`MCP URL: ${composioMcpUrl}`);
console.log(`\nUse this command to add to Claude Code:`);
console.log(`claude mcp add --transport http gmail-composio "${composioMcpUrl}" --headers "X-API-Key:${COMPOSIO_API_KEY}"`);
```

## Conclusion

You've successfully integrated Gmail with Claude Code using Composio's MCP server. Now you can interact with Gmail directly from your terminal using natural language commands.
Key features of this setup:
- Terminal-native experience without switching contexts
- Natural language commands for Gmail operations
- Secure authentication through Composio's managed MCP
- Tool Router for dynamic tool discovery and execution
Next steps:
- Try asking Claude Code to perform various Gmail operations
- Add more toolkits to your Tool Router session for multi-app workflows
- Integrate this setup into your development workflow for increased productivity
You can extend this by adding more toolkits, implementing custom workflows, or building automation scripts that leverage Claude Code's capabilities.

## How to build Gmail MCP Agent with another framework

- [Cursor](https://composio.dev/toolkits/gmail/framework/cursor)
- [ChatGPT](https://composio.dev/toolkits/gmail/framework/chatgpt)
- [Claude Cowork](https://composio.dev/toolkits/gmail/framework/claude-cowork)
- [Antigravity](https://composio.dev/toolkits/gmail/framework/antigravity)
- [OpenAI Agents SDK](https://composio.dev/toolkits/gmail/framework/open-ai-agents-sdk)
- [Claude Agent SDK](https://composio.dev/toolkits/gmail/framework/claude-agents-sdk)
- [Grok Bot](https://composio.dev/toolkits/gmail/framework/grok-bot)
- [Muse](https://composio.dev/toolkits/gmail/framework/muse)
- [Codex](https://composio.dev/toolkits/gmail/framework/codex)
- [Kimi Code](https://composio.dev/toolkits/gmail/framework/kimi)
- [Grok Build](https://composio.dev/toolkits/gmail/framework/grok-build)
- [VS Code](https://composio.dev/toolkits/gmail/framework/vscode)
- [OpenCode](https://composio.dev/toolkits/gmail/framework/opencode)
- [OpenClaw](https://composio.dev/toolkits/gmail/framework/openclaw)
- [Hermes](https://composio.dev/toolkits/gmail/framework/hermes-agent)
- [Atomic Agent](https://composio.dev/toolkits/gmail/framework/atomic-agent)
- [Pi](https://composio.dev/toolkits/gmail/framework/pi-agent)
- [DeepSeek Harness](https://composio.dev/toolkits/gmail/framework/deepseek)
- [CLI](https://composio.dev/toolkits/gmail/framework/cli)
- [Google ADK](https://composio.dev/toolkits/gmail/framework/google-adk)
- [LangChain](https://composio.dev/toolkits/gmail/framework/langchain)
- [Vercel AI SDK](https://composio.dev/toolkits/gmail/framework/ai-sdk)
- [Mastra AI](https://composio.dev/toolkits/gmail/framework/mastra-ai)
- [LlamaIndex](https://composio.dev/toolkits/gmail/framework/llama-index)
- [CrewAI](https://composio.dev/toolkits/gmail/framework/crew-ai)
- [Pydantic AI](https://composio.dev/toolkits/gmail/framework/pydantic-ai)
- [AutoGen](https://composio.dev/toolkits/gmail/framework/autogen)

## Related Toolkits

- [Outlook](https://composio.dev/toolkits/outlook) - Outlook is Microsoft's email and calendaring platform for unified communications and scheduling. It helps users stay organized with powerful email, contacts, and calendar management.
- [Slack](https://composio.dev/toolkits/slack) - Slack is a channel-based messaging platform for teams and organizations. It helps people collaborate in real time, share files, and connect all their tools in one place.
- [Gong](https://composio.dev/toolkits/gong) - Gong is a platform for video meetings, call recording, and team collaboration. It helps teams capture conversations, analyze calls, and turn insights into action.
- [Microsoft teams](https://composio.dev/toolkits/microsoft_teams) - Microsoft Teams is a collaboration platform that combines chat, meetings, and file sharing within Microsoft 365. It keeps distributed teams connected and productive through seamless virtual communication.
- [Slackbot](https://composio.dev/toolkits/slackbot) - Slackbot is a conversational automation tool for Slack that handles reminders, notifications, and automated responses. It boosts team productivity by streamlining onboarding, answering FAQs, and managing timely alerts—all right inside Slack.
- [2chat](https://composio.dev/toolkits/_2chat) - 2chat is an API platform for WhatsApp and multichannel text messaging. It streamlines chat automation, group management, and real-time messaging for developers.
- [Agent mail](https://composio.dev/toolkits/agent_mail) - Agent mail provides AI agents with dedicated email inboxes for sending, receiving, and managing emails. It empowers agents to communicate autonomously with people, services, and other agents—no human intervention needed.
- [Aircall](https://composio.dev/toolkits/aircall) - Aircall is a cloud-based phone and call-center platform for business communications. It centralizes calls, contacts, teams, numbers, and tags in one place.
- [Android Texter](https://composio.dev/toolkits/android_texter) - Android Texter is an API service that connects Android phones to SMS, MMS, contacts, and device data. Use it to automate mobile messaging without building your own phone-to-API bridge.
- [Basecamp](https://composio.dev/toolkits/basecamp) - Basecamp is a project management and team collaboration tool by 37signals. It helps teams organize tasks, share files, and communicate efficiently in one place.
- [Blooio](https://composio.dev/toolkits/blooio) - Blooio is a stable v2 API platform for messaging, chats, contacts, groups, phone numbers, and account analytics. It gives teams a clean way to build reliable communication workflows without stitching together fragile custom APIs.
- [Callback24](https://composio.dev/toolkits/callback24) - Callback24 is a telephony API for managing phone calls, users, services, and routing groups. It centralizes call control and routing to automate voice workflows and operations.
- [CallOnTheGo](https://composio.dev/toolkits/callonthego) - CallOnTheGo is a telephony API for managing phone numbers, caller IDs, suppression lists, audio assets, contact lists, and Voice AI campaigns. It provides programmatic control over calling infrastructure and campaign automation for scalable voice outreach.
- [Carbon Voice MCP](https://composio.dev/toolkits/carbon_voice_mcp) - Carbon Voice MCP is a voice-first collaboration platform for messages, conversations, and workflows. Use it to centralize voice communications and streamline team collaboration.
- [CardClan](https://composio.dev/toolkits/cardclan) - CardClan is a digital card platform for creating and sending personalized team cards. Use it to celebrate moments, share card links, and manage card workflows without extra coordination.
- [Chatwork](https://composio.dev/toolkits/chatwork) - Chatwork is a team communication platform with group chats, file sharing, and task management. It helps businesses boost collaboration and streamline productivity.
- [Clickmeeting](https://composio.dev/toolkits/clickmeeting) - ClickMeeting is a cloud-based platform for running online meetings and webinars. It helps businesses and individuals host, manage, and engage virtual audiences with ease.
- [Confluence](https://composio.dev/toolkits/confluence) - Confluence is Atlassian's team collaboration and knowledge management platform. It helps your team organize, share, and update documents and project content in one secure workspace.
- [Daily](https://composio.dev/toolkits/daily) - Daily is a WebRTC video and audio API platform for building rooms, meetings, recordings, live streams, transcriptions, and telephony. It gives developers reliable real-time media infrastructure without managing complex conferencing stacks.
- [Dailybot](https://composio.dev/toolkits/dailybot) - DailyBot streamlines team collaboration with chat-based standups, reminders, and polls. It keeps work flowing smoothly in your favorite messaging platforms.

## Frequently Asked Questions

### What are the differences in Tool Router MCP and Gmail MCP?

With a standalone Gmail MCP server, the agents and LLMs can only access a fixed set of Gmail tools tied to that server. However, with the Composio Tool Router, agents can dynamically load tools from Gmail and many other apps based on the task at hand, all through a single MCP endpoint.

### Can I use Tool Router MCP with Claude Code?

Yes, you can. Claude Code fully supports MCP integration. You get structured tool calling, message history handling, and model orchestration while Tool Router takes care of discovering and serving the right Gmail tools.

### Can I manage the permissions and scopes for Gmail while using Tool Router?

Yes, absolutely. You can configure which Gmail scopes and actions are allowed when connecting your account to Composio. You can also bring your own OAuth credentials or API configuration so you keep full control over what the agent can do.

### How safe is my data with Composio Tool Router?

All sensitive data such as tokens, keys, and configuration is fully encrypted at rest and in transit. Composio is SOC 2 Type 2 compliant and follows strict security practices so your Gmail data and credentials are handled as safely as possible.

---
[See all toolkits](https://composio.dev/toolkits) · [Composio docs](https://docs.composio.dev/llms.txt)
