> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/en/build/integrate/google-workspace-connector.md). Agents can also search and read this documentation through its [MCP server](https://docs.maiagent.ai/~gitbook/mcp).

# Google Workspace Connector

Use the built-in Google Workspace connector (MCP) to let Agents search Gmail messages, Google Calendar events, and Google Drive documents

## Use Case: A Work Agent That Finds Email, Events, and Documents <a href="#use-case" id="use-case"></a>

Much of everyday work involves finding things: the quotation attachment a customer sent last week, the time of this afternoon's meeting, or the latest version of an SOP in a shared drive. This information is scattered across Gmail, Google Calendar, and Google Drive, requiring employees to switch between tabs to search.

With MaiAgent's built-in **Google Workspace connector**, an Agent can access these services through an authorized Google account and find and organize information with a single request, for example:

* “Find the email the supplier sent last week with a quotation attached, and organize the amounts into a table.”
* “What meetings do I have tomorrow afternoon? Are any of them video calls with customers?”
* “Are there any new employee training presentations in Drive? Give me the links.”

{% hint style="info" %}
**About this page**

This page shows how to add the Google Workspace connector to a custom Agent as an <mark style="color:blue;">MCP</mark> tool. For full details on tool fields and OAuth authorization, see [Create an MCP Tool](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/mcp-setup.md#oauth-connector). For members connecting their own accounts in MaiGPT, see [Connectors](https://docs.maiagent.ai/maiagent-user-guide/en/work/maigpt/connectors.md). For connectors in official built-in Agents, see [Manage Official Built-in Agents › Connectors](https://docs.maiagent.ai/maiagent-user-guide/en/org/management.md#connectors).
{% endhint %}

## How It Works <a href="#how-it-works" id="how-it-works"></a>

The Google Workspace connector is a Remote MCP server maintained by MaiAgent and registered in the platform's connector list (with its source labeled “Built-in”). You do not need to host a server or enter a server URL. It uses OAuth 2.0 authorization:

1. Click to authorize, and you are redirected to Google's sign-in and consent screens.
2. Select a Google account, review the permissions listed, and grant consent.
3. Return to MaiAgent. Credentials are encrypted and stored on the backend, not in the browser.
4. The Agent then calls services such as Gmail, Calendar, and Drive using this Google account.

### Available Services and Access Levels <a href="#scopes" id="scopes"></a>

When members authorize the Google Workspace connector in MaiGPT, a “<mark style="color:blue;">Select Authorization Scopes</mark>” window appears first. They can adjust each service's access level to grant only the permissions they need:

| Service                            | Available Access Levels (Defaults)                                              |
| ---------------------------------- | ------------------------------------------------------------------------------- |
| Google Drive                       | Read-only / Files created by this app only / Full access (default: Full access) |
| Gmail                              | Send only / Send and manage (default: Send and manage)                          |
| Google Calendar                    | Read-only / Full access (default: Full access)                                  |
| Google Sheets, Docs, Slides, Forms | Enable or disable each service individually (all enabled by default)            |

With Gmail set to “Send only,” the Agent can send email but cannot search or read messages. To let the Agent search email, keep “Send and manage” selected.

When authorizing through a tool (using “Organization-wide” or “Individual Contact Authorization” below), review the permissions you are granting on Google's consent screen.

{% hint style="warning" %}
**Available actions depend on the retrieved tool list**

The actions an Agent can perform depend on the tool list the platform retrieves from the MCP server after authorization (for example, searching email, reading attachment contents, or retrieving download links). Different authorization scopes provide different tools. Check the list under “<mark style="color:blue;">Allowed Tools</mark>,” and **do not promise actions in the role instructions that are absent from the list** (for example, if there is no tool for sending email, do not let the Agent promise to send a message).
{% endhint %}

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* Your role has <mark style="color:blue;">tool permissions</mark> to create and edit tools (ask your organization administrator to check [Role and Permission Management](https://docs.maiagent.ai/maiagent-user-guide/en/org/roles/role-permission.md)).
* A Google account to authorize, belonging to a Google Workspace that allows third-party app access. If the Workspace administrator restricts third-party OAuth apps, Google will reject authorization. Ask the administrator to allow the app.
* Decide whose account to authorize: should this Agent use **one account shared across the organization**, or should **each user sign in to their own account**? See the explanation below.

## Workflow <a href="#workflow" id="workflow"></a>

### 1. Create a Google Workspace Tool <a href="#step1-create-tool" id="step1-create-tool"></a>

#### Open Tool Management and Select MCP <a href="#open-tool-form" id="open-tool-form"></a>

From the left menu, go to <mark style="color:blue;">AI Features</mark> → <mark style="color:blue;">Tools</mark>, then click <mark style="color:blue;">Add Tool</mark> in the upper right. Select <mark style="color:blue;">MCP</mark> as the tool type, and enter a display name (such as `Google Workspace Work Assistant`) and a tool description.

#### Select Google Workspace from the Connector Cards <a href="#pick-connector" id="pick-connector"></a>

Under “<mark style="color:blue;">Select a Service to Connect</mark>,” click the **Google Workspace** card. The system fills in the MCP server URL automatically and handles authentication through OAuth, so you do not need to enter a key in the headers.

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-8c46200f2a5265891f745d958d24cc7a1b28097e%2Fgoogle-workspace-connector-picker.png?alt=media" alt="The Google Workspace connector card is selected, showing OAuth 2.0 and “Search Gmail messages, query calendar events, and read Drive documents”"><figcaption><p>Select the Google Workspace card</p></figcaption></figure>

#### Choose Whose Account to Authorize <a href="#choose-auth-subject" id="choose-auth-subject"></a>

After selecting the card, use “<mark style="color:blue;">Authorization Subject</mark>” to choose whose Google account the Agent will use. For the general rules for the two options, see [Create an MCP Tool: Choose the Authorization Subject](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/mcp-setup.md#oauth-auth-subject). For Google Workspace:

| Authorization Subject                                             | Suitable Scenarios                                                                                                                    | Notes                                                                                                                                                                                                                                |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <mark style="color:blue;">Organization-wide</mark>                | Searching a shared mailbox, shared calendar, or departmental shared drive; Agents available to anonymous visitors on LINE or Web Chat | All users access data through the account of the person who authorized it. **Do not use a personal mailbox for shared authorization.**                                                                                               |
| <mark style="color:blue;">Individual Contact Authorization</mark> | Employees searching their own email, events, and files                                                                                | Requires identified users (signed in, or identified by a Source ID passed from the website). **The Agent will not receive this tool in conversations with anonymous visitors or visitors who have only filled out a Pre-chat form.** |

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-ab9f1e357542632edf59cbaab6f295ad2a0b56b2%2Fgoogle-workspace-contact-auth.png?alt=media" alt="Individual Contact Authorization is selected, with a notice that individual authorization requires a signed-in user"><figcaption><p>When “Individual Contact Authorization” is selected, a notice explains that anonymous visitors will not have access to this tool</p></figcaption></figure>

#### Complete Authorization and Select Tools <a href="#authorize-and-fetch" id="authorize-and-fetch"></a>

* **Organization-wide**: Click “<mark style="color:blue;">Authorize</mark>,” then sign in and grant consent in the Google window. Once complete, the screen displays “<mark style="color:blue;">Authorized</mark>,” and the system automatically retrieves and saves the tool list. Open this tool again, enable only the tools this Agent needs under “<mark style="color:blue;">Allowed Tools</mark>,” and click “<mark style="color:blue;">Confirm</mark>.”
* **Individual Contact Authorization**: No authorization is needed here. The first time a contact uses the tool in a conversation, an authorization card appears in the conversation so they can authorize it with their own Google account. Web Chat users can later view or disconnect it in [Connected Services](https://docs.maiagent.ai/maiagent-user-guide/en/build/choose-channel/web-chat/connected-services.md). Administrators can view, revoke, or trigger reauthorization from the “<mark style="color:blue;">Connector Authorization</mark>” tab in the “<mark style="color:blue;">Contacts</mark>” edit window.

{% hint style="warning" %}
The authorization window opens as a pop-up. If your browser blocks pop-ups, allow pop-ups for this site, then click “<mark style="color:blue;">Authorize</mark>” again.
{% endhint %}

### 2. Create an Agent and Configure Its Tools <a href="#step2-create-assistant" id="step2-create-assistant"></a>

Create a new Agent (or edit an existing one). Under “<mark style="color:blue;">Response Mode Settings</mark>,” switch the response mode to <mark style="color:blue;">Agent</mark>, then select the Google Workspace tool you just created on the “<mark style="color:blue;">Tools</mark>” tab. For detailed steps, see [Configure Tools for an Agent](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/configure_tools.md).

Use the following role instructions as a reference. Clearly explain what to do before authorization and prohibit pretending that an action was performed:

```
You are an internal work assistant. You can use Google Workspace tools to search the user's Gmail messages and attachments, query Google Calendar events, and search documents in Drive.

Principles:
1. Confirm the time range and keywords before searching. If they are unclear, ask one clarifying question before searching.
2. Base your answers only on tool results. Include the email subject, sender, and date, or the file name and link. If nothing is found, say so directly. Do not guess.
3. If a tool response indicates missing or expired authorization, explain that Google authorization must be completed first and ask the user to follow the on-screen instructions. Do not repeatedly retry the tool call.
4. Do not ask users for account passwords or any credentials.
5. When working with email contents, summarize only the parts relevant to the task. Do not reproduce the entire message.
```

{% hint style="info" %}
If this Agent is for **organization members** to use in MaiGPT or internal Q\&A, you can also bind connectors enabled by the organization on the “<mark style="color:blue;">MaiGPT Connectors</mark>” tab in the Agent settings (Agent mode only), in addition to adding tools. Members authorize these connectors individually. To enable connectors for the organization, see [Manage Connectors (Administrators)](https://docs.maiagent.ai/maiagent-user-guide/en/work/maigpt/connectors/connectors-admin.md).
{% endhint %}

### 3. Put It into Use <a href="#step3-go-live" id="step3-go-live"></a>

Once configured, test it in the Agent's chat interface. Here are some common questions and how the Agent handles them:

| User Question                                                       | What the Agent Does                                                                                         |
| ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| “Find emails sent by Finance last week with Excel attachments.”     | Searches messages by sender, time, and attachment criteria, and lists subjects, dates, and attachment names |
| “What is this email attachment about? Summarize it for me.”         | Reads the attachment contents and summarizes the key points                                                 |
| “What free slots do I have for a one-hour meeting later this week?” | Reads calendar events and organizes available time slots                                                    |
| “Are there any spreadsheets about the ‘annual budget’ in Drive?”    | Searches Drive and returns file names and links                                                             |

You can review each tool call's parameters and results in [Tool Execution Records](https://docs.maiagent.ai/maiagent-user-guide/en/build/agent-ops/tool-execution-records.md) to check whether the Agent used the right tool and whether authorization is still valid.

## Read Gmail Attachments <a href="#gmail-attachments" id="gmail-attachments"></a>

For example, after connecting Google Workspace in MaiGPT, a sales assistant asks: “Find the quotation email the demo supplier sent last week, and summarize the items and amounts in the PDF attachment.” The Agent finds the email and downloads the attachment. The attachment is first saved as a file in this conversation, then the Agent reads the PDF contents and replies with a summary of the items and amounts.

Members can connect Google Workspace in MaiGPT through ＋ → <mark style="color:blue;">Connectors</mark> next to the chat input. Services that have not been authorized display <mark style="color:blue;">Authorize</mark> on the right. After authorization, they display <mark style="color:blue;">Enabled</mark> and a toggle. For steps, see [Connectors](https://docs.maiagent.ai/maiagent-user-guide/en/work/maigpt/connectors.md#how-to-connect).

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-a9c1d353f1b7548df82a33e22962073bf6c8acc9%2Fgoogle-workspace-connector-maigpt-authorize.png?alt=media" alt="The ＋ menu is expanded to show “Connectors.” Connected services list Google Workspace (Enabled, toggle on), Microsoft 365 (with an Authorize button on the right), and Google Analytics"><figcaption><p>MaiGPT ＋ → Connectors: Google Workspace is authorized and enabled</p></figcaption></figure>

### How Attachments Are Read <a href="#how-attachments-are-read" id="how-attachments-are-read"></a>

1. After the Agent downloads an attachment through the connector, it is saved as **a file in this conversation** and used only in this conversation. The tool response in the conversation shows only a single line with the save result (file name, type, and size), without the attachment's raw encoded data. The system assigns the saved file name (for example, `gmail_get_attachment-1.pdf`); it is not the original name from the email.
2. The Agent then uses the <mark style="color:blue;">Parse Attachment Content</mark> system function to read the contents (for plain text files, it can also use <mark style="color:blue;">Read Plain Text Attachment</mark>). Both are under <mark style="color:blue;">Advanced Settings</mark> → <mark style="color:blue;">System Functions</mark> in the Agent settings. See [Control System Functions](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/configure_tools.md#control-system-functions). If both are disabled, the attachment is still saved in the conversation, but the Agent explains that it cannot read it here.
3. If you ask about the same attachment later in the same conversation, the Agent can retrieve it from this conversation's file list without downloading it again. See [Retrieve Files from This Conversation](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/configure_tools.md#conversation-files).

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-4fa0619197d2042efd965eea3094e534347f6b9c%2Fgoogle-workspace-gmail-attachment-pdf.png?alt=media" alt="A MaiGPT conversation: the user asks the Agent to summarize the PDF attachment in a quotation email from the docs-line demo supplier. The execution steps are Gmail List Messages, Gmail Get Message, Gmail Get Attachment, and processed files. The response lists Item A 1,200, Item B 3,400, and a total of 4,600"><figcaption><p>The Agent downloads a Gmail PDF attachment, saves it in the conversation, then reads and summarizes its contents</p></figcaption></figure>

### Supported Attachment Formats <a href="#supported-attachment-formats" id="supported-attachment-formats"></a>

| Type            | Formats                                                                                                                                          |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Documents       | PDF; Word (.docx, .doc, .odt); Excel (.xlsx, .xls, .ods); PowerPoint (.pptx, .ppt, .odp)                                                         |
| Email files     | Outlook messages (.msg)                                                                                                                          |
| Text and tables | CSV and plain text, in either UTF-8 or Big5 encoding (Chinese text in CSV files saved from Traditional Chinese Excel can also be read correctly) |
| Images          | PNG, JPEG, GIF, WebP, TIFF, BMP; contents are read using image recognition                                                                       |
| Audio           | MP3, WAV, M4A, AAC; processed as audio attachments. M4A recordings from both iPhone and Android phones are supported                             |

### Attachments That Cannot Be Read <a href="#unreadable-attachments" id="unreadable-attachments"></a>

The following attachments are not saved in the conversation. The Agent receives their size and the reason they cannot be read (for example, exceeding the size limit, or an unsupported format such as an archive or video), and explains this to the user:

* **Exceeds the size limit**: Attachments larger than the platform's attachment parsing limit (10 MB by default)
* **Corrupted Office files and encrypted .docx, .xlsx, and .pptx files**
* **Archives and executables**: For example, ZIP, RAR, 7-Zip, and gzip archives, and executable files
* **Video**: MP4 or QuickTime videos with visual content (audio-only M4A recordings are unaffected)

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-3d2d92aa9acca1119911cb2cf23ce82bef96655c%2Fgoogle-workspace-gmail-attachment-too-large.png?alt=media" alt="The Gmail Get Attachment tool response says the attachment was not saved in the conversation (not saved as an attachment), with a size of 11 MB. The Agent replies that the attachment is an 11 MB ZIP file, exceeding the 10 MB attachment processing limit, so its contents cannot be read"><figcaption><p>When an attachment exceeds the size limit, the Agent explains why it cannot be read</p></figcaption></figure>

Encrypted legacy .doc and .xls files are saved in the conversation, but their contents also cannot be read during parsing.

{% hint style="info" %}
To let the Agent search and read email attachments, members must keep Gmail set to “Send and manage” when authorizing. See [Available Services and Access Levels](#scopes).
{% endhint %}

## FAQ <a href="#faq" id="faq"></a>

**Q: Google displays “This app is blocked” during authorization, or I cannot select my company account.**\
A: Your company's Google Workspace administrator has restricted third-party OAuth apps. Ask the Workspace administrator to allow the MaiAgent app in the Admin console, then authorize again.

**Q: It worked before, but now the Agent says authorization is no longer valid.**\
A: The Google authorization token may have expired or been revoked. For organization-wide authorization, open the tool, click “<mark style="color:blue;">Revoke</mark>,” then “<mark style="color:blue;">Authorize</mark>” again. For individual contact authorization, users can click “<mark style="color:blue;">Reauthorize</mark>” in [Connected Services](https://docs.maiagent.ai/maiagent-user-guide/en/build/choose-channel/web-chat/connected-services.md), or an administrator can trigger reauthorization from the “<mark style="color:blue;">Connector Authorization</mark>” tab in the “<mark style="color:blue;">Contacts</mark>” edit window.

**Q: How do I revoke authorization?**\
A: For organization-wide authorization, click “<mark style="color:blue;">Revoke</mark>” in the tool settings. For individual contact authorization, users can disconnect it in [Connected Services](https://docs.maiagent.ai/maiagent-user-guide/en/build/choose-channel/web-chat/connected-services.md), and administrators can also revoke it from the “<mark style="color:blue;">Connector Authorization</mark>” tab in the “<mark style="color:blue;">Contacts</mark>” edit window. To also remove the record on Google's side, remove MaiAgent's access under “Third-party apps & services” in your Google Account.

**Q: Can the Agent send email, create events, or write to files on behalf of users?**\
A: This depends on the authorization scopes and the retrieved tool list. First confirm that the corresponding tools (such as sending email or creating events) appear under “<mark style="color:blue;">Allowed Tools</mark>,” then include those actions in the role instructions. When members authorize in MaiGPT, select “Send and manage” for Gmail and “Full access” for Calendar.

## Further Reading <a href="#further-reading" id="further-reading"></a>

* [Create an MCP Tool](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/mcp-setup.md): Full details on MCP tool fields and OAuth connectors
* [Configure Tools for an Agent](https://docs.maiagent.ai/maiagent-user-guide/en/build/tools/configure_tools.md)
* [Tool Execution Records](https://docs.maiagent.ai/maiagent-user-guide/en/build/agent-ops/tool-execution-records.md)
* [Connected Services](https://docs.maiagent.ai/maiagent-user-guide/en/build/choose-channel/web-chat/connected-services.md): Users manage their own authorization
* [Connectors](https://docs.maiagent.ai/maiagent-user-guide/en/work/maigpt/connectors.md): Members authorize connections themselves in MaiGPT
* [Manage Official Built-in Agents › Connectors](https://docs.maiagent.ai/maiagent-user-guide/en/org/management.md#connectors): Connector authorization for official built-in Agents


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/en/build/integrate/google-workspace-connector.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
