gmail-mcp-server-rust

abhinav20sep/gmail-mcp-server-rust

3.2

If you are the rightful owner of gmail-mcp-server-rust and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

A high-performance Rust implementation of the Gmail MCP Server for Claude/AI integration via the Model Context Protocol.

Tools
19
Resources
0
Prompts
0

Gmail MCP Server (Rust)

License: MIT Rust

A high-performance Rust implementation of the Gmail MCP Server for Claude/AI integration via the Model Context Protocol.

Inspired by: GongRzhe/Gmail-MCP-Server (TypeScript)

This is a complete Rust rewrite providing better performance, memory safety, and native binaries.

Features

  • OAuth 2.0 Authentication: Secure Google OAuth flow with token refresh
  • Email Operations: Send, draft, read, search, modify, and delete emails
  • Attachment Support: Send emails with file attachments, download attachments
  • Label Management: Create, update, delete, and list Gmail labels
  • Filter Management: Create filters with criteria and actions, includes templates
  • Batch Operations: Efficient batch modify/delete for multiple messages
  • Full MCP Protocol: Implements the Model Context Protocol for AI tool integration
  • Comprehensive Tests: 61 tests (24 unit + 37 integration) with 0 clippy warnings

Available Tools (19 total)

ToolDescription
send_emailSend a new email (with optional attachments)
draft_emailCreate a draft email
read_emailRead a specific email by ID
search_emailsSearch emails with Gmail query syntax
modify_emailAdd/remove labels from an email
delete_emailMove email to trash
list_email_labelsList all Gmail labels
batch_modify_emailsModify labels on multiple emails
batch_delete_emailsDelete multiple emails
create_labelCreate a new label
update_labelUpdate a label's properties
delete_labelDelete a label
get_or_create_labelGet existing or create new label
create_filterCreate a new filter
list_filtersList all filters
get_filterGet a specific filter
delete_filterDelete a filter
create_filter_from_templateCreate filter from predefined templates
download_attachmentDownload an email attachment

Prerequisites

  • Rust 1.70+ (installed via rustup)
  • Google Cloud Project with Gmail API enabled
  • OAuth 2.0 credentials (Desktop app type)

Installation

Build from Source

git clone https://github.com/abhinav-copilot/gmail-mcp-server-rust.git
cd gmail-mcp-server-rust
cargo build --release

The binary will be at target/release/gmail-mcp-server.

Setup

1. Create Google Cloud OAuth Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Enable the Gmail API
  4. Go to Credentials → Create Credentials → OAuth 2.0 Client IDs
  5. Select "Desktop app" as application type
  6. Download the JSON file

2. Configure Credentials

Save the downloaded OAuth file as either:

  • ~/.gmail-mcp/gcp-oauth.keys.json (recommended)
  • ./gcp-oauth.keys.json (current directory)

Or set environment variable:

export GMAIL_OAUTH_PATH=/path/to/gcp-oauth.keys.json

3. Authenticate

# Run authentication flow
./gmail-mcp-server auth

This opens your browser for Google OAuth consent. After approval, credentials are stored in ~/.gmail-mcp/credentials.json.

Usage

Standalone Server

# Start the MCP server (communicates via stdio)
./gmail-mcp-server

With Claude Desktop / Cursor

Add to your MCP configuration (e.g., ~/.config/claude/claude_desktop_config.json):

{
  "mcpServers": {
    "gmail": {
      "command": "/path/to/gmail-mcp-server",
      "args": []
    }
  }
}

Sending Emails with Attachments

The send_email and draft_email tools support file attachments:

{
  "name": "send_email",
  "arguments": {
    "to": ["recipient@example.com"],
    "subject": "Document attached",
    "body": "Please see the attached file.",
    "attachments": ["/path/to/document.pdf", "/path/to/image.png"]
  }
}

Supported attachment types: PDF, Word, Excel, images (PNG, JPG, GIF), text, CSV, JSON, XML, ZIP.

Project Structure

src/
├── lib.rs               # Library crate root
├── main.rs              # Binary entry point, CLI handling
├── config.rs            # Configuration management
├── error.rs             # Error types with thiserror
├── gmail/
│   ├── mod.rs           # Gmail module exports
│   ├── types.rs         # Gmail API types (serde)
│   ├── auth.rs          # OAuth 2.0 authentication
│   ├── client.rs        # Gmail API client
│   ├── utils.rs         # Email utilities, attachment support
│   ├── labels.rs        # Label management
│   └── filters.rs       # Filter management
└── mcp/
    ├── mod.rs           # MCP module exports
    ├── types.rs         # MCP protocol types
    ├── server.rs        # MCP server (stdio transport)
    └── tools.rs         # Tool definitions & handlers
tests/
└── integration_tests.rs # Integration tests

Development

# Build
cargo build

# Run tests
cargo test

# Lint
cargo clippy

# Format
cargo fmt

# Build optimized release
cargo build --release

Configuration

Environment VariableDescriptionDefault
GMAIL_OAUTH_PATHPath to OAuth keys file~/.gmail-mcp/gcp-oauth.keys.json
GMAIL_CREDENTIALS_PATHPath to stored tokens~/.gmail-mcp/credentials.json
GMAIL_OAUTH_PORTOAuth callback port3000
RUST_LOGLog level (trace, debug, info, warn, error)info

License

This project is licensed under the MIT License - see the file for details.

Acknowledgments

  • Original Implementation: GongRzhe/Gmail-MCP-Server - The TypeScript implementation that inspired this Rust port
  • Model Context Protocol: modelcontextprotocol.io - The protocol specification
  • Anthropic: For creating Claude and the MCP ecosystem