Gmail MCP Server

Gmail MCP Server

Enables intelligent integration with Gmail and Google Calendar for context-aware email analysis, advanced searching, and personalized response drafting. It supports natural language interactions for managing communication history, detecting events in emails, and creating calendar entries.

Category
访问服务器

README

Gmail MCP Server

smithery badge

A Model Context Protocol (MCP) server for Gmail & Google Calendar integration with Claude Desktop, enabling intelligent, context-aware interactions with your email.

🌟 Features

  • Deep Email Analysis: Provides comprehensive context from entire conversation threads
  • Context-Aware Responses: Generates responses considering full communication history
  • Intelligent Action Suggestions: Analyzes email content for calendar events, tasks, and follow-ups
  • Calendar Integration: Detects events in emails and creates calendar entries with natural language support
  • Advanced Search: Searches across entire email history with semantic understanding
  • Personalization: Adapts to your communication style with specific contacts

🚀 Getting Started

Prerequisites

  • Python 3.10+
  • A Google Cloud Platform account with Gmail API and Google Calendar API (optional) enabled
  • OAuth 2.0 credentials for the Gmail API and Google Calendar API (optional)
  • Claude Desktop with MCP support (currently only LLM interface to support MCP)

Installation

Installing via Smithery

To install Gmail Integration Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @bastienchabal/gmail-mcp --client claude

Installing Manually

  1. Clone this repository:

    git clone https://github.com/bastienchabal/gmail-mcp.git
    cd gmail-mcp
    
  2. Set up a virtual environment using uv:

    pip install uv
    uv venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies:

    uv pip install -e .
    

⚙️ Configuration

Step 1: Authenticate with Google

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable Google APIs:
  4. Configure the OAuth consent screen:
    • Select "External" user type
    • Add your email as a test user
    • Add all the scopes of Gmail and Calendar
  5. Create OAuth 2.0 credentials:
    • Choose "Desktop app" as the application type
    • Download the JSON credentials file and copy the Client ID and Client Secret

Step 2: Configure Claude Desktop

  1. Create or edit the claude_desktop_config.json file in /Users/<username>/Library/Application Support/Claude
  2. Add the following configuration, replacing the placeholders with your actual values:
{
  "mcpServers": {
    "gmail-mcp": {
      "command": "/<absolute-path>/gmail-mcp/.venv/bin/mcp",
      "args": [
        "run",
        "/<absolute-path>/gmail-mcp/gmail_mcp/main.py:mcp"
      ],
      "cwd": "/<absolute-path>/gmail-mcp",
      "env": {
        "PYTHONPATH": "/<absolute-path>/gmail-mcp",
        "CONFIG_FILE_PATH": "/<absolute-path>/gmail-mcp/config.yaml",
        "GOOGLE_CLIENT_ID": "<your-client-id>",
        "GOOGLE_CLIENT_SECRET": "<your-client-secret>",
        "TOKEN_ENCRYPTION_KEY": "<generate-a-random-key>"
      }
    }
  }
}

Notes:

  • Replace <absolute-path> with the actual path to your gmail-mcp directory
  • Replace <your-client-id> and <your-client-secret> with your Google OAuth credentials (previously generated in the json file)
  • Optional : Generate a random encryption key with: python -c "import os; from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

The configuration is designed to keep sensitive data (client ID, client secret, and encryption key) in the Claude Desktop configuration file, while non-sensitive settings are stored in the config.yaml file included in the repository.

Step 3: Use Claude Desktop

  1. Open Claude Desktop
  2. Type a prompt like: "Please retrieve my last email"
  3. Claude should automatically connect to the MCP server and ask you to authenticate to your Gmail account (creating the file tokens.json)

❓ Troubleshooting

Important Note on MCP

If Claude Desktop doesn't connect automatically (i.e. you do not see the tool icon underneath the prompt input), you can try:

  • Restarting Claude Desktop
  • Asking Claude to "Use the Gmail MCP server"
  • Login to Gmail manually using one of these methods:

Important Note on Authentication

  1. Authentication Problems:

    • Run python debug/auth_test.py to test the authentication process with detailed feedback
    • Check that the token file exists at the project root
    • Verify that your Google Cloud Console project has the correct redirect URI configured
    • Make sure all required scopes are added to your OAuth consent screen
    • If you see "Scope has changed" errors, ensure that the openid scope is included in your OAuth consent screen
    • If you see "redirect_uri_mismatch" errors, add the exact URI shown in the error message to your authorized redirect URIs in Google Cloud Console
    • If the callback page doesn't load or process properly, check if port 8000 is already in use by another application
  2. Calendar API Issues:

    • Make sure you've enabled the Calendar API in Google Cloud Console
    • Check that you've granted all the necessary scopes during authentication
    • Run python debug/reauth_calendar.py to re-authenticate with Calendar API scopes
    • Verify that CALENDAR_API_ENABLED is set to true in your environment variables

Important Note on Calendar Integration

Calendar integration can be turned off in the configuration file. If you've previously authenticated with the Gmail MCP server and are now enabling Calendar integration, you'll need to re-authenticate to grant the additional Calendar API scopes. You can do this by:

  1. Deleting the existing tokens.json file (if present, either at projet root or in ~/Users/<username/>gmail_mcp_tokens/tokens.json)
  2. Restarting the MCP server
  3. Following the authentication process again

👤 Usage

The Gmail MCP provides powerful, context-aware tools for managing your emails and calendar:

Email Management

  • Email Overview: Get a comprehensive view of your inbox with counts and recent emails
  • Advanced Search: Use Gmail's powerful search syntax to find specific emails
  • Detailed Email Analysis: View emails with full context, including thread history and sender information

Context-Aware Email Replies

  • Intelligent Reply Preparation: Analyze the full context of an email thread before replying
  • Communication Pattern Analysis: Understand your communication history with the sender
  • Personalized Drafting: Create draft replies that match your communication style with specific contacts
  • Entity Recognition: Identify important dates, times, action items, and other entities in emails
  • Related Email Context: Consider other relevant emails when crafting replies

Calendar Integration

  • Event Creation: Create calendar events with natural language time descriptions
  • Event Detection: Automatically detect potential events mentioned in emails
  • Calendar Management: View, search, and manage your upcoming calendar events
  • Smart Scheduling: Schedule meetings with appropriate context from email conversations

Example Requests

You can ask Claude to use these capabilities with natural language requests like:

  • "Show me an overview of my inbox"
  • "Find all unread emails from my boss about the quarterly report"
  • "Help me reply to the last email from Sarah about the project deadline"
  • "Create a calendar event for the team meeting mentioned in John's email"
  • "What meetings do I have scheduled for next week?"
  • "Analyze this email thread and help me understand the key points before I reply"
  • "Draft a response to this email considering my previous communications with this person"

Available Resources

The MCP provides rich contextual resources that Claude can access:

  • Email Context: Detailed information about specific emails
  • Thread Context: Full conversation history for email threads
  • Sender Context: Information about your relationship and communication history with senders
  • Authentication Status: Current authentication state with Google
  • Gmail Status: Overview of your Gmail account
  • Server Information: Details about the MCP server configuration

Available Guides

The MCP includes several guides to help you get the most out of its capabilities:

  • Quick Start Guide: Basic instructions for getting started
  • Authentication Guide: Help with the authentication process
  • Search Guide: Advanced Gmail search syntax reference
  • Reply Guide: Best practices for context-aware email replies
  • Debug Guide: Troubleshooting common issues

☑️ This MCP is configured so Claude will always ask you for confirmation before doing any important action, such as sending an email or creating a meeting.

⚠ Beta Notice

This MCP is a WIP and is currently in beta.

📝 License

This project is licensed under the MIT License.

💡 Acknowledgements

  • This project uses the Model Context Protocol (MCP) developed by Anthropic
  • Gmail API access is provided by Google's API services

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选