Skip to main content
Glama
README.md
# Gmail MCP Local

A local, read-only Gmail connector for Codex and other MCP clients. Search your inbox, read specific messages, and use your assistant to summarize threads or draft replies in chat.

The server runs on your computer and calls Google directly. It requests only [`gmail.readonly`](https://developers.google.com/workspace/gmail/api/auth/scopes), stores authorization in your operating system's credential store, and exposes two read-only tools. Emails you ask the assistant to read become part of its context and are subject to your assistant provider's data settings.

## Try it with example emails

Install Python 3.11 or newer and Git. Codex CLI is optional if you use the desktop app's MCP settings.

### macOS or Linux

```sh
git clone https://github.com/sorokin-as/gmail-mcp-local.git
cd gmail-mcp-local
python3 -m venv .venv
.venv/bin/python -m pip install .
codex mcp add gmail-local-demo -- "$PWD/.venv/bin/gmail-mcp-local" serve --demo
```

### Windows PowerShell

```powershell
git clone https://github.com/sorokin-as/gmail-mcp-local.git
Set-Location gmail-mcp-local
py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install .
$gmailMcp = Join-Path (Get-Location) ".venv\Scripts\gmail-mcp-local.exe"
codex mcp add gmail-local-demo -- $gmailMcp serve --demo
```

For the desktop app, go to **Settings → MCP servers → Add server**, choose **STDIO**, and enter the absolute path to the `gmail-mcp-local` executable above (ending in `.exe` on Windows). Pass `serve` and `--demo` as separate arguments. Save and restart the app. [Codex MCP setup](https://learn.chatgpt.com/docs/extend/mcp?surface=cli#connect-codex-to-an-mcp-server)

In a new Codex chat, try:

> Use gmail-local-demo to find unread emails. Read the result and draft a reply in this chat.

Demo mode works offline. It uses two fictional messages and supports `in:inbox`, `is:unread`, and plain search words.

## Connect your Gmail account

1. Open [Google's Personal mode setup](https://console.cloud.google.com/auth/overview/personal). Create a Google OAuth client of type **Desktop app** under the Google account you plan to connect and download its JSON. Enable [Gmail API](https://console.cloud.google.com/apis/library/gmail.googleapis.com) for the same project. Keep the downloaded JSON outside your checkout. If you have an **External / Testing** project instead, add your mailbox as a test user. Google expires those authorizations after seven days.
2. Authorize in your browser by running the following command with the path to your own JSON file. On Linux, start and unlock a desktop session with a Freedesktop Secret Service provider first. macOS uses Keychain and Windows uses Credential Locker.

   ```sh
   .venv/bin/gmail-mcp-local login --client "$HOME/Downloads/client_secret_example.json"
   ```

   On Windows PowerShell:

   ```powershell
   & $gmailMcp login --client "$env:USERPROFILE\Downloads\client_secret_example.json"
   ```

3. Add a second MCP server named `gmail-local` using the same executable and the single argument `serve`. For macOS or Linux with Codex CLI:

   ```sh
   codex mcp add gmail-local -- "$PWD/.venv/bin/gmail-mcp-local" serve
   ```

   On Windows PowerShell:

   ```powershell
   codex mcp add gmail-local -- $gmailMcp serve
   ```

4. In a new chat, try:

   > Use gmail-local to find five unread inbox emails. Read the ones that need an answer and draft replies here.

Each person creates their own Google OAuth client. Managed Google Workspace accounts may need administrator approval. Running `login` again replaces the locally saved account.

## Tools

| Tool | Input | Result |
| --- | --- | --- |
| `gmail_search` | Gmail query such as `in:inbox is:unread` or `from:alex@example.com newer_than:7d`, limit of 1–10 | Message IDs, sender, subject, date, unread status, and an indicator for more matches |
| `gmail_read` | Message ID from search, optional character limit up to 20,000 | Message text and headers, plus an indicator if the body was truncated |

The connector reads inline plain text and converts HTML-only messages to text. It never loads tracking images, follows email links, or downloads attachments. Messages that store their body separately from the Gmail message payload report the body as unavailable. Treat message content as untrusted, including instructions that ask the assistant to disclose data or perform actions.

## Disconnect

Run `gmail-mcp-local logout` using the executable from your virtual environment to delete the authorization stored on this computer. To revoke it at Google as well, remove the OAuth app in [Google Account connections](https://myaccount.google.com/connections). Run `codex mcp remove gmail-local` or remove the entry in desktop settings.

## Development

From the repository directory, use your virtual environment's Python:

```sh
python -m pip install -e .
python -m unittest discover -s tests -v
```

The tests use fictional messages and a stub Gmail API. No Google credentials are required.

TDQS

A3.6/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct roles: gmail_search finds messages and returns IDs, while gmail_read consumes one of those IDs to retrieve the full message. There is no realistic overlap or risk of misselection.

Naming Consistency5/5

Both tools follow the same gmail_<verb> convention, with concise and predictable names. The naming pattern is fully consistent.

Tool Count3/5

Two tools is thin for a Gmail integration, even a local/read-only one. Search and read form a coherent minimum, but the surface feels under-scoped for common Gmail workflows.

Completeness3/5

Search plus read covers basic message retrieval, but there are notable gaps such as thread retrieval, label/listing operations, attachments, and any write operations like send or draft. Agents can work around some gaps, but not all common Gmail tasks are supported.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues