Gmail MCP Server

Gmail MCP Server

Connects to Gmail accounts to search emails, retrieve full email content, and parse receipts from services like Swiggy, Zomato, and Uber with read-only access.

Category
访问服务器

README

Gmail MCP Server

A Model Context Protocol (MCP) server that connects to your Gmail account to retrieve and parse email receipts from various services like Swiggy, Zomato, Uber, and more. This provides a robust alternative to using private APIs.

Features

  • Email Search: Search emails using Gmail query syntax with flexible filters (sender, date range, subject, etc.)
  • Full Email Content: Retrieve complete email content including body and metadata
  • Receipt Parsing: Specialized parsers for:
    • Swiggy orders (with detailed item breakdown, prices, dates)
    • Future support planned for Zomato, Uber, Blinkit, and more

Prerequisites

  • Python 3.8 or higher
  • A Google Cloud account
  • Gmail API enabled on your Google Cloud project

Setup Guide

Step 1: Google Cloud Console Setup

  1. Create a Google Cloud Project

  2. Enable the Gmail API

    • Navigate to "APIs & Services" > "Library"
    • Search for "Gmail API" and click "Enable"
  3. Configure OAuth Consent Screen

    • Go to "APIs & Services" > "OAuth consent screen"
    • Choose "External" user type (or "Internal" if you have Google Workspace)
    • Fill in required fields:
      • App name: e.g., "Gmail MCP Server"
      • User support email: your email
      • Developer contact information: your email
    • Click "Save and Continue"
    • Add the scope: https://www.googleapis.com/auth/gmail.readonly
    • Add your email address as a Test User (critical for external apps)
  4. Create OAuth 2.0 Credentials

    • Go to "APIs & Services" > "Credentials"
    • Click "Create Credentials" > "OAuth client ID"
    • Application type: Desktop app
    • Name: "Gmail MCP Client"
    • Click "Create"
    • Download the JSON file and save it as credentials.json in the gmail-mcp-server directory

Step 2: Local Installation

  1. Clone or download this repository

  2. Navigate to the project directory

    cd gmail-mcp-server
    
  3. Create a virtual environment

    python -m venv venv
    
  4. Activate the virtual environment

    • Windows:
      venv\Scripts\activate
      
    • Mac/Linux:
      source venv/bin/activate
      
  5. Install dependencies

    pip install -r requirements.txt
    
  6. Copy your credentials file

    • Ensure credentials.json (downloaded from Google Cloud Console) is in the root of the gmail-mcp-server directory
    • You can use credentials.json.example as a reference for the expected structure

Step 3: First Run & Authentication

  1. Run the server for the first time

    python src/server.py
    
  2. Authenticate with Google

    • A browser window will automatically open
    • Sign in to your Google account
    • Grant the requested permissions (read-only Gmail access)
    • After successful authentication, a token.json file will be created
    • This token will be used for future runs (no need to re-authenticate)
  3. Verify the server is running

    • You should see log output indicating the MCP server is ready

Configuration for MCP Clients

VS Code Configuration

Add this to your VS Code settings.json or MCP configuration file:

{
  "mcpServers": {
    "gmail": {
      "command": "python",
      "args": [
        "path/to/gmail-mcp-server/src/server.py"
      ],
      "cwd": "path/to/gmail-mcp-server",
      "env": {}
    }
  }
}

Important: Replace path/to/gmail-mcp-server with the absolute path to your installation directory.

Claude Desktop Configuration

Add this to your Claude Desktop MCP configuration file (claude_desktop_config.json):

{
  "mcpServers": {
    "gmail": {
      "command": "python",
      "args": [
        "path/to/gmail-mcp-server/src/server.py"
      ],
      "cwd": "path/to/gmail-mcp-server"
    }
  }
}

Note: Ensure the Python executable is from your virtual environment, or activate the virtual environment before launching the MCP client.

Available Tools

1. search_emails

Search for emails with flexible filters.

Parameters:

  • query (optional): General Gmail search query
  • sender (optional): Filter by sender (e.g., "swiggy", "uber")
  • recipient (optional): Filter by recipient
  • subject (optional): Filter by subject line
  • start_date (optional): Start date in common formats (e.g., "2024-01-01", "last week")
  • end_date (optional): End date (exclusive)
  • max_results (optional): Maximum number of emails to return (default: 10)

Returns: List of emails with ID, subject, sender, date, and snippet

2. get_email_content

Retrieve full content of a specific email.

Parameters:

  • email_id (required): Gmail message ID from search results

Returns: Complete email content including body, headers, and metadata

3. get_swiggy_orders

Fetch and parse Swiggy order receipts.

Parameters:

  • start_date (optional): Filter orders after this date (inclusive)
  • end_date (optional): Filter orders before this date (exclusive)
  • limit (optional): Maximum number of orders to return

Returns: Parsed order data with items, prices, dates, and order details

Security & Privacy

  • Credentials: Your credentials.json and token.json files contain sensitive authentication data and are excluded from version control via .gitignore
  • Read-Only Access: This server only requests read-only Gmail permissions
  • Local Processing: All email parsing happens locally on your machine
  • No Data Storage: Email data is not stored persistently by this server

Troubleshooting

"credentials.json not found"

  • Ensure you've downloaded the OAuth client credentials from Google Cloud Console
  • Place the file in the root directory of this project
  • Rename it to exactly credentials.json

Authentication issues

  • Delete token.json and re-run the server to re-authenticate
  • Ensure your email is added as a Test User in the OAuth consent screen
  • Check that the Gmail API is enabled in your Google Cloud project

Import errors

  • Ensure your virtual environment is activated
  • Reinstall dependencies: pip install -r requirements.txt

Server not connecting to VS Code/Claude

  • Verify the absolute path in your MCP configuration
  • Ensure Python is accessible from the command line
  • Check that the cwd points to the correct directory
  • Review logs for any startup errors

Development

To modify or extend this server:

  1. The main server logic is in src/server.py
  2. Authentication handling is in src/auth.py
  3. Add new receipt parsers by following the Swiggy parser pattern
  4. Submit pull requests for new features or bug fixes

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests for:

  • New receipt parsers (Zomato, Uber, Blinkit, etc.)
  • Bug fixes
  • Documentation improvements
  • Feature enhancements

推荐服务器

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

官方
精选