Gmail MCP server

Provides a clean interface for accessing Gmail emails through OAuth2 authentication, automatically handling authentication flows and processing HTML content into plain text for better readability.
Back to servers
Setup instructions
Provider
Hamze Ghalebi
Release date
May 25, 2025
Language
Go
Stats
4 stars

Gmail MCP Server is a Model Context Protocol implementation that enables AI assistants and automation tools to access Gmail securely through OAuth2 authentication. Built with Rust, it provides a clean interface for fetching and processing emails while maintaining high performance and security standards.

Features

  • Secure OAuth2 Authentication - Google-standard security
  • Gmail Integration - Fetch and process emails from inbox
  • Clean Email Processing - HTML to text conversion with URL removal
  • High Performance - Built with Rust for speed and safety
  • MCP Protocol - Standard interface for AI tool integration

Installation

Prerequisites

  • Rust (1.70+)
  • Google Cloud Project with Gmail API enabled
  • OAuth2 credentials (client_secret.json)

Setup Steps

  1. Clone & Build

    git clone https://github.com/RustSandbox/gmail_MCP.git
    cd gmail_MCP
    cargo build --release
    
  2. Configure Gmail API

    • Go to Google Cloud Console
    • Enable Gmail API
    • Create OAuth2 credentials
    • Download as client_secret.json in project root
  3. Run Server

    cargo run
    

    The server will start and listen on http://localhost:3003/sse

Usage

Available Tools

The server provides a single tool:

gmail_reader - Read Gmail emails

  • Parameters:
    • action (string): Action to perform ("read")
    • max_results (number, optional): Max emails to fetch (1-500, default: 10)

Authentication Flow

  1. On first run, the server will open your browser for Google OAuth2 authentication
  2. Grant the necessary Gmail read permissions
  3. Authentication tokens will be cached for future use
  4. To re-authenticate, delete the token_cache.json file

Configuration

Required Files

  • client_secret.json - OAuth2 credentials (required)
  • token_cache.json - Generated automatically after first authentication

No environment variables are needed for basic operation.

Architecture

The Gmail MCP Server sits between an AI assistant and the Gmail API:

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   AI Assistant  │◄──►│  Gmail MCP Server │◄──►│   Gmail API     │
│   (Claude, etc) │    │   (This Project)  │    │   (Google)      │
└─────────────────┘    └──────────────────┘    └─────────────────┘

Performance

  • Handles 100+ emails per second
  • Minimal resource requirements
  • Fast startup time (<3 seconds build time)

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "gmail" '{"command":"cargo","args":["run"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "gmail": {
            "command": "cargo",
            "args": [
                "run"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "gmail": {
            "command": "cargo",
            "args": [
                "run"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later