Gmail MCP server

Manage your emails effortlessly with a standardized interface for drafting, sending, retrieving, and organizing messages. Streamline your email workflow with complete Gmail API coverage, including label and thread management.
Back to servers
Setup instructions
Provider
Shinzo Labs
Release date
Mar 27, 2025
Language
TypeScript
Package
Stats
5.3K downloads
29 stars

Gmail MCP Server is a Model Context Protocol implementation that provides a standardized interface for managing Gmail services including emails, threads, labels, drafts, and settings. It connects your applications to Gmail through a secure OAuth2 authentication process with Google Cloud credentials.

Prerequisites

Dependencies

To install the Gmail MCP server, you'll need:

  • Node.js 18 or higher

Google Workspace Setup

Google API Client Setup (Once Per Organization)

  1. Navigate to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Gmail API for your project
  4. Go to Credentials and create an OAuth 2.0 Client ID (choose "Desktop app" type)
  5. Download the OAuth keys JSON file and save it to ~/.gmail-mcp/gcp-oauth.keys.json
    • Note: On MacOS, you may need to enable hidden files to create the .gmail-mcp directory

Client OAuth Authorization (Once Per User)

  1. Have the user copy the ~/.gmail-mcp/gcp-oauth.keys.json file to their computer at the same path
  2. Run the authentication command:
    npx @shinzolabs/gmail-mcp auth
    
  3. A browser window will open for the user to select their profile and approve the requested permissions
  4. For remote server installations, the refresh token will be stored in ~/.gmail-mcp/credentials.json

Installation Options

Using Smithery Remote Server (Recommended)

To install using Smithery's CLI:

npx -y @smithery/cli install @shinzo-labs/gmail-mcp

You'll be prompted to enter your CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN.

Local Installation with NPX

Add the following configuration to your MCP client's config.json:

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

Building from Source

  1. Clone the repository:

    git clone https://github.com/shinzo-labs/gmail-mcp.git
    
  2. Install packages and build:

    pnpm i && pnpm build
    
  3. Configure your MCP client's config.json:

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

Configuration Variables

The following environment variables can be used to configure the server:

Variable Description Required? Default
AUTH_SERVER_PORT Port for OAuth authentication server No 3000
CLIENT_ID Google API client ID For remote server ''
CLIENT_SECRET Google API client secret For remote server ''
GMAIL_CREDENTIALS_PATH Path to user credentials file No MCP_CONFIG_DIR/credentials.json
GMAIL_OAUTH_PATH Path to Google API Client file No MCP_CONFIG_DIR/gcp-oauth.keys.json
MCP_CONFIG_DIR Directory for configuration files No ~/.gmail-mcp
REFRESH_TOKEN OAuth refresh token For remote server ''
PORT Port for HTTP transport No 3000
TELEMETRY_ENABLED Enable telemetry No true

Using the MCP Server

The Gmail MCP server provides endpoints for various Gmail operations:

Message Management

To list messages with optional filtering:

const result = await mcp.invoke("gmail", "list_messages", {
  maxResults: 10,
  q: "is:unread"
});

To get a specific message:

const result = await mcp.invoke("gmail", "get_message", {
  id: "message-id-here",
  format: "full"
});

To send an email:

const result = await mcp.invoke("gmail", "send_message", {
  message: {
    to: ["[email protected]"],
    subject: "Hello",
    body: "This is a test email"
  }
});

Label Management

To list all labels:

const result = await mcp.invoke("gmail", "list_labels", {});

To create a new label:

const result = await mcp.invoke("gmail", "create_label", {
  name: "My New Label",
  labelListVisibility: "labelShow",
  messageListVisibility: "show"
});

Thread Management

To list email threads:

const result = await mcp.invoke("gmail", "list_threads", {
  maxResults: 10,
  q: "label:inbox"
});

Draft Management

To create a draft email:

const result = await mcp.invoke("gmail", "create_draft", {
  message: {
    to: ["[email protected]"],
    subject: "Draft Email",
    body: "This is a draft email"
  }
});

Settings Management

To get vacation responder settings:

const result = await mcp.invoke("gmail", "get_vacation", {});

To update vacation responder:

const result = await mcp.invoke("gmail", "update_vacation", {
  enableAutoReply: true,
  responseSubject: "Out of Office",
  responseBodyHtml: "<p>I am currently out of office until January 1st.</p>",
  startTime: "2023-12-24T00:00:00Z",
  endTime: "2024-01-01T23:59:59Z"
});

Advanced Usage

Working with Attachments

To get a message attachment:

const result = await mcp.invoke("gmail", "get_attachment", {
  messageId: "message-id-here",
  id: "attachment-id-here"
});

Batch Operations

To modify multiple messages at once:

const result = await mcp.invoke("gmail", "batch_modify_messages", {
  ids: ["msg1", "msg2", "msg3"],
  addLabelIds: ["Label_123"],
  removeLabelIds: ["UNREAD"]
});

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":["@shinzolabs/gmail-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": [
                "@shinzolabs/gmail-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": [
                "@shinzolabs/gmail-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