Gmail MCP Server

Gmail MCP Server

A Model Context Protocol server that enables Claude AI to interact with Gmail, supporting email sending, reading, searching, labeling, draft management, and batch operations through natural language commands.

Category
访问服务器

README

Gmail MCP Server

<div align="center">

A powerful Model Context Protocol (MCP) server that enables Claude AI to directly interact with Gmail.

Gmail MCP MIT License Python Version </div>

📖 Table of Contents

📋 Overview

The Gmail MCP Server is a comprehensive implementation that enables AI assistants like Claude to directly interact with Gmail through natural language. It exposes a rich set of tools for email management, enabling seamless integration between conversational AI and your inbox.

💡 Key Features

  • Complete Email Management

    • Send plain text and HTML emails with attachments
    • Read emails with proper parsing of complex message structures
    • Search your inbox with Gmail's powerful query syntax
    • Create and update draft emails
    • Manage labels, read/unread status, and trash
    • Perform batch operations on multiple emails
  • Advanced Integration

    • Modern Python codebase with async/await pattern
    • Comprehensive error handling and recovery
    • Detailed progress reporting
    • Secure OAuth authentication flow
    • Multiple transport modes (STDIO and SSE)
    • Support for different deployment scenarios

🚀 Quick Start

Prerequisites

  • Python 3.8 or higher
  • A Google Cloud project with the Gmail API enabled
  • OAuth 2.0 credentials for the Gmail API

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/gmail-mcp-server.git
    cd gmail-mcp-server
    
  2. Set up a virtual environment

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
    
  3. Install dependencies

    pip install -r requirements.txt
    
  4. Set up Google Cloud and OAuth credentials

    Visit the Google Cloud Console to:

    • Create a new project
    • Enable the Gmail API
    • Set up OAuth consent screen
    • Create OAuth Client ID credentials (Desktop application)
    • Download credentials as credentials.json in project root

First Run and Authentication

Run the server once to authenticate:

python gmail_server.py

This will open a browser window asking you to authenticate with your Google account. After authentication, a token.json file will be created and saved for future use.

Configure Claude Desktop

  1. Edit your Claude Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  2. Add the Gmail MCP server to the configuration:

    {
      "mcpServers": {
        "gmail": {
          "command": "python",
          "args": [
            "/absolute/path/to/gmail-mcp-server/gmail_server.py"
          ]
        }
      }
    }
    
  3. Save the file and restart Claude Desktop

Note: Replace "/absolute/path/to/gmail-mcp-server/gmail_server.py" with the actual absolute path to the gmail_server.py file in your cloned repository.

🧰 Available Tools

The Gmail MCP Server exposes the following tools to Claude:

Email Sending

  • send_email - Send basic emails with text/HTML content
  • send_email_with_attachment - Send emails with file attachments
  • send_email_with_multiple_attachments - Send emails with multiple attachments

Email Reading

  • read_email - Read the content of a specific email by ID
  • get_unread_emails - Get a list of unread emails
  • get_important_emails - Get emails marked as important
  • get_emails_with_attachments - Get emails that have attachments
  • get_recent_emails - Get emails from the last X days

Email Search and Organization

  • search_emails - Search emails using Gmail's query syntax
  • get_email_labels - List all Gmail labels/folders
  • create_email_label - Create a new label
  • delete_email_label - Delete an existing label
  • label_email - Apply a label to an email
  • remove_email_label - Remove a label from an email

Email Status Management

  • mark_as_read - Mark an email as read
  • mark_as_unread - Mark an email as unread
  • delete_email - Move an email to trash

Draft Management

  • create_email_draft - Create a new draft email
  • update_email_draft - Update an existing draft
  • list_email_drafts - List available drafts
  • send_draft - Send an existing draft

Batch Operations

  • batch_apply_label - Apply a label to multiple emails
  • batch_delete_emails - Move multiple emails to trash

Account Information

  • get_email_profile - Get Gmail profile information
  • summarize_recent_emails - Create a summary of recent emails

💬 Usage Examples

Here are some example prompts for Claude:

Send an email to john@example.com with the subject "Project Update" and let them know we're still on track for the deadline next week.
Search my inbox for any emails from Bank of America in the last month and summarize them for me.
Find all unread emails from my boss and create a summary of any action items mentioned in them.
Draft an email to the team about the upcoming meeting on Thursday at 2pm. Remind everyone to prepare their weekly updates.

🔧 Advanced Configuration

Environment Variables

The server supports multiple environment variables for customization:

Variable Description
GMAIL_TOKEN_PATH Custom path to store OAuth token
GMAIL_CREDENTIALS_PATH Custom path to OAuth credentials
GOOGLE_CLIENT_ID OAuth client ID (alternative to credentials file)
GOOGLE_CLIENT_SECRET OAuth client secret (alternative to credentials file)
MCP_PORT Port for SSE transport (default: 3000)
DEBUG Enable debug mode (true or false)

SSE Server Mode

The server can be run in SSE (Server-Sent Events) mode for HTTP-based integration:

python gmail_server.py --sse [port]

This starts the server on the specified port (default: 3000), making it accessible via HTTP.

📚 Documentation

🔒 Security Considerations

  • The server uses OAuth 2.0 for secure Gmail API authentication
  • All actions run locally on your machine - emails never pass through third-party servers
  • Authentication tokens are stored locally and can be revoked at any time
  • The server requires local file access only for reading attachments
  • Claude always asks for confirmation before sending or deleting emails

🤝 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 MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Google for the Gmail API
  • Anthropic for Claude and the Model Context Protocol
  • Contributors to the Python Gmail API client libraries

<div align="center"> Made with ❤️ for the MCP and Claude community </div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选