# Gmail — how to use (mcp.ai)

Read, search and send Gmail messages straight from your AI agent.

## Option A — via MCP (recommended)
Remote MCP endpoint (HTTP, streamable): `https://api.mcp.ai/p_gmail?ms=1796396040000`
Add it as a custom/remote MCP connector in your client (Claude, Cursor, VS Code…), then authenticate when prompted. Once connected, ask the agent to use the server's tools (e.g. `gmail_list`).

## Option B — via direct REST API
Base URL: `https://api.mcp.ai/api/gmail`
Auth: `Authorization: Bearer sk_live_…` — create a workspace API key at https://new.mcp.ai/settings/api-keys
Discover endpoints: `GET https://api.mcp.ai/api/gmail/_endpoints`

### Endpoints
- `POST https://api.mcp.ai/api/gmail/add/label/to/email` — Adds and/or removes specified gmail labels for a message; ensure `message id` and all `label ids` are valid (use 'listlabels' for custom label ids).
  - body: { user_id?: string, message_id: string, add_label_ids?: string[], remove_label_ids?: string[] }
- `POST https://api.mcp.ai/api/gmail/create/email/draft` — Creates a gmail email draft, supporting to/cc/bcc, subject, plain/html body (ensure `is html=true` for html), attachments, and threading.
  - body: { cc?: string[], bcc?: string[], body: string, is_html?: boolean, subject: string, user_id?: string, thread_id?: string, attachment?: object, recipient_email: string, extra_recipients?: string[] }
- `POST https://api.mcp.ai/api/gmail/create/label` — Creates a new label with a unique name in the specified user's gmail account.
  - body: { user_id?: string, label_name: string, text_color?: string, background_color?: string, label_list_visibility?: string, message_list_visibility?: string }
- `POST https://api.mcp.ai/api/gmail/delete/draft` — Permanently deletes a specific gmail draft using its id; ensure the draft exists and the user has necessary permissions for the given `user id`.
  - body: { user_id?: string, draft_id: string }
- `POST https://api.mcp.ai/api/gmail/delete/message` — Permanently deletes a specific email message by its id from a gmail mailbox; for `user id`, use 'me' for the authenticated user or an email address to which the authenticated user has delegated access
  - body: { user_id?: string, message_id: string }
- `POST https://api.mcp.ai/api/gmail/fetch/emails` — Fetches a list of email messages from a gmail account, supporting filtering, pagination, and optional full content retrieval.
  - body: { query?: string, user_id?: string, verbose?: boolean, ids_only?: boolean, label_ids?: string[], page_token?: string, max_results?: integer, include_payload?: boolean, include_spam_trash?: boolean }
- `POST https://api.mcp.ai/api/gmail/fetch/message/by/message/id` — Fetches a specific email message by its id, provided the `message id` exists and is accessible to the authenticated `user id`.
  - body: { format?: string, user_id?: string, message_id: string }
- `POST https://api.mcp.ai/api/gmail/fetch/message/by/thread/id` — Retrieves messages from a gmail thread using its `thread id`, where the thread must be accessible by the specified `user id`.
  - body: { user_id?: string, thread_id: string, page_token?: string }
- `POST https://api.mcp.ai/api/gmail/get/attachment` — Retrieves a specific attachment by id from a message in a user's gmail mailbox, requiring valid message and attachment ids (and `file_name`). The returned download link (`s3url`) is temporary and expires in about 1 hour; its path part can be reused as `s3key` to forward the file in /send/email, /reply/to/thread or /create/email/draft.
  - body: { user_id?: string, file_name: string, message_id: string, attachment_id: string }
- `POST https://api.mcp.ai/api/gmail/get/contacts` — Fetches contacts (connections) for the authenticated google account, allowing selection of specific data fields and pagination.
  - body: { page_token?: string, person_fields?: string, resource_name?: string, include_other_contacts?: boolean }
- `POST https://api.mcp.ai/api/gmail/get/people` — Retrieves either a specific person's details (using `resource name`) or lists 'other contacts' (if `other contacts` is true), with `person fields` specifying the data to return.
  - body: { page_size?: integer, page_token?: string, sync_token?: string, person_fields?: string, resource_name?: string, other_contacts?: boolean }
- `POST https://api.mcp.ai/api/gmail/get/profile` — Retrieves key gmail profile information (email address, message/thread totals, history id) for a user.
  - body: { user_id?: string }
- `POST https://api.mcp.ai/api/gmail/list/drafts` — Retrieves a paginated list of email drafts from a user's gmail account. use verbose=true to get full draft details including subject, body, sender, and timestamp.
  - body: { user_id?: string, verbose?: boolean, page_token?: string, max_results?: integer }
- `POST https://api.mcp.ai/api/gmail/list/labels` — Retrieves a list of all system and user-created labels for the specified gmail account.
  - body: { user_id?: string }
- `POST https://api.mcp.ai/api/gmail/list/threads` — Lists email threads in the Gmail account, with filtering and pagination. The filter is `query` (alias `q`, as in the Gmail API), in Gmail search syntax, e.g. `from:apple.com newer_than:2d`. `maxResults` and `pageToken` are accepted as aliases of `max_results` and `page_token`. The response includes `nextPageToken` for the next page. `resultSizeEstimate` is only Gmail's estimate and may be the same with or without a filter: count the returned `threads`. `labelIds` is not supported here; filter by label in `query` (`label:INBOX`) or use `/fetch/emails` with `label_ids`.
  - body: { query?: string, user_id?: string, verbose?: boolean, page_token?: string, max_results?: integer }
- `POST https://api.mcp.ai/api/gmail/modify/thread/labels` — Adds or removes specified existing label ids from a gmail thread, affecting all its messages; ensure the thread id is valid.
  - body: { user_id?: string, thread_id: string, add_label_ids?: string[], remove_label_ids?: string[] }
- `POST https://api.mcp.ai/api/gmail/move/to/trash` — Moves an existing, non-deleted email message to the trash for the specified user.
  - body: { user_id?: string, message_id: string }
- `POST https://api.mcp.ai/api/gmail/patch/label` — Patches the specified label.
  - body: { id: string, name?: string, color?: object, userId: string, labelListVisibility?: string, messageListVisibility?: string }
- `POST https://api.mcp.ai/api/gmail/remove/label` — Permanently deletes a specific, existing user-created gmail label by its id for a user; cannot delete system labels.
  - body: { user_id?: string, label_id: string }
- `POST https://api.mcp.ai/api/gmail/reply/to/thread` — Sends a reply within a specific gmail thread using the original thread's subject, requiring a valid `thread id` and correctly formatted email addresses. supports attachments via the `attachment` param
  - body: { cc?: string[], bcc?: string[], is_html?: boolean, user_id?: string, thread_id: string, attachment?: object, message_body: string, recipient_email: string, extra_recipients?: string[] }
- `POST https://api.mcp.ai/api/gmail/search/people` — Searches contacts by matching the query against names, nicknames, emails, phone numbers, and organizations, optionally including 'other contacts'.
  - body: { query: string, pageSize?: integer, person_fields?: string, other_contacts?: boolean }
- `POST https://api.mcp.ai/api/gmail/send/draft` — Sends the specified, existing draft to the recipients in the to, cc, and bcc headers.
  - body: { user_id?: string, draft_id: string }
- `POST https://api.mcp.ai/api/gmail/send/email` — Sends an email via gmail api using the authenticated user's google profile display name, requiring `is html=true` if the body contains html and valid `s3key`, `mimetype`, `name` for any attachment.
  - body: { cc?: string[], bcc?: string[], body: string, is_html?: boolean, subject?: string, user_id?: string, attachment?: object, recipient_email: string, extra_recipients?: string[] }
- `POST https://api.mcp.ai/api/gmail/upload/attachment` — Uploads a file (by public URL or base64) and returns `{ s3key, mimetype, name }` ready to pass in the `attachment` parameter of /send/email, /reply/to/thread or /create/email/draft. Use it to attach a file that is not already in Gmail.
  - body: { filename: string, url?: string, content_base64?: string, mimetype?: string }
- `POST https://api.mcp.ai/api/gmail/history/list` — Mailbox changes since a historyId (incremental sync). A too-old historyId returns 404 `history_id_expired`: do a full sync with list/threads and use the historyId from get/profile.
  - body: { user_id?: string, start_history_id: string, history_types?: string[], label_id?: string, max_results?: integer, page_token?: string }
- `POST https://api.mcp.ai/api/gmail/batch/modify/messages` — Add and/or remove labels on up to 1000 messages in one call (mark read, archive, star).
  - body: { ids: string[], add_label_ids?: string[], remove_label_ids?: string[], user_id?: string }
- `POST https://api.mcp.ai/api/gmail/fetch/messages` — Fetch 1 to 50 messages by id in Gmail's format. `messages[]` in request order; a failing id goes to `errors[]` without failing the batch.
  - body: { ids: string[], format?: string, metadata_headers?: string[] }

## More
- Page: https://new.mcp.ai/gmail
- Agent spec (llms.txt): https://new.mcp.ai/gmail/llms.txt
- Postman collection: https://new.mcp.ai/gmail/postman.json
