Gmail MCP Server

Gmail MCP Server

Provides read-only access to Gmail, enabling email search, unread listing, message and thread retrieval, and draft reply preparation without sending.

Category
访问服务器

README

Gmail MCP Server

A Model Context Protocol (MCP) server that provides read-only access to Gmail. Allows Claude Code to safely search, read, and analyze your Gmail inbox.

Features

  • search_emails - Search using Gmail query syntax
  • list_unread - List unread emails
  • get_message - Get full message content with attachments metadata
  • get_thread - Get all messages in a conversation thread
  • draft_reply - Prepare draft reply content (does NOT send)

Prerequisites

  • Node.js 18+
  • A Google Cloud project with Gmail API enabled
  • OAuth 2.0 Desktop App credentials

Google Cloud Setup

1. Create a Google Cloud Project

  1. Go to Google Cloud Console
  2. Click "Select a project" → "New Project"
  3. Name your project (e.g., "Gmail MCP Server")
  4. Click "Create"

2. Enable Gmail API

  1. In your project, go to "APIs & Services" → "Library"
  2. Search for "Gmail API"
  3. Click on it and press "Enable"

3. Configure OAuth Consent Screen

  1. Go to "APIs & Services" → "OAuth consent screen"
  2. Select "External" (or "Internal" if using Google Workspace)
  3. Fill in the required fields:
    • App name: "Gmail MCP Server"
    • User support email: your email
    • Developer contact: your email
  4. Click "Save and Continue"
  5. Add scopes:
    • https://www.googleapis.com/auth/gmail.readonly
    • https://www.googleapis.com/auth/gmail.compose
  6. Add your email as a test user (if External)
  7. Complete the setup

4. Create OAuth Credentials

  1. Go to "APIs & Services" → "Credentials"
  2. Click "Create Credentials" → "OAuth client ID"
  3. Select "Desktop app" as application type
  4. Name it (e.g., "Gmail MCP Desktop")
  5. Click "Create"
  6. Download or copy the Client ID and Client Secret

Installation

# Clone or navigate to the project
cd gmail-mcp

# Install dependencies
npm install

# Build the project
npm run build

Configuration

  1. Copy the example environment file:
cp .env.example .env
  1. Edit .env with your OAuth credentials:
CLIENT_ID=your-client-id.apps.googleusercontent.com
CLIENT_SECRET=your-client-secret

First Run (Authorization)

The first time you run the server, it will:

  1. Open your browser for Google authorization
  2. Ask you to sign in and grant permissions
  3. Save the tokens locally in token.json

Subsequent runs will reuse the saved tokens automatically.

Usage with Claude Code

Add the MCP Server

claude mcp add gmail node ./dist/index.js

Or add to your Claude Code configuration manually:

{
  "mcpServers": {
    "gmail": {
      "command": "node",
      "args": ["./dist/index.js"],
      "cwd": "/path/to/gmail-mcp"
    }
  }
}

Available Tools

search_emails

Search emails using Gmail query syntax.

Query examples:
- "from:user@example.com"
- "subject:meeting"
- "is:unread"
- "after:2024/01/01 before:2024/12/31"
- "has:attachment filename:pdf"
- "in:inbox -category:promotions"

list_unread

List unread emails (shortcut for is:unread search).

get_message

Get full content of a specific email by message ID.

get_thread

Get all messages in a conversation thread by thread ID.

draft_reply

Prepare a draft reply to a thread. Provides context for composing a response but does NOT send any email.

Development

# Run in development mode (with hot reload)
npm run dev

# Type check
npm run typecheck

# Build for production
npm run build

# Run production build
npm start

Security Notes

  • OAuth tokens are stored locally in token.json
  • Never commit .env or token.json to version control
  • The server only requests read and compose permissions
  • No emails are sent - draft_reply only prepares content
  • Email content is not logged

Troubleshooting

"Missing CLIENT_ID or CLIENT_SECRET"

Ensure your .env file exists and contains valid credentials.

"Authorization timeout"

The OAuth flow has a 5-minute timeout. Restart the server and complete authorization promptly.

"Token refresh failed"

Delete token.json and re-authorize.

"Access blocked: This app's request is invalid"

Ensure your OAuth consent screen is properly configured and your email is added as a test user.

推荐服务器

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

官方
精选