communication
Gmail MCP, CLI, and Lua Integration for AI Agents
Gmail integration docs for AI agents: MCP gateway setup, Gmail CLI commands, Lua API reference, credentials, and function schemas.
16 functions 9 read 7 write OAuth browser flow auth
Gmail for agents
OAuth can be configured in web hosts through redirect and in CLI hosts through local/device authorization; runtime works with stored tokens.
Use this integration from Lua code mode, the headless integrations CLI, or the KosmoKrator MCP gateway. The same package metadata powers all three surfaces.
Machine-Readable Metadata
- integration_slug
gmail- route_slug
gmail- package
google- auth_strategy
oauth2_authorization_codeOAuth browser flow- cli_setup_supported
true- cli_runtime_supported
true- mcp_gateway_supported
true- lua_supported
true- supports_multi_account
false
Quick Links
Lua APIAgent-facing namespace and function reference. Gmail CLIHeadless setup and direct function calls. Gmail MCPMCP gateway setup for external clients. Submit feedbackReport missing tools, auth problems, wrong docs, or runtime issues. ContributeAdd tools or improve metadata in the integrations repo.
Gmail MCP Client Matrix
Use these pages when a specific agent client or framework needs copy-pasteable MCP setup for Gmail.
Claude Code Gmail MCP setup for Claude Code. Cursor Gmail MCP setup for Cursor. Codex Gmail MCP setup for Codex. OpenAI Agents Gmail MCP setup for OpenAI Agents SDK. Claude Agent SDK Gmail MCP setup for Claude Agent SDK. Vercel AI SDK Gmail MCP setup for Vercel AI SDK. LangChain Gmail MCP setup for LangChain. LangGraph Gmail MCP setup for LangGraph. CrewAI Gmail MCP setup for CrewAI. MCP clients Gmail MCP setup for Generic MCP Clients.
Gmail CLI Matrix
Use these pages for direct Gmail CLI workflows in scripts, CI, cron, and agent wrappers.
CI Gmail CLI for CI. Cron Jobs Gmail CLI for cron jobs. Shell Scripts Gmail CLI for shell scripts. Headless Automation Gmail CLI for headless automation. Coding Agents Gmail CLI for coding agents.
Function Catalog
| Function | Type | Parameters | Description |
|---|---|---|---|
gmail.gmail_add_labels | Write write | 3 | Add labels to one or more Gmail messages. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_archive | Read read | 2 | Archive one or more Gmail messages (remove from inbox). Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_create_draft | Write write | 5 | Create a draft email in Gmail (not sent). |
gmail.gmail_mark_read | Write write | 2 | Mark one or more Gmail messages as read. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_mark_unread | Write write | 2 | Mark one or more Gmail messages as unread. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_read | Read read | 2 | Read the full content of a Gmail message by its ID. Returns headers (From, To, Subject, Date), the decoded text body, and a list of attachments. Use gmail_search first to find message IDs, then use this tool to read the full content. |
gmail.gmail_remove_labels | Write write | 3 | Remove labels from one or more Gmail messages. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_reply | Read read | 6 | Reply to an existing Gmail message (maintains the thread). |
gmail.gmail_count_by_sender | Read read | 2 | Count all matching Gmail messages grouped by sender. Automatically paginates through ALL results (handles thousands of messages). Returns top senders sorted by count. Use for questions like "who sends me the most email?" or "count unread by sender". |
gmail.gmail_list_labels | Read read | 0 | List all labels in the Gmail mailbox (INBOX, SENT, custom labels, etc.). |
gmail.gmail_save_attachment | Read read | 4 | Download an email attachment and save it to workspace files. Requires a messageId and attachmentId (both returned by gmail_read). The file is saved under the agent's folder and can be browsed in the Files page. |
gmail.gmail_search_emails | Read read | 4 | Search Gmail messages using Gmail query syntax (e.g., "from:alice subject:meeting is:unread has:attachment after:2026-02-01"). Returns message summaries with headers. Max 100 per page. |
gmail.gmail_send_draft | Write write | 1 | Send a previously created Gmail draft by its ID. |
gmail.gmail_send_email | Write write | 5 | Send an email directly via Gmail. |
gmail.gmail_trash | Read read | 2 | Move one or more Gmail messages to trash. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_untrash | Read read | 2 | Remove one or more Gmail messages from trash. Provide messageIds (comma-separated) for batch operations. |