Gmail邮件管理MCP服务

一个通过MCP协议提供Gmail操作的服务,支持标签列表、邮件搜索与读取、草稿编写与发送、标签管理及邮件删除等功能。

  • by henrysouchien
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 henrysouchien/gmail-mcp

使用说明

gmail-mcp

MCP server for Gmail operations.

Tools

Tool Description
gmail_list_labels List system and user Gmail labels
gmail_list_inbox List messages from a label (optionally unread only)
gmail_search_emails Search emails with Gmail query syntax
gmail_read_email Read a full email by message ID
gmail_create_draft Compose a new email draft
gmail_create_reply_draft Compose a reply draft for a message/thread
gmail_send_draft Send an existing draft after review with its confirmation token
gmail_manage_labels Add or remove labels on a message
gmail_manage_labels_bulk Add or remove labels on multiple messages
gmail_delete_email Move message to trash or permanently delete

Setup

Prerequisites

  • Python 3.10+
  • Gmail account with API access
  • OAuth desktop client credentials from Google Cloud Console

Installation

git clone https://github.com/<your-user>/gmail-mcp.git
cd gmail-mcp
"$(uv python find --system --managed-python 3.13.15)" -m venv --copies venv
venv/bin/python -m pip install -e .

Authentication

  1. Save OAuth credentials outside the repository at ~/.config/gmail-mcp/gmail_credentials.json and restrict the file to your user:
mkdir -p ~/.config/gmail-mcp
chmod 700 ~/.config/gmail-mcp
chmod 600 ~/.config/gmail-mcp/gmail_credentials.json
  1. Run initial authentication once:
venv/bin/python -c "from src import gmail_client; gmail_client.authenticate()"
  1. Complete browser consent. The token cache is written to ~/.config/gmail-mcp/gmail_token.pickle with mode 0600.

Set GMAIL_CONFIG_DIR to relocate both defaults, or use GMAIL_CREDENTIALS_FILE and GMAIL_TOKEN_FILE for per-process overrides.

Claude Code Configuration

Add to ~/.claude.json:

{
  "mcpServers": {
    "gmail-mcp": {
      "type": "stdio",
      "command": "/path/to/gmail-mcp/venv/bin/python",
      "args": ["/path/to/gmail-mcp/run_server.py"]
    }
  }
}

Development

venv/bin/python -c "from src.server import mcp; print([t.name for t in mcp._tool_manager._tools.values()])"
venv/bin/python run_server.py

License

MIT