Gmail MCP Server

Gmail MCP Server

Enables AI assistants to read unread Gmail messages and create properly threaded draft replies through the Gmail API, allowing natural language email management while keeping drafts for manual review before sending.

Category
Visit Server

README

Gmail MCP Server

An MCP (Model Context Protocol) server that lets an AI assistant:

  • Read your unread Gmail messages via the Gmail API
  • Create properly threaded draft replies in Gmail

Built for the Anthropic programme foundation project as an end-to-end example.


Features

get_unread_emails(maxResults: int = 10)

Fetches unread emails from your inbox and returns a JSON structure:

{
  "emails": [
    {
      "id": "string",
      "threadId": "string",
      "from": "string",
      "subject": "string",
      "snippet": "string",
      "internalDate": "string"
    }
  ]
}

Fields:

  • id – Gmail message ID
  • threadId – Gmail thread ID (used when replying)
  • from – sender
  • subject – email subject
  • snippet – short preview of the message
  • internalDate – message timestamp (ms since epoch, as string)

create_draft_reply(threadId: str, replyBody: str)

Creates a draft reply in the specified Gmail thread.

Returns a JSON structure:

{
  "draftId": "string | null",
  "threadId": "string",
  "to": "string",
  "subject": "string"
}
  • Correctly threads the reply using In-Reply-To and References headers.
  • Leaves the draft in your Gmail Drafts folder for manual review / sending.

OAuth tokens are stored locally in token.json and refreshed automatically.


Architecture / Tech Stack

  • Language: Python 3
  • MCP server: mcp Python SDK (FastMCP)
  • Gmail API client: google-api-python-client, google-auth-oauthlib
  • Client: Claude Desktop using MCP over stdio

Prerequisites

  • Python 3.10+ installed
  • Claude Desktop installed
  • A Google account with access to Gmail
  • A Google Cloud project with the Gmail API enabled

Setup

  1. Clone the repository and create a virtual environment

    git clone <your-repo-url> gmail-mcp-server
    cd gmail-mcp-server
    
    python3 -m venv .venv
    source .venv/bin/activate  # Windows: .venv\Scripts\Activate.ps1
    
    pip install -r requirements.txt
    
  2. Create a Google Cloud project & enable Gmail API

    • Go to the Google Cloud Console.
    • Create (or select) a project.
    • Enable Gmail API for that project.
    • Configure the OAuth consent screen (External / Testing is fine for personal use).
  3. Create OAuth credentials

    • In APIs & Services → Credentials, create an OAuth client ID.
    • Application type: Desktop app.
    • Download the JSON file and save it in the project root as:
    credentials.json
    
  4. First-time Gmail authentication (optional sanity check)

    The project includes a small script to verify Gmail is configured correctly:

    source .venv/bin/activate
    python debug_gmail.py
    

    This will:

    • Open a browser window asking you to sign in and approve Gmail scopes.
    • Save a local token.json file for future runs.
    • Print the IDs of your unread messages.
  5. Ignore local secrets and environment-specific files

    Make sure your .gitignore (in this repo) includes at least:

    .venv/
    __pycache__/
    credentials.json
    token.json
    *.log
    

    These files must never be committed to GitHub.


Claude Desktop Configuration

Claude Desktop uses claude_desktop_config.json to know how to launch MCP servers.

On macOS this file is usually at:

~/Library/Application Support/Claude/claude_desktop_config.json

Add (or merge) the following configuration:

{
  "mcpServers": {
    "gmail-mcp-server": {
      "command": "/Users/<you>/Code/gmail-mcp-server/.venv/bin/python",
      "args": [
        "/Users/<you>/Code/gmail-mcp-server/server.py"
      ],
      "env": {
        "GMAIL_CREDENTIALS_PATH": "/Users/<you>/Code/gmail-mcp-server/credentials.json"
      }
    }
  }
}

Replace /Users/<you>/Code/gmail-mcp-server with the actual path to this project on your machine.

After editing the file, quit and restart Claude Desktop so it picks up the new MCP server.


Usage in Claude

Once Claude Desktop is restarted, open a new chat and try:

List and summarise unread emails

“Use the gmail-mcp-server tools to call get_unread_emails with maxResults 5, then summarise the emails.”

Claude will:

  • Call the get_unread_emails tool.
  • Receive the JSON list of unread emails.
  • Summarise them in natural language.

Inspect raw JSON (for debugging / demo)

“Call get_unread_emails with maxResults 3 and show me the raw JSON output.”

Create a draft reply

  1. First fetch unread emails and inspect the JSON to find a threadId.
  2. Then:

“Use the gmail-mcp-server tools to call create_draft_reply with this threadId: <PASTE_THREAD_ID> and a reply body that politely confirms I received their email and proposes a call next week. Tell me what draftId was created.”

  1. Open Gmail → Drafts to see the newly created reply in the correct thread.

Screenshots (for project submission)

Suggested screenshots to include in your submission / repo:

  • Claude calling get_unread_emails and showing the JSON result.
  • Claude summarising the unread emails.
  • Claude calling create_draft_reply and reporting the created draftId.
  • Gmail UI showing the draft reply in the correct thread.

Place them in a screenshots/ folder and reference them in your application as needed.


Security Notes

  • This server is intended for local, personal use as a learning/demo project.
  • credentials.json and token.json are sensitive and must remain local.
  • Scopes are limited to:
    • gmail.readonly – reading messages
    • gmail.compose – creating drafts
  • The server does not send credentials or email content to any third-party service other than Gmail and the local Claude Desktop client.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured