An MCP server that lets AI agents search Gmail threads, understand your email writing style, and create draft emails.
- Go 1.25+
- A Google Cloud project with the Gmail API enabled (see Google Setup)
- Optional: an OpenAI API key for auto-generating a personal writing style guide
# 1. Build
make build
# 2. Run (stdio mode — your MCP client manages the process)
GMAIL_CLIENT_ID=... GMAIL_CLIENT_SECRET=... ./bin/gmail-mcp-server
# 3. Or as a persistent HTTP server on port 6633
GMAIL_CLIENT_ID=... GMAIL_CLIENT_SECRET=... ./bin/gmail-mcp-server --http
# Show all flags
./gmail-mcp-server help
./gmail-mcp-server --helpOn first run a browser window opens for Gmail OAuth. Approve it once — the token is cached locally for subsequent runs.
- Open Google Cloud Console
- Create a new project (or reuse an existing one)
- Go to APIs & Services → Library, search for Gmail API, click Enable
- Go to APIs & Services → Credentials → Create Credentials → OAuth Client ID
- If prompted, configure the OAuth consent screen:
- User type: External
- Fill in App name, support email, developer email
- Add your own email under Test users
- Application type: Desktop application
- Click Create — copy the Client ID and Client Secret
| Scope | Why |
|---|---|
gmail.readonly |
Search and read emails, download attachments |
gmail.compose |
Create and update drafts |
The server never sends emails or deletes anything.
Build the image once from the project root:
podman build -t localhost/gmail-mcp-server .Create a named volume for the OAuth token (persists across container restarts):
podman volume create gmail-mcp-dataRun the server:
podman run -d --name gmail-mcp-server \
-p 6633:6633 \
-v gmail-mcp-data:/config \
-e GMAIL_CLIENT_ID=<your-client-id> \
-e GMAIL_CLIENT_SECRET=<your-client-secret> \
-e XDG_CONFIG_HOME=/config \
localhost/gmail-mcp-serverFirst run — authorize Gmail access:
open http://localhost:6633/authThe page shows a Google link and a short verification code. Click the link, sign in, enter the code if prompted, and the page updates to show "Authorized". The token is saved in the volume — no restart needed.
Register with Claude Code (once, after authorizing):
claude mcp add --transport http --scope user gmail http://localhost:6633/mcpSubsequent runs just start the container — the cached token is loaded from
the volume automatically. Visit /auth at any time to check status or
re-authorize if the token ever expires.
git clone https://github.com/your-org/gmail-mcp-server
cd gmail-mcp-server
make build # produces bin/gmail-mcp-server
make install # copies to $GOPATH/bin/gmail-mcp-serverDownload from the Releases page. Binaries are available for:
- Linux amd64 / arm64
- macOS amd64 / arm64
- Windows amd64
Option A: credentials.json file (recommended for local use)
Download the credentials file directly from Google Cloud Console:
- Go to APIs & Services → Credentials
- Click the pencil icon next to your OAuth client → Download JSON
- Save the file as
credentials.jsonin the config directory
The file looks like this:
{
"installed": {
"client_id": "123….apps.googleusercontent.com",
"project_id": "my-project",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"client_secret": "GOCSPX-…",
"redirect_uris": ["http://localhost"]
}
}Run ./gmail-mcp-server help to see the exact config directory path on your machine.
Option B: environment variables (recommended for MCP client configs / containers)
| Variable | Description |
|---|---|
GMAIL_CLIENT_ID |
OAuth client ID (…apps.googleusercontent.com) |
GMAIL_CLIENT_SECRET |
OAuth client secret |
Variables can be set in the MCP client config env block, exported in your shell, or placed in a .env file in the working directory.
Environment variables take precedence over credentials.json if both are present.
The server stores token.json and personal-email-style-guide.md here:
| Platform | Primary | Fallback |
|---|---|---|
| Linux | $XDG_CONFIG_HOME/gmail-mcp-server (~/.config/gmail-mcp-server) |
— |
| macOS | ~/.config/gmail-mcp-server |
~/Library/Application Support/gmail-mcp-server (used if it already exists) |
| Windows | %AppData%\gmail-mcp-server |
— |
Run ./gmail-mcp-server --help or the /server-status prompt to see the exact path on your machine.
The MCP client launches a new server process each time. OAuth can prompt on every restart — use HTTP mode to avoid that.
Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json on Mac,
%APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"gmail": {
"command": "/path/to/gmail-mcp-server",
"env": {
"GMAIL_CLIENT_ID": "your_client_id.apps.googleusercontent.com",
"GMAIL_CLIENT_SECRET": "your_client_secret"
}
}
}
}Cursor (~/.cursor/mcp.json on Mac/Linux, %USERPROFILE%\.cursor\mcp.json on Windows) — same format.
Start the server once — OAuth happens at startup, then all clients share the same authenticated process:
# Default port 6633
./gmail-mcp-server --http
# Custom port
./gmail-mcp-server --http --port 3000Then point your client at the MCP endpoint instead of a command:
{
"mcpServers": {
"gmail": {
"url": "http://localhost:6633/mcp"
}
}
}Endpoint exposed in HTTP mode:
POST /mcp— MCP JSON-RPC (streamable HTTP transport)
| Tool | Description |
|---|---|
search_threads |
Search Gmail with Gmail query syntax + quarter shorthand |
fetch_email_bodies |
Fetch full body content for specific thread IDs |
create_draft |
Create a new draft or overwrite an existing one in a thread |
extract_attachment_by_filename |
Extract plain text from PDF, DOCX, or TXT attachments |
get_personal_email_style_guide |
Return the personal writing style guide |
search_threads expands quarter references before querying Gmail:
| You write | Gmail receives |
|---|---|
Q1 2026 |
after:2026/01/01 before:2026/04/01 |
Q2 2026 |
after:2026/04/01 before:2026/07/01 |
Q3 2026 |
after:2026/07/01 before:2026/10/01 |
Q4 2025 |
after:2025/10/01 before:2026/01/01 |
Quarter references combine freely with other Gmail operators:
from:boss@company.com Q1 2026
has:attachment Q4 2025
subject:invoice Q2 2026 is:unread
file://personal-email-style-guide— your personal email writing style (auto-generated or manual)
/server-status— show config paths and authentication status
Create personal-email-style-guide.md in the config directory to give the AI your preferred tone and conventions. The file is returned by the get_personal_email_style_guide tool and the file://personal-email-style-guide resource before any draft is written.
make build # → bin/gmail-mcp-server
make install # → $GOPATH/bin/gmail-mcp-server
make test # race detector + coverage profile
make test-coverage # test + HTML coverage report
make test-short # skip slow/integration tests
make lint # golangci-lint
make fmt # gofmt + goimports
make tidy # go mod tidy + verify
make release-snapshot # local GoReleaser snapshot (no publish)
make release # publish tagged release (requires GITHUB_TOKEN)Cross-platform releases (Linux, macOS, Windows × amd64/arm64) are produced by GoReleaser.