> ## Documentation Index
> Fetch the complete documentation index at: https://context7.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Integration

> Sync Google Docs and Google Slides from Drive folders, Shared Drives and single files, and keep them current every day

Context7 can sync Google Docs and Google Slides from Google Drive and serve them like any other library. Google Drive stays the source of truth: a daily sync picks up edits, and files that are removed or no longer shared leave the results.

An admin connects Google once under **Workspace Settings › Google**. Then an admin chooses which folders, Shared Drives, Docs and presentations to sync from **Add source → Google Drive**, **Google Docs** or **Google Slides**. All three use the same connection. Only the selected items, and the Docs and presentations under selected folders, are indexed.

> [!NOTE]
>
> Google Docs and Google Slides are supported. Spreadsheets, PDFs and other file types in a selected folder are skipped. The picker marks them as not supported.

## Choose a connection method

Context7 reads Drive as one Google identity, and sees only what that identity can open. It always uses one read-only scope:

| Scope | Why |
| - | - |
| `https://www.googleapis.com/auth/drive.readonly` | List the selected folders, export Google Docs and read Google Slides. Context7 never writes to Drive. |

There are three ways to give Context7 that identity:

| Method | Identity Google sees | Needs | Good fit when |
| - | - | - | - |
| **Google account** | A dedicated Workspace user, such as `context7-bot@yourcompany.com` | An internal OAuth client, and one sign-in by an admin | Your organization blocks service account keys or sharing outside your domain |
| **Service account key** | A service account, or a Workspace user through domain-wide delegation | A JSON key for the service account | Your organization allows service account keys |
| **Server credentials** | A service account, through the server's own credentials | Context7 on GKE with Workload Identity, or workload identity federation from AWS, Azure or another OIDC provider | You do not want any key or token stored in Context7 |

> [!TIP]
>
> If your security team blocks service account keys and sharing outside your domain, use **Google account**. It needs no key and no domain-wide delegation, and nothing is shared outside your organization.

Open **Workspace Settings › Google** and choose the method under **Authentication**. Each method has a **Set up Google Cloud** panel with the steps below. Enter your project ID there, and the panel fills it into the commands.

### Compare the security trade-offs

Every method uses the same read-only scope, and Context7 stores any secret encrypted. The methods differ in what Context7 holds, which identity Google sees, and what someone could read with a leaked credential:

| | Google account | Service account key | Service account key with delegation | Server credentials |
| - | - | - | - | - |
| What Context7 stores | The OAuth client secret and a refresh token | The service account's JSON key | The service account's JSON key | Nothing. The server's environment holds the credentials. |
| Identity Google sees | The Context7 Workspace user | The service account | The user in **Act as user** | The service account |
| You share folders with | The Context7 Workspace user | The service account, an `iam.gserviceaccount.com` address outside your domain | The user in **Act as user** | The service account, outside your domain |
| Super admin approval | No | No | Yes, for domain-wide delegation | No |
| Redirect URI | An HTTPS name under a public top-level domain, only for a **Web application** client. The host can stay internal | No | No | No |
| A leaked credential can read | What is shared with the Context7 user | What is shared with the service account | Drive as any user in your domain | What is shared with the service account |
| To revoke access | Click **Disconnect**, which also asks Google to revoke the sign-in (if that fails, remove the access in the Google account's security settings), or suspend the Context7 user | Delete the key in Google Cloud | Remove the client ID from domain-wide delegation, and delete the key | Remove the service account binding for the workload |

**Disconnect** on the **Google** page removes the stored credentials. For a service account key, the key stays valid at Google until you delete it there. Libraries keep their indexed content after a disconnect, but they stop syncing until you connect again with the same method, account and **Act as user**. A new key for the same service account is fine.

## Google account

Context7 signs in as a Workspace user that exists only for Context7. You share folders with that user like with any colleague.

**1. Enable the Drive and Slides APIs**

In the Google Cloud console, select a project that belongs to your Workspace organization. Open **APIs & Services → Library** and enable the **Google Drive API** and the **Google Slides API**, or run:

```bash theme={null}
gcloud services enable drive.googleapis.com slides.googleapis.com --project=PROJECT_ID
```

**2. Configure the consent screen as Internal**

Open [Google Auth Platform](https://console.cloud.google.com/auth/overview) and click **Get started**. Enter an app name such as "Context7", and under **Audience** choose **Internal**. Only users of your organization can sign in, and Google does not need to verify the app.

**3. Create an OAuth client**

Open [Clients](https://console.cloud.google.com/auth/clients), click **Create client**, and choose a client type:

* **Web application**: Under **Authorized redirect URIs**, add the redirect URI that the settings page shows, for example `https://context7.yourcompany.com/api/google/oauth/callback`. After the sign-in, Google sends the browser back to Context7. Google accepts only an HTTPS URI with a domain under a public top-level domain, so this does not work for an IP address or a name such as `context7.corp`. The host can still be reachable only from your network.
* **Desktop app**: Use this when Context7 has no such address. The client needs no redirect URI. After the sign-in, Google opens an address on `127.0.0.1` that does not load. You copy that address from the browser's address bar and paste it into **Address after sign-in**.

Copy the client ID and the client secret into **OAuth client ID** and **OAuth client secret**.

**4. Create a Workspace user for Context7**

In the [Google Admin console](https://admin.google.com/ac/users), add a user only for Context7, such as `context7-bot@yourcompany.com`. Like any Workspace user, it usually takes a paid license seat. Do not use a person's account: Context7 can read everything this account can open, and the connection stops if the account is suspended or deleted.

**5. Share your folders with that user**

In Google Drive, share each folder with the Context7 user with **Viewer** access, or add the user to each Shared Drive as a **Viewer**.

**6. Sign in as that user**

Click **Sign in with Google** and sign in as the Context7 user, not as yourself. On Google's account list, choose **Use another account**. If Google says the app is blocked, a Workspace admin turns on **Trust internal, domain-owned apps** in [Security → API controls](https://admin.google.com/ac/owl).

Context7 stores the client secret and the sign-in's refresh token encrypted, and never returns them from any API. If Google later refuses the sign-in, for example because the account was suspended or its sessions were revoked, the settings page shows **Reconnect required** and syncs fail until an admin clicks **Reconnect** and signs in again.

## Service account key

Context7 signs in as a service account with a JSON key.

**1. Create the service account and its key**

Run these commands in [Cloud Shell](https://shell.cloud.google.com/) or with the gcloud CLI. Replace `PROJECT_ID` with your project ID. The first command enables the Google Drive API and the Google Slides API. The service account needs no IAM roles in the project.

```bash theme={null}
gcloud services enable drive.googleapis.com slides.googleapis.com --project=PROJECT_ID
gcloud iam service-accounts create context7-drive \
  --display-name="Context7 Drive sync" --project=PROJECT_ID
gcloud iam service-accounts keys create context7-drive-key.json \
  --iam-account=context7-drive@PROJECT_ID.iam.gserviceaccount.com
```

Organizations created on or after May 3, 2024 block service account keys by default with the `iam.disableServiceAccountKeyCreation` policy. If Google refuses to create the key, ask an organization admin to [allow keys for this project](https://cloud.google.com/resource-manager/docs/secure-by-default-organizations), or use another method.

**2. Paste the key**

Paste the contents of `context7-drive-key.json` into **Service account JSON key**, then delete the file. Click **Test connection**, then click **Connect**.

Context7 checks the key with Google before it saves it, stores it encrypted, and never returns it from any API. The settings page shows only the service account's email and the last characters of the key ID. To rotate the key, paste the new key and save.

**3. Share the content**

In Google Drive, share each folder you want to sync with the service account's email address, with **Viewer** access. For a Shared Drive, add the service account as a member with the **Viewer** role. The email ends in `iam.gserviceaccount.com`, so if Drive does not allow sharing outside your organization, ask a Workspace admin to allow it for the service account, or use domain-wide delegation.

### Domain-wide delegation (optional)

If sharing with the service account is not practical, the service account can act as one Workspace user and see what that user sees. You then share folders with that user, so nothing is shared outside your domain.

1. Copy the service account's client ID. It is `client_id` in the JSON key, and the **Set up Google Cloud** panel shows it after you paste the key.
2. A Workspace super admin opens [Domain-wide delegation](https://admin.google.com/ac/owl/domainwidedelegation) in the Google Admin console (**Security → Access and data control → API controls**) and clicks **Add new**.
3. They enter that client ID and the scope `https://www.googleapis.com/auth/drive.readonly`.
4. In Context7, enter the user's email address in **Act as user**.

> [!WARNING]
>
> Context7 acts only as the user in **Act as user**. But Google lets a service account with domain-wide delegation read Drive as any user in your domain, within the allowed scope. Protect the key accordingly, and expect your security team to review this setup.

> [!NOTE]
>
> Without delegation, the service account can read only what is explicitly shared with it. This keeps the approved content small and visible in Drive's sharing settings, so prefer it when you can.

## Server credentials

Context7 uses the server's Application Default Credentials, so no key is stored in Context7:

* `GOOGLE_APPLICATION_CREDENTIALS` pointing at a key file or a [workload identity federation](https://cloud.google.com/iam/docs/workload-identity-federation) configuration, for example for AWS or an OIDC provider.
* [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) when the server runs on GKE.

Create the service account as for a key, without the key command. For workload identity federation, let your workload identity pool act as the service account, and write the credential file. Replace the uppercase values with your pool, provider, subject and token file. On AWS or Azure, use `--aws` or `--azure` instead of `--credential-source-file`:

```bash theme={null}
gcloud services enable sts.googleapis.com iamcredentials.googleapis.com --project=PROJECT_ID
SA=context7-drive@PROJECT_ID.iam.gserviceaccount.com
POOL=projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL_ID
gcloud iam service-accounts add-iam-policy-binding "$SA" \
  --role=roles/iam.workloadIdentityUser \
  --member="principal://iam.googleapis.com/$POOL/subject/SUBJECT"
gcloud iam workload-identity-pools create-cred-config "$POOL/providers/PROVIDER_ID" \
  --service-account="$SA" \
  --credential-source-file=TOKEN_FILE \
  --output-file=google-credentials.json
```

Set `GOOGLE_APPLICATION_CREDENTIALS` to the path of `google-credentials.json` on the Context7 server, and restart it. Then share your folders with the service account as for a key, click **Test connection**, and click **Connect**.

Domain-wide delegation is not available in this mode.

## Test the connection

**Test connection** checks the credentials with Google and lists the first folders, files and Shared Drives that the identity can see. If the list is empty, share a folder with the identity, then test again. After you connect, the page shows the identity's email with a copy button.

## Add a library

Go to **Add** and choose a Google source:

* **Google Drive** syncs folders, Shared Drives, Docs and presentations.
* **Google Docs** and **Google Slides** sync single files of that kind. Folders and Shared Drives stay browsable but cannot be selected.

The picker is a tree of your Shared Drives and the items shared with the Context7 identity:

* Click a folder or Shared Drive to open it. Its contents load when you open it, and long lists load more as you scroll.
* Type in the search box to find folders and files by name in all of Drive, also inside folders that you have not opened.
* Check a folder or Shared Drive to select all of it. Later syncs then also pick up new files in it. If you uncheck items inside it, only its checked items are selected.
* **Selected** shows what the library will contain. A library can have up to 200 selected items.

Enter a title and click **Start sync**. The description is optional. The selection defines the library: to sync a different set of folders, add another library.

Each Doc is indexed under its Google URL, for example `https://docs.google.com/document/d/<id>/edit`. That link is the `Source:` of every result, so an agent can point people to the original document. Results taken from a document's text also name it, as `Source: <Doc title> (<link>)`.

### Google Slides

Each slide of a presentation is indexed as its own page, with a link that opens that slide: `https://docs.google.com/presentation/d/<id>/edit#slide=id.<slide id>`. The slide's title becomes its heading, and its text, lists, links, tables and speaker notes follow. Results taken from a slide name the deck and the slide, as `Source: <deck name>, slide <n>: <slide title> (<link>)`. Hidden (skipped) slides are not indexed.

Elements are indexed in reading order: top to bottom, and left to right within a row. An image, chart or video contributes its alt text, as `*Image: …*`, `*Chart: …*` or `*Video: …*`, and a video that has one keeps its link. WordArt contributes its text. Auto-generated alt text, such as a file name or "Picture 3", is left out. Images, charts, diagrams and videos themselves are not indexed.

Docs index an image's alt text the same way, as `*Image: …*`.

When a presentation changes, Context7 reads the whole presentation again:

* A slide that did not change reuses its last extraction.
* A deleted slide leaves the results.
* If one slide fails to index, its last indexed version stays.
* If the presentation cannot be read, all its slides keep their last indexed version.
* A presentation with no visible slides counts as empty and leaves the results.

## How syncing works

Every sync lists the selected folders again and compares each file with the last sync:

| Change in Drive | What happens |
| - | - |
| A file was edited, renamed or moved inside the selection | It is read and indexed again. |
| A file did not change | Its indexed content is kept as it is. No LLM or embedding calls are made for it. |
| A file was deleted, trashed, moved out of the selection, or unshared | It leaves the results. |
| A selected folder or Shared Drive was deleted, trashed, or unshared | All its files leave the results, and the library page and the **Libraries** list in **Workspace Settings › Google** show a warning. Share it again to restore them. |
| A file was emptied, or has nothing to index | It leaves the results. It is checked again when it changes. |
| A new file appeared in a selected folder | It is indexed. |

A sync builds the new index next to the live one and swaps it in only when it finishes, so queries always see a complete library.

### Failures keep valid content

* **One file fails** (for example a Doc is larger than Drive's 10 MB export limit, or the LLM times out while extracting it): the last indexed version of that file stays in the results. The library page shows a warning, its logs list the file and the reason, the **Libraries** list in **Workspace Settings › Google** shows the failed files, and the next sync tries it again.
* **The whole sync fails** (for example Google refuses access because the Drive API is disabled, or Google cannot be reached): all live content stays as it was, and the error is shown in the library's logs.

> [!WARNING]
>
> Sharing is the approval. When a selected folder or Shared Drive is no longer shared with the Context7 identity, the next sync removes its files from the results. Check sharing changes before the daily sync if you want to keep the content.

Context7 retries Google API quota errors with exponential backoff and limits how many requests it sends at once.

## Scheduled sync

Google Drive libraries sync every day at 03:00 server time by default. Under **Sync schedule** on the **Google** page (**Workspace Settings › Google**), you can:

* turn the scheduled sync off,
* change the schedule: pick a preset such as **Every 6 hours**, or enter a cron expression such as `0 */6 * * *`,
* click **Sync all now** to queue every Google Drive library at once.

When a sync fails, scheduled or manual, Context7 retries that library after 15 minutes, 1 hour and 6 hours. Each delay counts from the previous attempt. To sync one library by hand, click **Refresh** on its page, or **Sync now** next to it in the **Libraries** list. To read and re-index every file instead of skipping unchanged ones, select **Re-index all files** in the Refresh dialog, or in the library's menu in the **Libraries** list.

Only an admin can refresh a Google Drive library, even when **Refresh repositories** is on in **Workspace Settings › Authorization**: the sync reads Drive with the connector's credentials.

## Monitor libraries

The **Libraries** list on the **Google** page (**Workspace Settings › Google**) shows every Google Drive library with its selection, its last sync, and a status:

| Status | Meaning |
| - | - |
| Synced | The last sync finished with no failed files. |
| Syncing or Queued | A sync is running or waiting in the parse queue. |
| N files failed | Some files could not be refreshed. Expand the row to see each file and the reason; their last indexed version is still served. |
| Folder unavailable | A selected folder or Shared Drive is no longer shared with the Context7 identity, and its files were removed. |
| Sync failed | The whole sync failed, so the library still serves its previous content. Expand the row for the error. |

Expanding a row shows the most common failure reasons and up to 50 failed files, each linked to Drive. **Download CSV** exports every failed file. Problem libraries sort to the top, and **Needs attention** filters the list to them.

## Authority labels

[Authority labels](https://context7.com/docs/enterprise/authority-labels.md) can match Google Drive content by path or by URL:

* A path pattern matches the file's folder path and file name inside the selection. For example, `/QA/Standards/Release sign-off` is the **Release sign-off** Doc in the **Standards** folder of a selected **QA** folder, and the prefix `/QA/Standards/` matches every file in that folder. For a Shared Drive, the path starts with the Shared Drive's name.
* A URL pattern matches the Doc's Google URL, for example `https://docs.google.com/document/d/<id>`.

For a presentation:

* A URL prefix `https://docs.google.com/presentation/d/<id>` matches every slide of that presentation.
* A path rule matches the presentation's path in Drive, for example `/QA/Standards/Release review` for the **Release review** presentation in the **Standards** folder, and applies to all its slides.

## Network access

The server talks only to Google:

| Host | Used for |
| - | - |
| `oauth2.googleapis.com` | Access tokens for a service account key or a Google account |
| `sts.googleapis.com` | Access tokens for workload identity federation |
| `iamcredentials.googleapis.com` | Access tokens for workload identity federation with service account impersonation |
| `www.googleapis.com` | The Drive API |
| `slides.googleapis.com` | The Slides API, for presentations |

Set `GOOGLE_DRIVE_API_URL` and `GOOGLE_SLIDES_API_URL` to send Drive and Slides API calls through another endpoint, such as a Private Google Access address or a proxy. Each value must include the API path, for example `https://www.googleapis.com/drive/v3` and `https://slides.googleapis.com/v1`.

With **Google account**, the admin's browser also opens `accounts.google.com` for the sign-in. To send the server's OAuth calls through another endpoint, set `GOOGLE_OAUTH_TOKEN_URL` (default `https://oauth2.googleapis.com/token`), `GOOGLE_OAUTH_REVOKE_URL` (default `https://oauth2.googleapis.com/revoke`) and `GOOGLE_OAUTH_AUTHORIZE_URL` (default `https://accounts.google.com/o/oauth2/v2/auth`).

## Troubleshooting

| Message | Fix |
| - | - |
| "The private\_key in the JSON key is damaged" | The key was cut or changed when it was copied. Paste the whole JSON file again, or create a new key. |
| "Nothing is shared with … yet" | The credentials work, but no folder or Shared Drive is shared with the Context7 identity. Share one with **Viewer** access, then test again. |
| "Google rejected the credentials" | Check the key. With delegation, check that the client ID is allowed the `drive.readonly` scope in the Admin console. |
| "Google denied access … Check that the Drive API is enabled" | Enable the Google Drive API in the Google Cloud project you connected. |
| "Google Slides API request failed (403 …)" | Enable the Google Slides API in the Google Cloud project you connected. |
| "No longer available to the Google connector: folder …" | The folder was deleted, trashed or unshared, and its files were removed. Share it with the Context7 identity again, then click **Refresh**. |
| "Google refused access to the selected folder …" | Check that the Drive API is enabled and that the connector can read the folder. Live content is kept until this is fixed. |
| "The document is larger than the 10 MB Google Drive export limit" | Split the document. Its last indexed version stays available. |
| "The selection has more than 10000 documents" | A library holds at most 10,000 Docs and presentations. Split the selection into several libraries, or raise the limit with the `GOOGLE_DRIVE_MAX_FILES` environment variable. |
| "Google no longer accepts the sign-in for … (invalid\_grant)" | The Google account was suspended, its password policy ended the session, or the access was revoked. Click **Reconnect** on the **Google** page and sign in as the Context7 user again. |
| Google says the app is blocked when you sign in | A Workspace admin turns on **Trust internal, domain-owned apps** in **Security → API controls**. |
| "redirect\_uri\_mismatch" when signing in | The redirect URI in the Web application client does not match the one the settings page shows. Copy it again, or use a Desktop app client. |
| "The Google connector was replaced by a different account" | The library was added with another service account, delegated user or Google account. Add the library again with the current connection. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.