Use the Gmail CLI from KosmoKrator to call Gmail tools headlessly, return JSON, inspect schemas, and automate workflows from coding agents, scripts, and CI.
Gmail can be configured headlessly with `kosmokrator integrations:configure gmail`.
# Install KosmoKrator first if it is not available on PATH.curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash# Configure and verify this integration.kosmokrator integrations:configure gmail --set access_token="$GMAIL_ACCESS_TOKEN" --enable --read allow --write ask --jsonkosmokrator integrations:doctor gmail --jsonkosmokrator integrations:status --json
Credentials
Authentication type: OAuth browser flowoauth2_authorization_code. Configure credentials once, then use the same stored profile from
scripts, coding CLIs, Lua code mode, and the MCP gateway.
Key
Env var
Type
Required
Label
access_token
GMAIL_ACCESS_TOKEN
OAuth token oauth
yes
Google Account
Call Gmail Headlessly
Use the generic call form when another coding CLI or script needs a stable universal interface.
Every function below can be called headlessly. The generic form is stable across all integrations;
the provider shortcut is shorter but specific to Gmail.
gmail.gmail_add_labels
Write write
Add labels to one or more Gmail messages. Provide messageIds (comma-separated) for batch operations.
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.
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".
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.
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.
Recipient email address (defaults to original sender).
cc
string
no
CC recipients (comma-separated emails).
bcc
string
no
BCC recipients (comma-separated emails).
gmail.gmail_count_by_sender
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".
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.
Headless calls still follow the integration read/write permission policy. Configure read/write defaults
with integrations:configure. Add --force only for trusted automation that should bypass that policy.