Gmail MCP Server
A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Gmail through secure OAuth 2.0 authentication. Send emails, search messages, read emails, and manage multiple Gmail accounts directly from Claude Desktop.
README
Gmail MCP Server
A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Gmail through secure OAuth 2.0 authentication. Send emails, search messages, read emails, and manage multiple Gmail accounts directly from Claude Desktop.
Features
- Secure OAuth 2.0 Authentication - No passwords stored, tokens auto-refresh
- Multiple Account Support - Manage multiple Gmail accounts simultaneously
- Email Operations - Send, search, and read emails with full Gmail API support
- Advanced Search - Use Gmail's powerful search operators
- Real-time Integration - Works seamlessly with Claude Desktop
Quick Start
-
Setup Google Cloud Console:
- Create a project and enable Gmail API
- Create OAuth 2.0 credentials for desktop application
- Download credentials as
credentials.json
-
Install and Build:
npm install npm run build -
Configure Claude Desktop:
- Place
credentials.jsonin Claude Desktop's directory - Update
claude_desktop_config.jsonwith server path - Restart Claude Desktop
- Place
-
Start Using:
Send an email to john@example.com with subject "Hello" and body "Testing Gmail MCP"
Architecture
Built with TypeScript and follows MCP specifications:
- Entry Point:
src/index.ts- Main MCP server setup and tool definitions - Gmail Client:
src/gmail-client.ts- Gmail API wrapper with OAuth authentication - Authentication:
src/auth.ts- OAuth 2.0 credential management - Types:
src/types.ts- TypeScript interfaces and type definitions
Development
# Development mode with hot reload
npm run dev
# Test with MCP Inspector
npm run inspect
# Build for production
npm run build
Security
- Uses minimal required Gmail scopes (read and send only)
- Tokens stored locally with automatic refresh
- No email content stored permanently
- All operations performed locally
Complete User Guide
Overview
This Gmail MCP Server allows Claude Desktop to interact with your Gmail account through secure OAuth 2.0 authentication. You can send emails, search messages, read emails, and manage multiple Gmail accounts.
Prerequisites
- Node.js (version 18 or higher)
- Claude Desktop application installed
- Gmail account with API access enabled
- Google Cloud Console project with Gmail API enabled
Setup Instructions
1. Google Cloud Console Setup
-
Create a Google Cloud Project:
- Go to Google Cloud Console
- Create a new project or select an existing one
-
Enable Gmail API:
- Navigate to "APIs & Services" → "Library"
- Search for "Gmail API" and enable it
-
Create OAuth 2.0 Credentials:
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth 2.0 Client IDs"
- Choose "Desktop application"
- Download the credentials JSON file
- Important: This file will need to be placed in Claude Desktop's directory later
-
Configure OAuth Consent Screen:
- Go to "APIs & Services" → "OAuth consent screen"
- Add your email as a test user
- Set scopes:
https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/gmail.send
2. Project Setup
-
Clone and Install:
git clone <repository-url> cd gmail-mcp npm install -
Add Google Credentials:
- Rename your downloaded credentials file to
credentials.json - Place it in Claude Desktop's working directory (not the project directory)
- Location varies by OS:
- macOS:
~/Library/Application Support/Claude/ - Windows:
%APPDATA%\Claude\ - Linux:
~/.config/claude/
- macOS:
- Important: Never commit this file to version control
- Rename your downloaded credentials file to
-
Build the Project:
npm run build -
Test the Setup:
npm run inspectThis opens the MCP Inspector for testing tools before connecting to Claude Desktop.
3. Claude Desktop Integration
-
Locate Claude Desktop Config:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
- macOS:
-
Update Configuration:
{ "mcpServers": { "gmail": { "command": "node", "args": ["/absolute/path/to/your/gmail-mcp/build/index.js"] } } }Replace
/absolute/path/to/your/gmail-mcp/with the actual path to your project. -
Restart Claude Desktop:
- Close and reopen Claude Desktop
- The Gmail MCP server should now be available
First-Time Authentication
When you first use Gmail tools through Claude Desktop:
-
Browser Authentication:
- A browser window will open automatically
- Sign in with your Gmail account
- Grant the requested permissions
-
Token Storage:
- Authentication tokens are stored in the
accounts/directory within Claude Desktop's directory - These tokens auto-refresh and are valid for 6 months of inactivity
- Authentication tokens are stored in the
Available Tools
Email Operations
Send Email:
Send an email to john@example.com with subject "Meeting Tomorrow" and body "Don't forget our meeting at 2 PM"
Search Emails:
Search for emails from support@company.com in the last week
Read Email:
Read the email with message ID [message-id]
Account Management
List Accounts:
Show me all configured Gmail accounts
Add Account:
Add Gmail account jane@example.com
Remove Account:
Remove Gmail account old@example.com
Set Default Account:
Set primary@example.com as the default account
Usage Examples
Basic Email Operations
-
Send a simple email:
Send an email to team@company.com with subject "Project Update" and tell them the project is on track -
Search for recent emails:
Find all emails from my manager in the last 3 days -
Read a specific email:
Read the latest email from notifications@github.com
Multi-Account Usage
-
Send from specific account:
Send an email from work@company.com to client@example.com about the project status -
Search in specific account:
Search for invoices in my personal@gmail.com account
Advanced Gmail Search
Gmail search queries support operators like:
from:sender@example.comsubject:meetinghas:attachmentnewer_than:7dis:unread
Example:
Search for unread emails with attachments from the last week
Security & Privacy
Authentication Security
- Uses OAuth 2.0 with minimal required scopes
- Tokens stored locally in encrypted format
- No passwords stored anywhere
- Automatic token refresh
Data Privacy
- No email content is stored permanently
- All operations are performed locally
- No data sent to third parties
- Audit logs available in Claude Desktop
Best Practices
- Set restrictive file permissions on
credentials.jsonin Claude Desktop's directory - Regularly review OAuth consent screen
- Remove unused accounts
- Monitor token usage in Google Cloud Console
- Keep
credentials.jsonsecure - it's stored in Claude Desktop's directory for access by the MCP server
Troubleshooting
Common Issues
"No account specified and no default account set":
- Solution: Add an account using
add_accounttool or set a default account
"Authentication failed":
- Check if
credentials.jsonexists in Claude Desktop's directory (not the project directory) - Verify Gmail API is enabled in Google Cloud Console
- Try removing and re-adding the account
"Token expired":
- Tokens auto-refresh, but manual re-authentication may be needed
- Remove and re-add the account if issues persist
Claude Desktop not detecting MCP server:
- Verify the absolute path in config file
- Check that the build directory exists
- Restart Claude Desktop after config changes
Development and Testing
Test tools without Claude Desktop:
npm run inspect
Development mode with hot reload:
npm run dev
View server logs:
- Check Claude Desktop logs for MCP server output
- Use Inspector tool for detailed request/response debugging
File Structure
Project Directory:
gmail-mcp/
├── build/ # Compiled JavaScript (auto-generated)
├── src/ # TypeScript source code
├── package.json # Project dependencies
└── CLAUDE.md # Project instructions for Claude
Claude Desktop Directory (where credentials.json goes):
~/.config/claude/ # Linux
~/Library/Application Support/Claude/ # macOS
%APPDATA%\Claude\ # Windows
├── credentials.json # Google OAuth credentials (you provide)
├── accounts/ # Account tokens (auto-generated when using tools)
└── claude_desktop_config.json # Claude Desktop configuration
Limitations
- Rate limits: Gmail API has daily quotas
- Scope limitations: Only read and send permissions
- Token expiry: Tokens expire after 6 months of inactivity
- File attachments: Not currently supported for sending
- HTML emails: Limited formatting support
Getting Help
If you encounter issues:
- Check the troubleshooting section above
- Test with the MCP Inspector (
npm run inspect) - Review Google Cloud Console for API quotas and errors
- Check Claude Desktop logs for MCP server messages
Advanced Configuration
Custom Scopes
Modify the scopes in src/auth.ts if you need additional Gmail permissions.
Multiple Projects
You can run multiple instances for different Google Cloud projects by using different configuration names in Claude Desktop.
Development
See CLAUDE.md for development guidelines and architecture details.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.