Overview
The Gmail integration can work in two modes:- Tool-only mode: Agent has Gmail tools (read, send, search, draft) available when triggered from other channels
- Channel mode: Incoming emails can trigger the agent and receive automatic replies
Installation
Run the/add-gmail skill in Claude Code:
Google Cloud Setup
Create GCP Project
- Go to console.cloud.google.com
- Create a new project or select an existing one
Configure Consent Screen
- Go to APIs & Services → OAuth consent screen
- Choose External user type
- Fill in:
- App name (e.g., “NanoClaw Gmail”)
- User support email (your email)
- Developer contact email (your email)
- Click Save and Continue
- Skip adding scopes (the library handles this)
- Add yourself as a test user
- Click Save and Continue
Configuration
Install OAuth Credentials
Copy the downloaded credentials to~/.gmail-mcp/:
Authorize Access
Run the authorization flow:- Open your browser
- Ask you to sign in to Google
- Show an “app isn’t verified” warning (this is normal for personal OAuth apps)
- Ask for Gmail permissions
- Save credentials to
~/.gmail-mcp/credentials.json
If you see “This app isn’t verified” warning, click Advanced → Go to [app name] (unsafe). This is normal for personal OAuth apps that haven’t gone through Google’s verification process.
Rebuild Container
The Gmail integration requires rebuilding the agent container (for MCP server changes):Tool-Only Mode
In tool-only mode, the agent has these Gmail tools available:| Tool | Purpose |
|---|---|
mcp__gmail__get_profile | Get Gmail account info |
mcp__gmail__list_labels | List all Gmail labels |
mcp__gmail__search_emails | Search emails with Gmail query syntax |
mcp__gmail__get_email | Get full email content by ID |
mcp__gmail__send_email | Send a new email |
mcp__gmail__create_draft | Create a draft email |
Example Usage
From any registered channel:Channel Mode
In channel mode, the Gmail integration polls your inbox and triggers the agent when new emails arrive.How It Works
- Polling: Checks for unread emails every 60 seconds (configurable)
- Filtering: By default, only emails in Primary inbox trigger the agent (Promotions, Social, Updates, Forums excluded)
- Processing: Agent receives email content and can use Gmail tools to reply
- Notification: Agent is notified in the main channel about new emails
Email Filtering
Default filter query:- Only unread emails
- Only emails in the Primary inbox category
- Excludes Promotions, Social, Updates, and Forums
You can customize the filter query by modifying the
searchQuery parameter in the GmailChannel constructor in src/channels/gmail.ts.Thread Tracking
The channel tracks email threads to enable proper reply handling:Email Notification Format
When a new email arrives, the agent receives:Troubleshooting
OAuth Token Expired
Tokens expire after a period of inactivity. Re-authorize:Gmail Connection Not Responding
Test the connection directly:- Credentials exist:
ls -la ~/.gmail-mcp/ - Credentials are valid JSON:
cat ~/.gmail-mcp/credentials.json | jq - OAuth keys are valid:
cat ~/.gmail-mcp/gcp-oauth.keys.json | jq
Container Can’t Access Gmail
The container needs~/.gmail-mcp mounted. Verify in src/container-runner.ts:
Emails Not Being Detected (Channel Mode)
Check Filter Query
The default filter is
is:unread category:primary. Emails in Promotions, Social, etc. are excluded.“App isn’t verified” Warning
This is normal for personal OAuth apps. Click:- Advanced
- Go to [app name] (unsafe)
- Allow
Implementation Details
Dependencies
googleapis- Google APIs client library (channel mode only)@gongrzhe/server-gmail-autoauth-mcp- MCP server with Gmail tools (both modes)
JID Format
- Channel mode:
gmail:<thread-id>(e.g.,gmail:18a1b2c3d4e5f6g7)
Self-Registration Code (Channel Mode)
Polling Logic
Error Backoff
If polling fails, the interval increases exponentially:Removal
Tool-Only Mode
- Remove
~/.gmail-mcpmount fromsrc/container-runner.ts - Remove
gmailMCP server fromcontainer/agent-runner/src/index.ts - Remove
gmailfrom.nanoclaw/state.yaml - Clear stale agent-runner:
rm -r data/sessions/*/agent-runner-src 2>/dev/null || true - Rebuild:
cd container && ./build.sh && cd .. && npm run build - Restart service
Channel Mode
- Delete
src/channels/gmail.tsandsrc/channels/gmail.test.ts - Remove
import './gmail.js'fromsrc/channels/index.ts - Follow steps 1-6 from tool-only mode removal
- Uninstall:
npm uninstall googleapis
Next Steps
Channel Overview
Learn about the channel system
WhatsApp Channel
Set up WhatsApp integration