Gmail MCP server

Integrates with Gmail to enable email management tasks like sending, reading, searching, and labeling through natural language commands.
Back to servers
Setup instructions
Provider
gongrzhe
Release date
Dec 26, 2024
Language
TypeScript
Stats
571 stars

The Gmail AutoAuth MCP server integrates Gmail functionality into Claude Desktop through Model Context Protocol, enabling AI assistants to manage emails with natural language commands. It supports sending emails with attachments, downloading attachments, searching emails, managing labels, and performing batch operations.

Installation and Authentication

Installing via Smithery

For automatic installation through Smithery:

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

Manual Installation

Step 1: Create Google Cloud Project and Obtain Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Gmail API for your project
  4. Create OAuth 2.0 Credentials:
    • Navigate to "APIs & Services" > "Credentials"
    • Click "Create Credentials" > "OAuth client ID"
    • Choose "Desktop app" or "Web application" as application type
    • For Web application, add http://localhost:3000/oauth2callback to authorized redirect URIs
    • Download the JSON file and rename it to gcp-oauth.keys.json

Step 2: Authentication

Global Authentication (Recommended):

# 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

Local Authentication:

# Place gcp-oauth.keys.json in your current directory
npx @gongrzhe/server-gmail-autoauth-mcp auth

The authentication process will:

  • Look for credentials in current directory or ~/.gmail-mcp/
  • Copy credentials to global location if found locally
  • Launch browser for Google authentication
  • Save credentials as ~/.gmail-mcp/credentials.json

Step 3: Configure in Claude Desktop

Add this to your Claude Desktop configuration:

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

Docker Support

For Docker users:

  1. Authentication:
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
  1. Configuration:
{
  "mcpServers": {
    "gmail": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "mcp-gmail:/gmail-server",
        "-e",
        "GMAIL_CREDENTIALS_PATH=/gmail-server/credentials.json",
        "mcp/gmail"
      ]
    }
  }
}

Cloud Server Authentication

For cloud environments:

npx @gongrzhe/server-gmail-autoauth-mcp auth https://your-domain.com/oauth2callback

Setup instructions:

  1. Configure a reverse proxy to forward traffic to your authentication port
  2. Add the callback URL to authorized redirect URIs in Google Cloud Console
  3. Run authentication with your custom callback URL
  4. Configure your application to use the server

Available Tools

Send Email

Sends a new email immediately with various format options.

Basic email:

{
  "to": ["[email protected]"],
  "subject": "Meeting Tomorrow",
  "body": "Hi,\n\nJust a reminder about our meeting tomorrow at 10 AM.\n\nBest regards",
  "cc": ["[email protected]"],
  "bcc": ["[email protected]"],
  "mimeType": "text/plain"
}

Email with attachments:

{
  "to": ["[email protected]"],
  "subject": "Project Files",
  "body": "Hi,\n\nPlease find the project files attached.\n\nBest regards",
  "attachments": [
    "/path/to/document.pdf",
    "/path/to/spreadsheet.xlsx"
  ]
}

HTML email:

{
  "to": ["[email protected]"],
  "subject": "Meeting Tomorrow",
  "mimeType": "text/html",
  "body": "<html><body><h1>Meeting Reminder</h1><p>Just a reminder about our <b>meeting tomorrow</b> at 10 AM.</p></body></html>"
}

Draft Email

Creates a draft without sending:

{
  "to": ["[email protected]"],
  "subject": "Draft Report",
  "body": "Here's the draft report for your review.",
  "cc": ["[email protected]"],
  "attachments": ["/path/to/draft_report.docx"]
}

Read Email

Retrieves email content by ID:

{
  "messageId": "182ab45cd67ef"
}

Response includes attachment details:

Subject: Project Files
From: [email protected]
To: [email protected]
Date: Thu, 19 Jun 2025 10:30:00 -0400

Email body content here...

Attachments (2):
- document.pdf (application/pdf, 245 KB, ID: ANGjdJ9fkTs-i3GCQo5o97f_itG...)
- spreadsheet.xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, 89 KB, ID: BWHkeL8gkUt-j4HDRp6o98g_juI...)

Download Attachment

Downloads email attachments to your local filesystem:

{
  "messageId": "182ab45cd67ef",
  "attachmentId": "ANGjdJ9fkTs-i3GCQo5o97f_itG...",
  "savePath": "/path/to/downloads",
  "filename": "downloaded_document.pdf"
}

Search Emails

Searches for emails using Gmail search syntax:

{
  "query": "from:[email protected] after:2024/01/01 has:attachment",
  "maxResults": 10
}

Modify Email

Adds or removes labels from emails:

{
  "messageId": "182ab45cd67ef",
  "addLabelIds": ["IMPORTANT"],
  "removeLabelIds": ["INBOX"]
}

Delete Email

Permanently deletes an email:

{
  "messageId": "182ab45cd67ef"
}

List Email Labels

Retrieves all available Gmail labels:

{}

Create Label

Creates a new Gmail label:

{
  "name": "Important Projects",
  "messageListVisibility": "show",
  "labelListVisibility": "labelShow"
}

Update Label

Updates an existing Gmail label:

{
  "id": "Label_1234567890",
  "name": "Urgent Projects",
  "messageListVisibility": "show",
  "labelListVisibility": "labelShow"
}

Delete Label

Deletes a Gmail label:

{
  "id": "Label_1234567890"
}

Get or Create Label

Gets a label or creates it if it doesn't exist:

{
  "name": "Project XYZ",
  "messageListVisibility": "show",
  "labelListVisibility": "labelShow"
}

Batch Modify Emails

Modifies labels for multiple emails:

{
  "messageIds": ["182ab45cd67ef", "182ab45cd67eg", "182ab45cd67eh"],
  "addLabelIds": ["IMPORTANT"],
  "removeLabelIds": ["INBOX"],
  "batchSize": 50
}

Batch Delete Emails

Permanently deletes multiple emails:

{
  "messageIds": ["182ab45cd67ef", "182ab45cd67eg", "182ab45cd67eh"],
  "batchSize": 50
}

Advanced Search Syntax

The search_emails tool supports Gmail's search operators:

Operator Example Description
from: from:[email protected] Emails from a specific sender
to: to:[email protected] Emails sent to a specific recipient
subject: subject:"meeting notes" Emails with specific text in the subject
has:attachment has:attachment Emails with attachments
after: after:2024/01/01 Emails received after a date
before: before:2024/02/01 Emails received before a date
is: is:unread Emails with a specific state
label: label:work Emails with a specific label

You can combine multiple operators: from:[email protected] after:2024/01/01 has:attachment

Troubleshooting

OAuth Keys Not Found

  • Ensure gcp-oauth.keys.json is in your current directory or ~/.gmail-mcp/
  • Check file permissions

Invalid Credentials Format

  • Verify your OAuth keys file contains either web or installed credentials
  • For web applications, check that the redirect URI is correctly configured

Port Already in Use

  • Free up port 3000 before running authentication

Batch Operation Failures

  • Review error messages for specific failures
  • Try reducing batch size if encountering rate limiting

Attachment Issues

  • Verify file paths are correct and accessible
  • Check read/write permissions
  • Note Gmail's 25MB attachment size limit per email

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "gmail" '{"command":"npx","args":["@gongrzhe/server-gmail-autoauth-mcp"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

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

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later