Gmail MCP Server

Gmail MCP Server

A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Gmail through secure OAuth 2.0 authentication. Send emails, search messages, read emails, and manage multiple Gmail accounts directly from Claude Desktop.

Category
访问服务器

README

Gmail MCP Server

A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Gmail through secure OAuth 2.0 authentication. Send emails, search messages, read emails, and manage multiple Gmail accounts directly from Claude Desktop.

Features

  • Secure OAuth 2.0 Authentication - No passwords stored, tokens auto-refresh
  • Multiple Account Support - Manage multiple Gmail accounts simultaneously
  • Email Operations - Send, search, and read emails with full Gmail API support
  • Advanced Search - Use Gmail's powerful search operators
  • Real-time Integration - Works seamlessly with Claude Desktop

Quick Start

  1. Setup Google Cloud Console:

    • Create a project and enable Gmail API
    • Create OAuth 2.0 credentials for desktop application
    • Download credentials as credentials.json
  2. Install and Build:

    npm install
    npm run build
    
  3. Configure Claude Desktop:

    • Place credentials.json in Claude Desktop's directory
    • Update claude_desktop_config.json with server path
    • Restart Claude Desktop
  4. Start Using:

    Send an email to john@example.com with subject "Hello" and body "Testing Gmail MCP"
    

Architecture

Built with TypeScript and follows MCP specifications:

  • Entry Point: src/index.ts - Main MCP server setup and tool definitions
  • Gmail Client: src/gmail-client.ts - Gmail API wrapper with OAuth authentication
  • Authentication: src/auth.ts - OAuth 2.0 credential management
  • Types: src/types.ts - TypeScript interfaces and type definitions

Development

# Development mode with hot reload
npm run dev

# Test with MCP Inspector
npm run inspect

# Build for production
npm run build

Security

  • Uses minimal required Gmail scopes (read and send only)
  • Tokens stored locally with automatic refresh
  • No email content stored permanently
  • All operations performed locally

Complete User Guide

Overview

This Gmail MCP Server allows Claude Desktop to interact with your Gmail account through secure OAuth 2.0 authentication. You can send emails, search messages, read emails, and manage multiple Gmail accounts.

Prerequisites

  • Node.js (version 18 or higher)
  • Claude Desktop application installed
  • Gmail account with API access enabled
  • Google Cloud Console project with Gmail API enabled

Setup Instructions

1. Google Cloud Console Setup

  1. Create a Google Cloud Project:

  2. Enable Gmail API:

    • Navigate to "APIs & Services" → "Library"
    • Search for "Gmail API" and enable it
  3. Create OAuth 2.0 Credentials:

    • Go to "APIs & Services" → "Credentials"
    • Click "Create Credentials" → "OAuth 2.0 Client IDs"
    • Choose "Desktop application"
    • Download the credentials JSON file
    • Important: This file will need to be placed in Claude Desktop's directory later
  4. Configure OAuth Consent Screen:

    • Go to "APIs & Services" → "OAuth consent screen"
    • Add your email as a test user
    • Set scopes: https://www.googleapis.com/auth/gmail.readonly, https://www.googleapis.com/auth/gmail.send

2. Project Setup

  1. Clone and Install:

    git clone <repository-url>
    cd gmail-mcp
    npm install
    
  2. Add Google Credentials:

    • Rename your downloaded credentials file to credentials.json
    • Place it in Claude Desktop's working directory (not the project directory)
    • Location varies by OS:
      • macOS: ~/Library/Application Support/Claude/
      • Windows: %APPDATA%\Claude\
      • Linux: ~/.config/claude/
    • Important: Never commit this file to version control
  3. Build the Project:

    npm run build
    
  4. Test the Setup:

    npm run inspect
    

    This opens the MCP Inspector for testing tools before connecting to Claude Desktop.

3. Claude Desktop Integration

  1. Locate Claude Desktop Config:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/claude/claude_desktop_config.json
  2. Update Configuration:

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

    Replace /absolute/path/to/your/gmail-mcp/ with the actual path to your project.

  3. Restart Claude Desktop:

    • Close and reopen Claude Desktop
    • The Gmail MCP server should now be available

First-Time Authentication

When you first use Gmail tools through Claude Desktop:

  1. Browser Authentication:

    • A browser window will open automatically
    • Sign in with your Gmail account
    • Grant the requested permissions
  2. Token Storage:

    • Authentication tokens are stored in the accounts/ directory within Claude Desktop's directory
    • These tokens auto-refresh and are valid for 6 months of inactivity

Available Tools

Email Operations

Send Email:

Send an email to john@example.com with subject "Meeting Tomorrow" and body "Don't forget our meeting at 2 PM"

Search Emails:

Search for emails from support@company.com in the last week

Read Email:

Read the email with message ID [message-id]

Account Management

List Accounts:

Show me all configured Gmail accounts

Add Account:

Add Gmail account jane@example.com

Remove Account:

Remove Gmail account old@example.com

Set Default Account:

Set primary@example.com as the default account

Usage Examples

Basic Email Operations

  1. Send a simple email:

    Send an email to team@company.com with subject "Project Update" and tell them the project is on track
    
  2. Search for recent emails:

    Find all emails from my manager in the last 3 days
    
  3. Read a specific email:

    Read the latest email from notifications@github.com
    

Multi-Account Usage

  1. Send from specific account:

    Send an email from work@company.com to client@example.com about the project status
    
  2. Search in specific account:

    Search for invoices in my personal@gmail.com account
    

Advanced Gmail Search

Gmail search queries support operators like:

  • from:sender@example.com
  • subject:meeting
  • has:attachment
  • newer_than:7d
  • is:unread

Example:

Search for unread emails with attachments from the last week

Security & Privacy

Authentication Security

  • Uses OAuth 2.0 with minimal required scopes
  • Tokens stored locally in encrypted format
  • No passwords stored anywhere
  • Automatic token refresh

Data Privacy

  • No email content is stored permanently
  • All operations are performed locally
  • No data sent to third parties
  • Audit logs available in Claude Desktop

Best Practices

  • Set restrictive file permissions on credentials.json in Claude Desktop's directory
  • Regularly review OAuth consent screen
  • Remove unused accounts
  • Monitor token usage in Google Cloud Console
  • Keep credentials.json secure - it's stored in Claude Desktop's directory for access by the MCP server

Troubleshooting

Common Issues

"No account specified and no default account set":

  • Solution: Add an account using add_account tool or set a default account

"Authentication failed":

  • Check if credentials.json exists in Claude Desktop's directory (not the project directory)
  • Verify Gmail API is enabled in Google Cloud Console
  • Try removing and re-adding the account

"Token expired":

  • Tokens auto-refresh, but manual re-authentication may be needed
  • Remove and re-add the account if issues persist

Claude Desktop not detecting MCP server:

  • Verify the absolute path in config file
  • Check that the build directory exists
  • Restart Claude Desktop after config changes

Development and Testing

Test tools without Claude Desktop:

npm run inspect

Development mode with hot reload:

npm run dev

View server logs:

  • Check Claude Desktop logs for MCP server output
  • Use Inspector tool for detailed request/response debugging

File Structure

Project Directory:

gmail-mcp/
├── build/              # Compiled JavaScript (auto-generated)
├── src/                # TypeScript source code
├── package.json        # Project dependencies
└── CLAUDE.md          # Project instructions for Claude

Claude Desktop Directory (where credentials.json goes):

~/.config/claude/       # Linux
~/Library/Application Support/Claude/  # macOS
%APPDATA%\Claude\       # Windows
├── credentials.json    # Google OAuth credentials (you provide)
├── accounts/           # Account tokens (auto-generated when using tools)
└── claude_desktop_config.json  # Claude Desktop configuration

Limitations

  • Rate limits: Gmail API has daily quotas
  • Scope limitations: Only read and send permissions
  • Token expiry: Tokens expire after 6 months of inactivity
  • File attachments: Not currently supported for sending
  • HTML emails: Limited formatting support

Getting Help

If you encounter issues:

  1. Check the troubleshooting section above
  2. Test with the MCP Inspector (npm run inspect)
  3. Review Google Cloud Console for API quotas and errors
  4. Check Claude Desktop logs for MCP server messages

Advanced Configuration

Custom Scopes

Modify the scopes in src/auth.ts if you need additional Gmail permissions.

Multiple Projects

You can run multiple instances for different Google Cloud projects by using different configuration names in Claude Desktop.

Development

See CLAUDE.md for development guidelines and architecture details.

推荐服务器

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

官方
精选