# Gmail-MCP-Server

> MCP Server

This repository provides an MCP server for Gmail integration with Claude Desktop, enabling AI assistants to manage Gmail through natural language. It supports email sending, reading, searching, and label management

## Overview

- **Category:** Communication
- **Language:** JavaScript
- **Stars:** 1165
- **Forks:** 22
- **Owner:** GongRzhe
- **GitHub:** https://github.com/GongRzhe/Gmail-MCP-Server
- **Created:** 2024-12-26T02:58:42+00:00
- **Updated:** 2025-03-28T21:31:41+00:00
- **Source:** https://model-context-protocol.com/servers/gmail-mcp-server-ai-email-management

## Setup

## Setup

**Installing via Smithery:**

```bash
npx -y @smithery/cli install @gongrzhe/server-gmail-autoauth-mcp --client claude
```

**Installing Manually:**

1.  Create a Google Cloud Project and obtain credentials:

    a. Create a Google Cloud Project:
       - Go to [Google Cloud Console](https://console.cloud.google.com/)
       - Create a new project or select an existing one
       - Enable the Gmail API for your project

    b. Create OAuth 2.0 Credentials:
       - Go to "APIs & Services" > "Credentials"
       - Click "Create Credentials" > "OAuth client ID"
       - Choose either "Desktop app" or "Web application" as application type
       - Give it a name and click "Create"
       - For Web application, add `http://localhost:3000/oauth2callback` to the authorized redirect URIs
       - Download the JSON file of your client's OAuth keys
       - Rename the key file to `gcp-oauth.keys.json`

2.  Run Authentication:

    You can authenticate in two ways:

    a. Global Authentication (Recommended):
    ```bash
    # First time: Place gcp-oauth.keys.json in your home directory's .gmail-mcp folder
    mkdir -p ~/.gmail-mcp
    mv gcp-oauth.keys.json ~/.gmail-mcp/

    # Run authentication from anywhere
    npx @gongrzhe/server-gmail-autoauth-mcp auth
    ```

    b. Local Authentication:
    ```bash
    # Place gcp-oauth.keys.json in your current directory
    # The file will be automatically copied to global config
    npx @gongrzhe/server-gmail-autoauth-mcp auth
    ```

    The authentication process will:
    - Look for `gcp-oauth.keys.json` in the current directory or `~/.gmail-mcp/`
    - If found in current directory, copy it to `~/.gmail-mcp/`
    - Open your default browser for Google authentication
    - Save credentials as `~/.gmail-mcp/credentials.json`

    > **Note**:
    > - After successful authentication, credentials are stored globally in `~/.gmail-mcp/` and can be used from any directory
    > - Both Desktop app and Web application credentials are supported
    > - For Web application credentials, make sure to add `http://localhost:3000/oauth2callback` to your authorized redirect URIs

3.  Configure in Claude Desktop:

```json
{
  "mcpServers": {
    "gmail": {
      "command": "npx",
      "args": [
        "@gongrzhe/server-gmail-autoauth-mcp"
      ]
    }
  }
}
```

**Docker Support:**

1. Authentication:
```bash
docker run -i --rm \
  --mount type=bind,source=/path/to/gcp-oauth.keys.json,target=/gcp-oauth.keys.json \
  -v mcp-gmail:/gmail-server \
  -e GMAIL_OAUTH_PATH=/gcp-oauth.keys.json \
  -e "GMAIL_CREDENTIALS_PATH=/gmail-server/credentials.json" \
  -p 3000:3000 \
  mcp/gmail auth
```

2. Usage:
```json
{
  "mcpServers": {
    "gmail": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "mcp-gmail:/gmail-server",
        "-e",
        "GMAIL_CREDENTIALS_PATH=/gmail-server/credentials.json",
        "mcp/gmail"
      ]
    }
  }
}
```

## Tools

## Available Tools

1.  Send Email (`send_email`) (Sends a new email immediately.)
2.  Draft Email (`draft_email`) (Creates a draft email without sending it.)
3.  Read Email (`read_email`) (Retrieves the content of a specific email by its ID.)
4.  Search Emails (`search_emails`) (Searches for emails using Gmail search syntax.)
5.  Modify Email (`modify_email`) (Adds or removes labels from emails.)
6.  Delete Email (`delete_email`) (Permanently deletes an email.)
7.  List Email Labels (`list_email_labels`) (Retrieves all available Gmail labels.)
