trackmcp
Back to directory

A Gmail MCP server

13 stars PythonAI & Machine Learning Updated Nov 1, 2025

Documentation

Enhanced Gmail MCP Server

A powerful and feature-rich Model Context Protocol (MCP) server for Gmail integration, written in Python. This server enables AI assistants like Claude to interact with Gmail through natural language, providing comprehensive email management capabilities.

๐ŸŒŸ Key Features

๐Ÿ“ง Complete Email Management

  • Send emails with customizable subject, content, and recipients
  • Read and retrieve email content with full metadata
  • Move emails to trash with confirmation
  • Mark emails as read/unread
  • Open emails directly in browser

๐Ÿ“ Draft Management

  • Create draft emails for later review
  • List all draft emails
  • Edit existing drafts

๐Ÿท๏ธ Advanced Label Management

  • List all available labels
  • Create custom labels
  • Apply/remove labels from emails
  • Rename existing labels
  • Delete unused labels
  • Search emails by label

๐Ÿ“ Folder Organization

  • Create new folders (implemented as Gmail labels)
  • Move emails between folders
  • List all available folders

๐Ÿ” Powerful Search & Filtering

  • Search emails using Gmail's advanced query syntax
  • Create, manage, and delete email filters
  • Filter by sender, recipient, subject, content, and more
  • Customize search results with flexible parameters

๐Ÿ—„๏ธ Archive Management

  • Archive emails (remove from inbox without deleting)
  • Batch archive multiple emails matching search criteria
  • List all archived emails
  • Restore archived emails to inbox

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.8+
  • Google Cloud project with Gmail API enabled
  • OAuth 2.0 credentials

Installation

bash
# Clone the repository
git clone https://github.com/theposch/gmail-mcp.git
cd gmail-mcp

# Set up a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install the package
pip install -e .

Google Cloud Setup

1. Create a new Google Cloud project

2. Enable the Gmail API

3. Configure the OAuth consent screen:

    4. Create OAuth 2.0 credentials:

      Configuration

      Store your credentials securely and specify their location when running the server:

      bash
      # Example directory structure for credentials
      mkdir -p ~/.gmail-mcp
      # Move your downloaded credentials file
      mv ~/Downloads/client_secret_*.json ~/.gmail-mcp/credentials.json

      ๐Ÿ”ง Usage

      Running with Claude Desktop

      Add the following to your Claude Desktop configuration file (typically at `~/Library/Application Support/Claude/claude_desktop_config.json`):

      json
      {
        "mcpServers": {
          "gmail": {
            "command": "uv",
            "args": [
              "--directory",
              "/absolute/path/to/gmail-mcp",
              "run",
              "gmail",
              "--creds-file-path",
              "/absolute/path/to/credentials.json",
              "--token-path",
              "/absolute/path/to/tokens.json"
            ]
          }
        }
      }

      Testing with MCP Inspector

      For testing and debugging, use the MCP Inspector:

      bash
      npx @modelcontextprotocol/inspector uv run /path/to/gmail-mcp/src/gmail/server.py --creds-file-path /path/to/credentials.json --token-path /path/to/tokens.json

      ๐Ÿ” Security Considerations

      • Never commit credentials or token files to version control
      • Store credentials in a secure location with appropriate permissions
      • The server will request user confirmation before performing sensitive actions
      • Review Google Cloud Console regularly for unusual activity
      • Consider using environment variables for sensitive paths

      ๐Ÿ› ๏ธ Architecture

      This implementation features a comprehensive single-file architecture that handles all Gmail operations through the Google API client libraries. Key components include:

      • OAuth2 authentication with automatic token refresh
      • Comprehensive error handling and logging
      • Structured tool definitions with clear input schemas
      • Efficient email parsing and formatting

      ๐Ÿ“š Example Prompts

      Try these prompts with Claude after connecting the Gmail MCP server:

      • "Show me my unread emails"
      • "Search for emails from example@domain.com with attachments"
      • "Create a new label called 'Important Projects'"
      • "Draft an email to john@example.com about the upcoming meeting"
      • "Archive all emails from newsletter@example.com"
      • "Create a filter to automatically label emails from my team"

      ๐Ÿค Contributing

      Contributions are welcome! Please feel free to submit a Pull Request.

      1. Fork the repository

      2. Create your feature branch (`git checkout -b feature/amazing-feature`)

      3. Commit your changes (`git commit -m 'Add some amazing feature'`)

      4. Push to the branch (`git push origin feature/amazing-feature`)

      5. Open a Pull Request

      ๐Ÿ“„ License

      This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

      ๐Ÿ™ Acknowledgments

      • Inspired by various MCP server implementations in the community
      • Built with the Model Context Protocol framework
      • Uses Google's official API client libraries

      Frequently asked questions

      What is gmail-mcp?

      gmail-mcp is A Gmail MCP server

      How do I install gmail-mcp?

      Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

      Is gmail-mcp open source?

      Yes โ€” it is hosted on GitHub at https://github.com/theposch/gmail-mcp and has 13 stars.

      Related MCP tools

      All-Hands-AIopenhands

      ๐Ÿ™Œ OpenHands: Code Less, Make More for the Model Context Protocol. Enhance AI assistants with powerful integrations. Python-based implementation.

      64,677 Python
      agentartificial-intelligencechatgpt+6
      mem0aimem0

      Universal memory layer for AI Agents; Announcing OpenMemory MCP - local and secure memory management. Python-based implementation.

      42,646 Python
      agentsaiai-agents+12
      zhayujiechatgpt-on-wechat

      ๅŸบไบŽๅคงๆจกๅž‹ๆญๅปบ็š„่Šๅคฉๆœบๅ™จไบบ๏ผŒๅŒๆ—ถๆ”ฏๆŒ ๅพฎไฟกๅ…ฌไผ—ๅทใ€ไผไธšๅพฎไฟกๅบ”็”จใ€้ฃžไนฆใ€้’‰้’‰ ็ญ‰ๆŽฅๅ…ฅ๏ผŒๅฏ้€‰ๆ‹ฉChatGPT/Claude/DeepSeek/ๆ–‡ๅฟƒไธ€่จ€/่ฎฏ้ฃžๆ˜Ÿ็ซ/้€šไน‰ๅƒ้—ฎ/ Gemini/GLM-4/Kimi/LinkAI๏ผŒ่ƒฝๅค„็†ๆ–‡ๆœฌใ€่ฏญ้Ÿณๅ’Œๅ›พ็‰‡๏ผŒ่ฎฟ้—ฎๆ“ไฝœ็ณป็ปŸๅ’Œไบ’่”็ฝ‘๏ผŒๆ”ฏๆŒๅŸบไบŽ่‡ชๆœ‰็Ÿฅ่ฏ†ๅบ“่ฟ›่กŒๅฎšๅˆถไผไธšๆ™บ่ƒฝๅฎขๆœใ€‚

      39,573 Python
      aiai-agentchatgpt+17
      assafelovicgpt-researcher

      An LLM agent that conducts deep research (local and web) on any given topic and generates a long report with citations. Built for the Model Context Protocol to

      24,026 Python
      agentaiautomation+8
      jlowinfastmcp

      ๐Ÿš€ The fast, Pythonic way to build MCP servers and clients Trusted by 19900+ developers. Trusted by 19900+ developers. Trusted by 19900+ developers.

      19,927 Python
      agentsfastmcpllms+6
      1Panel-devmaxkb

      ๐Ÿ”ฅ MaxKB is an open-source platform for building enterprise-grade agents. MaxKB ๆ˜ฏๅผบๅคงๆ˜“็”จ็š„ๅผ€ๆบไผไธš็บงๆ™บ่ƒฝไฝ“ๅนณๅฐใ€‚ for the Model Context Protocol. Enhance AI assistants with po

      19,062 Python
      agentagentic-aichatbot+11

      Run your own MCP server? See who uses it and what to fix.

      Measure it with TrackMCP