How to integrate Gmail MCP with Codex

Codex is one of the most popular coding harnesses out there. And MCP makes the experience even better. With Gmail MCP integration, you can draft, triage, summarise emails, and much more, all without leaving the terminal or the app, whichever you prefer.

Gmail logoGmail
Oauth2

Gmail is Google's email service with powerful spam protection, search, and G Suite integration. It keeps your inbox organized and makes communication fast and reliable.

61 Tools2 Triggers

Introduction

Codex is one of the most popular coding harnesses out there. And MCP makes the experience even better. With Gmail MCP integration, you can draft, triage, summarise emails, and much more, all without leaving the terminal or the app, whichever you prefer.

Also integrate Gmail with

Why use Composio?

Apart from a managed and hosted MCP server, you will get:

  • CodeAct: A dedicated workbench that allows GPT to write its code to handle complex tool chaining. Reduces to-and-fro with LLMs for frequent tool calling.
  • Large tool responses: Handle them to minimise context rot.
  • Dynamic just-in-time access to 20,000 tools across 1000+ other Apps for cross-app workflows. It loads the tools you need, so GPTs aren't overwhelmed by tools you don't need.

How to install Gmail MCP in Codex

Run the setup command

Run this command in your terminal to add the Composio MCP server to Codex.

Terminal

It will initiate the authentication in a browser window, authorize Codex to access your Composio account.

Composio authentication page

(Optional) Authenticate with OAuth

To authenticate manually, run the login command to open a browser window and authorize Codex to access your Composio account.

bash
codex mcp login composio

Verify the connection

Run codex mcp list to confirm Composio appears as a registered MCP server.

bash
codex mcp list

Codex App

Codex App follows the same approach as VS Code.

  1. Click ⚙️ on the bottom left → MCP Servers → + Add servers → Streamable HTTP:
  2. Fill the header and Key fields with { "x-consumer-api-key" = "ck_*******" }.
  3. The Key is the Composio API key, that you can find on dashboard.composio.dev
  4. Click on Authenticate and authorize Codex to your Composio account and you're all set.
Codex App MCP setup
  1. Restart and verify if it's there in .codex/config.toml
bash
[mcp_servers.composio]
url = "https://connect.composio.dev/mcp"
http_headers = { "x-consumer-api-key" = "ck_*******" }

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, so your agent can search, read, draft, organize, and even manage contacts in your mailbox—all on your behalf.

  • Advanced email search and retrieval: Effortlessly instruct your agent to fetch emails by sender, subject, label, date, or keywords, and even retrieve full message content or threads.
  • Automated drafting and sending: Have your agent create new email drafts, craft replies, add CC/BCC, include attachments, and handle threading to streamline communication.
  • Smart label and inbox organization: Let the agent create new labels, apply or remove labels from emails, and keep your inbox clutter-free by archiving or moving messages.
  • Contact and thread management: Fetch your Gmail contacts, pull entire conversation threads, or download specific attachments to make follow-ups a breeze.
  • Email and draft cleanup: Direct your agent to permanently delete emails or drafts, helping you maintain a tidy mailbox with minimal effort.

Conclusion

You've successfully integrated Gmail with Codex using Composio's MCP server. Now you can interact with Gmail directly from your terminal, VS Code, or the Codex App using natural language commands.

Key benefits of this setup:

  • Seamless integration across CLI, VS Code, and standalone app
  • Natural language commands for Gmail operations
  • Managed authentication through Composio
  • Access to 20,000+ tools across 1000+ apps for cross-app workflows
  • CodeAct workbench for complex tool chaining

Next steps:

  • Try asking Codex to perform various Gmail operations
  • Explore cross-app workflows by connecting more toolkits
  • Build automation scripts that leverage Codex's AI capabilities
TOOLS & TRIGGERS

Supported Tools and Triggers

Every Gmail action and event your agent gets out of the box.

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

Batch delete Gmail messages

Tool to permanently delete multiple Gmail messages in bulk, bypassing Trash with no recovery possible.

Batch modify Gmail messages

Modify labels on multiple Gmail messages in one efficient API call.

Create email draft

Creates a Gmail email draft.

Create Gmail filter

Tool to create a new Gmail filter with specified criteria and actions.

Create label

Creates a new label with a unique name in the specified user's Gmail account.

Create Prompt Post

Send a one-shot prompt to the Sanity Content Agent.

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.

Delete Gmail filter

Tool to permanently delete a Gmail filter by its ID.

Delete label from account (permanent)

Permanently DELETES a user-created Gmail label from the account (not from a 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.

Delete thread

Tool to immediately and permanently delete a specified thread and all its messages.

Fetch emails

Fetches a list of email messages from a Gmail account, supporting filtering, pagination, and optional full content retrieval.

Fetch message by message ID

Fetches a specific email message by its ID, provided the `message_id` exists and is accessible to the authenticated `user_id`.

Fetch Message by Thread ID

Retrieves messages from a Gmail thread using its `thread_id`, where the thread must be accessible by the specified `user_id`.

Forward email message

Forward an existing Gmail message to specified recipients, preserving original body and attachments.

Get Gmail attachment

Retrieves a specific attachment by ID from a message in a user's Gmail mailbox, requiring valid message and attachment IDs.

Get Auto-Forwarding Settings

Tool to get the auto-forwarding setting for the specified account.

Get contacts

Fetches contacts (connections) for the authenticated Google account, allowing selection of specific data fields and pagination.

Get Draft

Retrieves a single Gmail draft by its ID.

Get Gmail filter

Tool to retrieve a specific Gmail filter by its ID.

Get label details

Gets details for a specified Gmail label.

Get Language Settings

Tool to retrieve the language settings for a Gmail user.

Get People

Retrieves either a specific person's details (using `resource_name`) or lists 'Other Contacts' (if `other_contacts` is true), with `person_fields` specifying the data to return.

Get Profile

Retrieves Gmail profile information (email address, aggregate messagesTotal/threadsTotal, historyId) for a user.

Get Vacation Settings

Tool to retrieve vacation responder settings for a Gmail user.

Import message

Tool to import a message into the user's mailbox with standard email delivery scanning and classification.

Insert message into mailbox

Tool to insert a message into the user's mailbox similar to IMAP APPEND.

List CSE identities

Tool to list client-side encrypted identities for an authenticated user.

List CSE key pairs

Tool to list client-side encryption key pairs for an authenticated user.

List Drafts

Retrieves a paginated list of email drafts from a user's Gmail account.

List Gmail filters

Tool to list all Gmail filters (rules) in the mailbox.

List forwarding addresses

Tool to list all forwarding addresses for the specified Gmail account.

List Gmail history

Tool to list Gmail mailbox change history since a known startHistoryId.

List Gmail labels

Retrieves all system and user-created labels for a Gmail account in a single unpaginated response.

List send-as aliases

Lists the send-as aliases for a Gmail account, including the primary address and custom 'from' aliases.

List S/MIME configs

Lists S/MIME configs for the specified send-as alias.

List threads

Retrieves a list of email threads from a Gmail account, identified by `user_id` (email address or 'me'), supporting filtering and pagination.

Modify thread labels

Adds or removes specified existing label IDs from a Gmail thread, affecting all its messages; ensure the thread ID is valid.

Trash thread

Moves the specified thread to the trash.

Move to Trash

Moves an existing, non-deleted email message to the trash for the specified user.

Patch Label

Patches the specified user-created label.

Patch send-as alias

Tool to patch the specified send-as alias for a Gmail user.

Reply to email thread

Sends a reply within a specific Gmail thread using the original thread's subject; do not provide a custom subject as it will start a new conversation instead of replying in-thread.

Search People

Searches contacts by matching the query against names, nicknames, emails, phone numbers, and organizations, optionally including 'Other Contacts'.

Send Draft

Sends an existing draft email AS-IS to recipients already defined within the draft.

Send Email

Sends an email via Gmail API using the authenticated user's Google profile display name.

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.

Get POP settings

Tool to retrieve POP settings for a Gmail account.

Get send-as alias

Tool to retrieve a specific send-as alias configuration for a Gmail user.

Stop watch notifications

Tool to stop receiving push notifications for a Gmail mailbox.

Untrash Message

Tool to remove a message from trash in Gmail.

Untrash thread

Tool to remove a thread from trash in Gmail.

Update draft

Updates (replaces) an existing Gmail draft's content in-place by draft ID.

Update IMAP settings

Tool to update IMAP settings for a Gmail account.

Update Label

Tool to update the properties of an existing Gmail label.

Update Language Settings

Tool to update the language settings for a Gmail user.

Update POP settings

Tool to update POP settings for a Gmail account.

Update send-as alias

Tool to update a send-as alias for a Gmail user.

Update User Attributes Values

Update user attribute values for a resource.

Update Vacation Settings

Tool to update vacation responder settings for a Gmail user.

FAQ

Frequently asked questions

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.

Yes, you can. Codex 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.

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.

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.

Start with Gmail.It takes 30 seconds.

Managed auth, hosted MCP servers, and every Gmail tool your agent needs.Free to start.

Start building