Gmail Automation via Rube MCP
Automate Gmail operations through Composio's Gmail toolkit via Rube MCP.
Prerequisites
- Rube MCP must be connected (RUBE_SEARCH_TOOLS available)
- Active Gmail connection via with toolkit
- Always call first to get current tool schemas
Setup
Get Rube MCP: Add
as an MCP server in your client configuration. No API keys needed — just add the endpoint and it works.
- Verify Rube MCP is available by confirming responds
- Call with toolkit
- If connection is not ACTIVE, follow the returned auth link to complete Google OAuth
- Confirm connection status shows ACTIVE before running any workflows
Core Workflows
1. Send an Email
When to use: User wants to compose and send a new email
Tool sequence:
- - Resolve contact name to email address [Optional]
- - Send the email [Required]
Key parameters:
- : Email address or 'me' for self
- : Email subject line
- : Email content (plain text or HTML)
- : Must be if body contains HTML markup
- /: Arrays of email addresses
- : Object with from prior download
Pitfalls:
- At least one of , , or required
- At least one of or required
- Attachment MUST contain '/' (e.g., 'application/pdf', not 'pdf')
- Total message size limit ~25MB after base64 encoding
- Use only for verified aliases in Gmail 'Send mail as' settings
2. Reply to a Thread
When to use: User wants to reply to an existing email conversation
Tool sequence:
- - Find the email/thread to reply to [Prerequisite]
- - Send reply within the thread [Required]
Key parameters:
- : Hex string from FETCH_EMAILS (e.g., '169eefc8138e68ca')
- : Reply content
- : Reply recipient
- : Set for HTML content
Pitfalls:
- must be hex string; prefixes like 'msg-f:' are auto-stripped
- Legacy Gmail web UI IDs (e.g., 'FMfcgz...') are NOT supported
- Subject is inherited from original thread; setting it creates a new thread instead
- Do NOT include subject parameter to stay within thread
3. Search and Filter Emails
When to use: User wants to find specific emails by sender, subject, date, label, etc.
Tool sequence:
- - Search with Gmail query syntax [Required]
GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID
- Get full message details for selected results [Optional]
Key parameters:
- : Gmail search syntax (from:, to:, subject:, is:unread, has:attachment, after:YYYY/MM/DD, before:YYYY/MM/DD)
- : 1-500 messages per page
- : System IDs like 'INBOX', 'UNREAD'
- : Set to get full message content
- : Set for just message IDs
- : For pagination (from )
Pitfalls:
- Returns max ~500 per page; follow via until absent
- is approximate, not exact count
- Use 'is:' for states (is:unread, is:snoozed, is:starred)
- Use 'label:' ONLY for user-created labels
- Common mistake: 'label:snoozed' is WRONG — use 'is:snoozed'
- on broad searches creates huge responses; default to metadata
- Custom labels require label ID (e.g., 'Label_123'), NOT label name
4. Manage Labels
When to use: User wants to create, modify, or organize labels
Tool sequence:
- - List all labels to find IDs and detect conflicts [Required]
- - Create a new label [Optional]
- - Rename or change label colors/visibility [Optional]
- - Delete a user-created label (irreversible) [Optional]
Key parameters:
- : Max 225 chars, no commas, '/' for nesting (e.g., 'Work/Projects')
- /: Hex values from Gmail's predefined palette
- : Label ID for PATCH/DELETE operations
Pitfalls:
- 400/409 error if name is blank, duplicate, or reserved (INBOX, SPAM, CATEGORY_*)
- Color specs must use Gmail's predefined palette of 102 hex values
- DELETE is permanent and removes label from all messages
- Cannot delete system labels (INBOX, SENT, DRAFT, etc.)
5. Apply/Remove Labels on Messages
When to use: User wants to label, archive, or mark emails as read/unread
Tool sequence:
- - Get label IDs for custom labels [Prerequisite]
- - Find target messages [Prerequisite]
GMAIL_BATCH_MODIFY_MESSAGES
- Bulk add/remove labels (up to 1000 messages) [Required]
- - Single-message label changes [Fallback]
Key parameters:
- : Array of message IDs (max 1000)
- : Array of label IDs to add
- : Array of label IDs to remove
- : 15-16 char hex string for single operations
Pitfalls:
- Max 1000 messageIds per BATCH call; chunk larger sets
- Use 'CATEGORY_UPDATES' not 'UPDATES'; full prefix required for category labels
- SENT, DRAFT, CHAT are immutable — cannot be added/removed
- To mark as read: REMOVE 'UNREAD'. To archive: REMOVE 'INBOX'
- must be 15-16 char hex, NOT UUIDs or web UI IDs
6. Handle Drafts and Attachments
When to use: User wants to create, edit, or send email drafts, possibly with attachments
Tool sequence:
- - Create a new draft [Required]
- - Edit draft content [Optional]
- - List existing drafts [Optional]
- - Send a draft (requires explicit user approval) [Optional]
- - Download attachment from existing message [Optional]
Key parameters:
- : Draft recipient
- : Draft subject (omit for reply drafts to stay in thread)
- : Draft content
- : Set for HTML content
- : Object with
- : For reply drafts (leave subject empty to stay in thread)
Pitfalls:
- Response includes (draft_id) AND ; use for draft operations
- Setting subject on a thread reply draft creates a NEW thread instead
- Attachment capped at ~25MB; base64 overhead can push near-limit files over
- UPDATE_DRAFT replaces entire content, not patches; include all fields you want to keep
- HTTP 429 on bulk draft creation; use exponential backoff
Common Patterns
ID Resolution
Label name → Label ID:
1. Call GMAIL_LIST_LABELS
2. Find label by name in response
3. Extract id field (e.g., 'Label_123')
Contact name → Email:
1. Call GMAIL_SEARCH_PEOPLE with query=contact_name
2. Extract emailAddresses from response
Thread ID from search:
1. Call GMAIL_FETCH_EMAILS or GMAIL_LIST_THREADS
2. Extract threadId (15-16 char hex string)
Pagination
- Set up to 500 per page
- Check response for
- Pass token as in next request
- Continue until is absent or empty string
- is approximate, not exact
Gmail Query Syntax
Operators:
- - Emails from sender
- - Emails to recipient
- - Subject contains exact phrase
- - Unread messages
- - Starred messages
- - Snoozed messages
- - Has attachments
- - After date (YYYY/MM/DD)
- - Before date
- - User-created label (use label ID)
- - In sent folder
- - Primary category
Combinators:
- - Both conditions (default)
- - Either condition
- - Exclude condition
- - Group conditions
Examples:
from:boss@company.com is:unread
- Unread emails from boss
subject:invoice has:attachment after:2024/01/01
- Invoices with attachments this year
(from:alice OR from:bob) is:starred
- Starred emails from Alice or Bob
Known Pitfalls
ID Formats:
- Custom label operations require label IDs (e.g., 'Label_123'), not display names
- Always call LIST_LABELS first to resolve names to IDs
- Message IDs are 15-16 char hex strings
- Do NOT use UUIDs, web UI IDs, or 'thread-f:' prefixes
Query Syntax:
- Use 'is:' for states (unread, snoozed, starred)
- Use 'label:' ONLY for user-created labels
- System labels use 'is:' or 'in:' (e.g., 'is:sent', 'in:inbox')
Rate Limits:
- BATCH_MODIFY_MESSAGES max 1000 messages per call
- Heavy use triggers 403/429 rate limits
- Implement exponential backoff for bulk operations
Response Parsing:
- Response data may be nested under or
- Parse defensively with fallbacks
- Timestamp uses RFC3339 with 'Z' suffix
- Normalize to '+00:00' for parsing if needed
Attachments:
- Attachment from prior download may expire
- Use promptly after retrieval
- Mimetype must include '/' separator
Quick Reference
| Task | Tool Slug | Key Params |
|---|
| Send email | GMAIL_SEND_EMAIL | recipient_email, subject, body, is_html |
| Reply to thread | GMAIL_REPLY_TO_THREAD | thread_id, message_body, recipient_email |
| Search emails | GMAIL_FETCH_EMAILS | query, max_results, label_ids, page_token |
| Get message details | GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID | message_id |
| List labels | GMAIL_LIST_LABELS | (none) |
| Create label | GMAIL_CREATE_LABEL | label_name, background_color, text_color |
| Modify labels bulk | GMAIL_BATCH_MODIFY_MESSAGES | messageIds, addLabelIds, removeLabelIds |
| Create draft | GMAIL_CREATE_EMAIL_DRAFT | recipient_email, subject, body, thread_id |
| Send draft | GMAIL_SEND_DRAFT | draft_id |
| Get attachment | GMAIL_GET_ATTACHMENT | message_id, attachment_id |
| Search contacts | GMAIL_SEARCH_PEOPLE | query |
| Get profile | GMAIL_GET_PROFILE | (none) |
When to Use
This skill is applicable to execute the workflow or actions described in the overview.