Gmail MCP Tool for Cline
A Model Context Protocol (MCP) server that provides Gmail integration capabilities for Cline or other MCP-compatible AI assistants.
Overview
This tool allows Cline to interact with your Gmail account to:
- List and read emails - View emails in your inbox, search for specific messages, and read their contents
- Draft and send emails - Create drafts, modify them, and send emails on your behalf
- Organize your inbox - Apply labels, move messages between folders, and set up filtering rules
Architecture
The Gmail MCP tool is built using:
- TypeScript - For type-safe development
- MCP SDK - To expose tools and resources to Cline
- Google API Node.js Client - For Gmail API interactions
- OAuth2 Authentication - For secure access to your Gmail account
Gmail API Capabilities
This tool implements the following Gmail API functionalities:
Email Reading & Management
- List emails with filtering options
- Read complete email content
- Apply/remove labels
- Move emails between folders
- Advanced search capability using Gmail's query syntax
Email Composition & Sending
- Create new draft emails
- Update existing drafts
- Send new emails or drafts
- Reply to or forward existing emails
Mail Rules & Automation
- Create and manage labels
- Define filtering rules for incoming mail
- View and modify existing filters
Initial Setup
Prerequisites
- A Google Cloud Project with the Gmail API enabled
- OAuth client credentials (client ID and client secret)
- Node.js and npm installed
Setup Steps
-
Create a Google Cloud Project:
- Go to Google Cloud Console
- Create a new project
- Enable the Gmail API
- Create OAuth consent screen (External) with your email in test users
- Create OAuth client credentials (Web application)
- Download the credentials JSON file
-
Get a refresh token:
- Run the included script:
node scripts/get-refresh-token.js - Follow the authentication flow in your browser
- Copy the refresh token from the output
- Run the included script:
-
Configure MCP settings:
- Add the Gmail MCP server configuration to your MCP settings file:
"gmail": {
"command": "node",
"args": ["/path/to/gmail-mcp/build/index.js"],
"env": {
"GMAIL_CLIENT_ID": "your-client-id",
"GMAIL_CLIENT_SECRET": "your-client-secret",
"GMAIL_REFRESH_TOKEN": "your-refresh-token"
},
"disabled": false,
"autoApprove": []
}
Available Tools
The Gmail MCP server provides the following tools for Cline:
Email Reading
gmail_list_messages- List emails with filtering optionsgmail_get_message- Get detailed content of a specific emailgmail_search- Search emails with Gmail's query syntax
Email Management
gmail_modify_message- Apply/remove labels or mark as read/unreadgmail_trash_message- Move message to trashgmail_delete_message- Permanently delete message
Email Composition
gmail_create_draft- Create a new draft emailgmail_update_draft- Update an existing draftgmail_delete_draft- Delete a draftgmail_send_draft- Send an existing draftgmail_send_message- Create and send a new email directly
Reply & Forward
gmail_create_reply- Create a reply to an emailgmail_create_forward- Create a forward of an email
Label Management
gmail_list_labels- List all labels in the accountgmail_create_label- Create a new labelgmail_delete_label- Delete a labelgmail_update_label- Modify a label's properties
Filter Management
gmail_list_filters- List all filters in the accountgmail_create_filter- Create a new filtergmail_delete_filter- Delete a filter
Development
Building from source
# Install dependencies
npm install
# Build the project
npm run build
Project Structure
src/index.ts- Main MCP server implementationsrc/gmail-client.ts- Gmail API wrappersrc/tool-definitions.ts- Tool schema definitionssrc/auth-utils.ts- Authentication utilitiesscripts/get-refresh-token.js- OAuth refresh token generation
Privacy and Security
This tool runs locally on your machine and requires OAuth credentials to access your Gmail account. Your email data is never stored outside your control.
It's recommended to:
- Use a dedicated Google Cloud Project
- Limit the permissions requested during OAuth
- Regularly rotate your refresh token
Limitations
- Subject to Gmail API rate limits and quotas
- Complex filtering rules may require multiple operations
- Attachments over a certain size may need special handling
Roadmap
Future enhancements may include:
- Email template management
- Scheduled sending capabilities
- Advanced filtering and organization tools
- Attachment handling improvements
- Integration with other Google services (Calendar, Drive)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT