gmail-automation
Original:🇺🇸 English
Not Translated
Automate Gmail tasks via Rube MCP (Composio): send/reply, search, labels, drafts, attachments. Always search tools first for current schemas.
2installs
Added on
NPX Install
npx skill4agent add aaaaqwq/claude-code-skills gmail-automationSKILL.md Content
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
RUBE_MANAGE_CONNECTIONSgmail - Always call first to get current tool schemas
RUBE_SEARCH_TOOLS
Setup
Get Rube MCP: Add as an MCP server in your client configuration. No API keys needed — just add the endpoint and it works.
https://rube.app/mcp- Verify Rube MCP is available by confirming responds
RUBE_SEARCH_TOOLS - Call with toolkit
RUBE_MANAGE_CONNECTIONSgmail - 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]
GMAIL_SEARCH_PEOPLE - - Send the email [Required]
GMAIL_SEND_EMAIL
Key parameters:
- : Email address or 'me' for self
recipient_email - : Email subject line
subject - : Email content (plain text or HTML)
body - : Must be
is_htmlif body contains HTML markuptrue - /
cc: Arrays of email addressesbcc - : Object with
attachmentfrom prior download{s3key, mimetype, name}
Pitfalls:
- At least one of ,
recipient_email, orccrequiredbcc - At least one of or
subjectrequiredbody - Attachment MUST contain '/' (e.g., 'application/pdf', not 'pdf')
mimetype - Total message size limit ~25MB after base64 encoding
- Use only for verified aliases in Gmail 'Send mail as' settings
from_email
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]
GMAIL_FETCH_EMAILS - - Send reply within the thread [Required]
GMAIL_REPLY_TO_THREAD
Key parameters:
- : Hex string from FETCH_EMAILS (e.g., '169eefc8138e68ca')
thread_id - : Reply content
message_body - : Reply recipient
recipient_email - : Set
is_htmlfor HTML contenttrue
Pitfalls:
- must be hex string; prefixes like 'msg-f:' are auto-stripped
thread_id - 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_EMAILS - - Get full message details for selected results [Optional]
GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID
Key parameters:
- : Gmail search syntax (from:, to:, subject:, is:unread, has:attachment, after:YYYY/MM/DD, before:YYYY/MM/DD)
query - : 1-500 messages per page
max_results - : System IDs like 'INBOX', 'UNREAD'
label_ids - : Set
include_payloadto get full message contenttrue - : Set
ids_onlyfor just message IDstrue - : For pagination (from
page_token)nextPageToken
Pitfalls:
- Returns max ~500 per page; follow via
nextPageTokenuntil absentpage_token - is approximate, not exact count
resultSizeEstimate - 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
include_payload=true - 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]
GMAIL_LIST_LABELS - - Create a new label [Optional]
GMAIL_CREATE_LABEL - - Rename or change label colors/visibility [Optional]
GMAIL_PATCH_LABEL - - Delete a user-created label (irreversible) [Optional]
GMAIL_DELETE_LABEL
Key parameters:
- : Max 225 chars, no commas, '/' for nesting (e.g., 'Work/Projects')
label_name - /
background_color: Hex values from Gmail's predefined palettetext_color - : Label ID for PATCH/DELETE operations
id
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]
GMAIL_LIST_LABELS - - Find target messages [Prerequisite]
GMAIL_FETCH_EMAILS - - Bulk add/remove labels (up to 1000 messages) [Required]
GMAIL_BATCH_MODIFY_MESSAGES - - Single-message label changes [Fallback]
GMAIL_ADD_LABEL_TO_EMAIL
Key parameters:
- : Array of message IDs (max 1000)
messageIds - : Array of label IDs to add
addLabelIds - : Array of label IDs to remove
removeLabelIds - : 15-16 char hex string for single operations
message_id
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
message_id
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]
GMAIL_CREATE_EMAIL_DRAFT - - Edit draft content [Optional]
GMAIL_UPDATE_DRAFT - - List existing drafts [Optional]
GMAIL_LIST_DRAFTS - - Send a draft (requires explicit user approval) [Optional]
GMAIL_SEND_DRAFT - - Download attachment from existing message [Optional]
GMAIL_GET_ATTACHMENT
Key parameters:
- : Draft recipient
recipient_email - : Draft subject (omit for reply drafts to stay in thread)
subject - : Draft content
body - : Set
is_htmlfor HTML contenttrue - : Object with
attachment{s3key, mimetype, name} - : For reply drafts (leave subject empty to stay in thread)
thread_id
Pitfalls:
- Response includes (draft_id) AND
data.id; usedata.message.idfor draft operationsdata.id - 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 responseThread 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
max_results - Check response for
nextPageToken - Pass token as in next request
page_token - Continue until is absent or empty string
nextPageToken - is approximate, not exact
resultSizeEstimate
Gmail Query Syntax
Operators:
- - Emails from sender
from:sender@example.com - - Emails to recipient
to:recipient@example.com - - Subject contains exact phrase
subject:"exact phrase" - - Unread messages
is:unread - - Starred messages
is:starred - - Snoozed messages
is:snoozed - - Has attachments
has:attachment - - After date (YYYY/MM/DD)
after:2024/01/01 - - Before date
before:2024/12/31 - - User-created label (use label ID)
label:custom_label - - In sent folder
in:sent - - Primary category
category:primary
Combinators:
- - Both conditions (default)
AND - - Either condition
OR - - Exclude condition
NOT - - Group conditions
()
Examples:
- - Unread emails from boss
from:boss@company.com is:unread - - Invoices with attachments this year
subject:invoice has:attachment after:2024/01/01 - - Starred emails from Alice or Bob
(from:alice OR from:bob) is:starred
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
data_previewdata.messages - Parse defensively with fallbacks
- Timestamp uses RFC3339 with 'Z' suffix
messageTimestamp - Normalize to '+00:00' for parsing if needed
Attachments:
- Attachment from prior download may expire
s3key - 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) |