gmail-mcp-server

gmail-mcp-server

Enables reading, sending, searching, and managing Gmail through Claude using the official Google Gmail API.

Category
访问服务器

README

gmail-mcp-server

Gmail MCP Server — read, send, search, and manage Gmail through Claude using Google's official API.

npm version License: MIT Node.js

19 tools for emails, drafts, labels, threads, and attachments — powered by the official Google Gmail API with OAuth 2.0. Works with any Google account (personal Gmail or Google Workspace).

Tools

Email Operations (5)

Tool Description
gmail_search Search emails using Gmail query syntax
gmail_get_message Get full email content by ID
gmail_send Send an email (supports CC, BCC, reply threading)
gmail_get_thread Get all messages in a thread
gmail_get_profile Get your Gmail profile info

Drafts (4)

Tool Description
gmail_create_draft Create a draft email
gmail_list_drafts List all saved drafts
gmail_send_draft Send an existing draft
gmail_delete_draft Delete a draft

Labels (3)

Tool Description
gmail_list_labels List all labels
gmail_create_label Create a new label
gmail_delete_label Delete a label

Message Management (4)

Tool Description
gmail_trash Move email to trash
gmail_untrash Restore email from trash
gmail_mark_read Mark email as read
gmail_mark_unread Mark email as unread
gmail_modify_labels Add or remove labels from an email

Attachments (2)

Tool Description
gmail_list_attachments List all attachments in an email
gmail_get_attachment Download attachment as base64

Setup

This server uses Google's official Gmail API. You need to create OAuth 2.0 credentials once in Google Cloud Console — this takes about 5 minutes.

Step 1 — Create a Google Cloud Project

  1. Go to console.cloud.google.com
  2. Click the project dropdown at the top → "New Project"
  3. Give it a name (e.g. gmail-mcp) and click Create
  4. Make sure the new project is selected

Step 2 — Enable the Gmail API

  1. In the left menu go to "APIs & Services""Library"
  2. Search for "Gmail API"
  3. Click it → click "Enable"

Step 3 — Configure OAuth Consent Screen

  1. Go to "APIs & Services""OAuth consent screen"
  2. Choose "External" (works for any Google account) → click Create
  3. Fill in:
    • App name: Gmail MCP Server (or anything)
    • User support email: your email
    • Developer contact email: your email
  4. Click Save and Continue
  5. On the Scopes page, click "Add or Remove Scopes" and add these:
    https://www.googleapis.com/auth/gmail.readonly
    https://www.googleapis.com/auth/gmail.send
    https://www.googleapis.com/auth/gmail.compose
    https://www.googleapis.com/auth/gmail.modify
    https://www.googleapis.com/auth/gmail.labels
    
  6. Click Save and Continue
  7. On Test users, click "Add Users" → add your Gmail address
  8. Click Save and ContinueBack to Dashboard

Step 4 — Create OAuth Client ID

  1. Go to "APIs & Services""Credentials"
  2. Click "+ Create Credentials""OAuth client ID"
  3. Application type: "Desktop app"
  4. Name: Gmail MCP Server
  5. Click Create
  6. Click "Download JSON" — save this file, you'll need it next

Step 5 — Install & Authenticate

# Install the package
npm install -g @dev-hitesh-gupta/gmail-mcp-server

# Install dependencies for first run
npx playwright install chromium 2>/dev/null; true

# Create config directory and place your credentials
mkdir -p ~/.gmail-mcp
cp /path/to/downloaded-credentials.json ~/.gmail-mcp/credentials.json

# Authenticate — opens a browser window for Google sign-in
gmail-mcp-server auth

Your token is saved to ~/.gmail-mcp/token.json and auto-refreshed on expiry.

Step 6 — Add to Claude Code

claude mcp add gmail -- npx @dev-hitesh-gupta/gmail-mcp-server

Or manually in your Claude config (~/.claude/claude_desktop_config.json):

{
  "mcpServers": {
    "gmail": {
      "command": "npx",
      "args": ["@dev-hitesh-gupta/gmail-mcp-server"]
    }
  }
}

Multiple Accounts

You can connect multiple Gmail accounts by running separate server instances with different config directories:

{
  "mcpServers": {
    "gmail-work": {
      "command": "npx",
      "args": ["@dev-hitesh-gupta/gmail-mcp-server"],
      "env": { "GMAIL_MCP_CONFIG_DIR": "~/.gmail-mcp-work" }
    },
    "gmail-personal": {
      "command": "npx",
      "args": ["@dev-hitesh-gupta/gmail-mcp-server"],
      "env": { "GMAIL_MCP_CONFIG_DIR": "~/.gmail-mcp-personal" }
    }
  }
}

Authenticate each separately:

GMAIL_MCP_CONFIG_DIR=~/.gmail-mcp-work gmail-mcp-server auth
GMAIL_MCP_CONFIG_DIR=~/.gmail-mcp-personal gmail-mcp-server auth

Gmail Search Syntax

The gmail_search tool supports the full Gmail query language:

from:boss@company.com           # From specific sender
to:me                           # Sent to you
subject:invoice                 # Subject contains word
is:unread                       # Unread emails
is:starred                      # Starred emails
has:attachment                  # Has attachments
after:2024/01/01                # After date
before:2024/12/31               # Before date
label:work                      # Has label
in:inbox                        # In inbox
in:sent                         # In sent
in:spam                         # In spam

Combine queries:

from:client@company.com is:unread has:attachment
subject:urgent OR subject:important
from:boss@company.com after:2024/06/01

Configuration

Environment Variable Default Description
GMAIL_MCP_CONFIG_DIR ~/.gmail-mcp Directory for credentials and token

Data & Auth Storage

All data is stored locally:

~/.gmail-mcp/
├── credentials.json    # Your Google OAuth client credentials
└── token.json          # Access + refresh token (auto-managed)

Security: Never commit credentials.json or token.json to version control. Add ~/.gmail-mcp/ to your .gitignore.


Troubleshooting

"Not authenticated" / "Credentials not found":

# Make sure credentials.json is in place
ls ~/.gmail-mcp/credentials.json

# Re-authenticate
gmail-mcp-server auth

Token expired:

rm ~/.gmail-mcp/token.json
gmail-mcp-server auth

"Access blocked" during Google sign-in: Your OAuth app is in test mode. Go to Google Cloud Console → OAuth consent screen → add your email under Test users.

Scope errors: Ensure all 5 Gmail scopes are added in the OAuth consent screen (Step 3 above).


Requirements

  • Node.js 18+
  • A Google account (personal Gmail or Google Workspace)
  • Google Cloud project with Gmail API enabled (see setup above)

License

MIT — Hitesh Gupta

推荐服务器

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

官方
精选