communication
Gmail CLI for Coding Agents
Use the Gmail CLI for coding agents with headless JSON commands, schema discovery, credentials, and permission controls.
16 functions 9 read 7 write OAuth browser flow auth
Gmail CLI for Coding Agents
Let coding agents discover schemas and execute integration functions through CLI commands or MCP.
Use this pattern when another coding agent needs exact commands and schema discovery. The Gmail CLI uses the same integration registry as the TUI, Lua runtime, and MCP gateway, but returns predictable command output for automation.
Command Shape
# Gmail CLI for Coding Agents
kosmokrator integrations:configure gmail --set access_token="$GMAIL_ACCESS_TOKEN" --enable --read allow --write ask --json
kosmo integrations:call gmail.gmail_add_labels '{"message_id":"example_message_id","message_ids":"example_message_ids","label_ids":"example_label_ids"}' --json Discovery Before Execution
Agents and scripts can inspect Gmail docs and schemas before choosing a function.
kosmo integrations:docs gmail --json
kosmo integrations:docs gmail.gmail_add_labels --json
kosmo integrations:schema gmail.gmail_add_labels --json
kosmo integrations:search "Gmail" --json
kosmo integrations:list --json Useful Gmail CLI Functions
| Function | Type | Parameters | Description |
|---|---|---|---|
gmail.gmail_add_labels | Write | message_id, message_ids, label_ids | Add labels to one or more Gmail messages. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_archive | Read | message_id, message_ids | Archive one or more Gmail messages (remove from inbox). Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_create_draft | Write | to, subject, body, cc, bcc | Create a draft email in Gmail (not sent). |
gmail.gmail_mark_read | Write | message_id, message_ids | Mark one or more Gmail messages as read. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_mark_unread | Write | message_id, message_ids | Mark one or more Gmail messages as unread. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_read | Read | message_id, format | 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 | message_id, message_ids, label_ids | Remove labels from one or more Gmail messages. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_reply | Read | message_id, thread_id, body, to, cc, bcc | Reply to an existing Gmail message (maintains the thread). |
gmail.gmail_count_by_sender | Read | query, label_ids | 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 | none | List all labels in the Gmail mailbox (INBOX, SENT, custom labels, etc.). |
gmail.gmail_save_attachment | Read | message_id, attachment_id, filename, mime_type | 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 | query, max_results, page_token, label_ids | 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 | draft_id | Send a previously created Gmail draft by its ID. |
gmail.gmail_send_email | Write | to, subject, body, cc, bcc | Send an email directly via Gmail. |
gmail.gmail_trash | Read | message_id, message_ids | Move one or more Gmail messages to trash. Provide messageIds (comma-separated) for batch operations. |
gmail.gmail_untrash | Read | message_id, message_ids | Remove one or more Gmail messages from trash. Provide messageIds (comma-separated) for batch operations. |
Automation Notes
- Use
--jsonfor machine-readable output. - Keep credentials out of argv by using environment variables or stored KosmoKrator configuration.
- Configure read/write policy before unattended runs; use
--forceonly for trusted automation. - Use the MCP gateway instead when the agent needs dynamic tool discovery inside a conversation.