Sponsored by Deepsite.site

Enhanced Gmail MCP Server

Created By
theposch9 months ago
A Gmail MCP server
Content

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

# 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:
    • Select "External" user type
    • Add your email as a test user
    • Add the scope: https://www.googleapis.com/auth/gmail/modify
  4. Create OAuth 2.0 credentials:
    • Choose "Desktop app" as the application type
    • Download the JSON credentials file

Configuration

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

# 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):

{
  "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:

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
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
WindsurfThe new purpose-built IDE to harness magic
CursorThe AI Code Editor
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Playwright McpPlaywright MCP server
Amap Maps高德地图官方 MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
ChatWiseThe second fastest AI chatbot™
Serper MCP ServerA Serper MCP Server
DeepChatYour AI Partner on Desktop
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.