npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

unified-gmail-mcp

v1.1.0

Published

Unified inbox MCP server for multiple Gmail accounts with HTML/Markdown support and attachments

Downloads

12

Readme

Unified Gmail MCP Server

A Model Context Protocol (MCP) server that provides a truly unified inbox across multiple Gmail accounts. Unlike traditional multi-account email tools that simply switch between accounts, this MCP aggregates messages from all your Gmail accounts into a single, chronologically-sorted stream.

Perfect for managing personal, work, and client email addresses through Claude or other MCP-compatible AI assistants.

Features

  • 📬 Unified Inbox - View messages from all accounts in a single, date-sorted stream
  • 🔍 Cross-Account Search - Search across all connected Gmail accounts simultaneously
  • 📤 Send & Reply - Send emails from any connected account with proper threading
  • Rich Text Emails - Send plain text, HTML, or Markdown emails (auto-converted to styled HTML)
  • 📎 Attachments - Send files with any email (base64 encoded)
  • 🗄️ Archive Support - Archive messages across all accounts
  • 🔐 OAuth 2.0 - Secure authentication with automatic token refresh
  • 💾 Local Storage - Tokens stored locally in SQLite (not sent to external servers)
  • Parallel Fetching - Fast performance with concurrent API calls
  • 🔢 Multi-Account - Support for up to 10 Gmail accounts

Installation

Option 1: npm (Recommended)

Install globally and run with npx:

npm install -g unified-gmail-mcp

Or use directly with npx (no install required):

{
  "mcpServers": {
    "unified-gmail": {
      "command": "npx",
      "args": ["-y", "unified-gmail-mcp"],
      "env": {
        "GOOGLE_OAUTH_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GOOGLE_OAUTH_CLIENT_SECRET": "your-client-secret"
      }
    }
  }
}

Option 2: From Source

  1. Clone the repository:

    git clone https://github.com/mrchevyceleb/unified-gmail-mcp.git
    cd unified-gmail-mcp
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build
  4. Set up Google OAuth credentials (see Setup Guide below)

  5. Configure your MCP client (see Configuration below)

Google OAuth Setup

Step 1: Create a Google Cloud Project

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Navigate to APIs & Services > Library
  4. Search for "Gmail API" and click Enable

Step 2: Create OAuth 2.0 Credentials

IMPORTANT: You must use a Web application OAuth client type, NOT Desktop.

  1. In Google Cloud Console, go to APIs & Services > Credentials
  2. Click + CREATE CREDENTIALS > OAuth client ID
  3. Select Web application as the application type
  4. Under Authorized redirect URIs, add:
    http://localhost:8089/callback
  5. Click Create and save your Client ID and Client Secret

Common Mistake: Make sure you add the redirect URI under "Authorized redirect URIs" in the OAuth client settings, NOT under "Authorized Domains" in the Branding section.

Required OAuth Scopes

The server requests these scopes during authentication:

  • gmail.readonly - Read email messages
  • gmail.send - Send emails
  • gmail.modify - Archive messages (modify labels)
  • gmail.labels - Access label information
  • userinfo.email - Get user's email address

Configuration

Environment Variables

| Variable | Required | Description | |----------|----------|-------------| | GOOGLE_OAUTH_CLIENT_ID | Yes | Your Google OAuth Client ID | | GOOGLE_OAUTH_CLIENT_SECRET | Yes | Your Google OAuth Client Secret | | GMAIL_MCP_DATA_DIR | No | Custom path for token storage (default: ~/.unified-gmail-mcp) |

Claude Desktop

Add this to your Claude Desktop config file:

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

Using npx (Recommended)

{
  "mcpServers": {
    "unified-gmail": {
      "command": "npx",
      "args": ["-y", "unified-gmail-mcp"],
      "env": {
        "GOOGLE_OAUTH_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GOOGLE_OAUTH_CLIENT_SECRET": "your-client-secret"
      }
    }
  }
}

Using Local Installation

{
  "mcpServers": {
    "unified-gmail": {
      "command": "node",
      "args": ["/absolute/path/to/unified-gmail-mcp/dist/index.js"],
      "env": {
        "GOOGLE_OAUTH_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GOOGLE_OAUTH_CLIENT_SECRET": "your-client-secret"
      }
    }
  }
}

Other MCP Clients

The server uses stdio transport and requires these environment variables:

  • GOOGLE_OAUTH_CLIENT_ID - Your Google OAuth Client ID
  • GOOGLE_OAUTH_CLIENT_SECRET - Your Google OAuth Client Secret

Usage

Adding Accounts

When you first use the MCP, you'll need to authenticate your Gmail accounts:

"Add my Gmail account"

This will:

  1. Open a browser window for OAuth authentication
  2. Ask you to sign in to your Google account
  3. Request permission to access Gmail
  4. Save the tokens locally for future use

Repeat for each Gmail account you want to add (up to 10 accounts).

Checking Email

"Show me a summary of all my email accounts"

Returns unread counts and recent subjects for each connected account.

"Get my latest 20 emails across all accounts"

Returns a unified, chronologically-sorted stream of messages.

Searching

"Search all my accounts for invoices from last month"

Uses Gmail search syntax across all connected accounts.

Sending Email

Plain Text

"Send an email from my work account to [email protected]"

Markdown (Rich Text)

"Send an email with format markdown to [email protected] with body:

# Meeting Summary

Here are the key points:
- Item 1
- Item 2

**Action items** are due Friday."

The markdown is automatically converted to beautifully styled HTML.

HTML

"Send an HTML email to [email protected] with this body: <h1>Hello</h1><p>Welcome!</p>"

Replying

"Reply to that message from Sarah saying I'll be there at 3pm"

Automatically uses the account that received the original message.

Sending with Attachments

"Send an email to [email protected] with subject 'Report' and attach the PDF"

Attachments are provided as base64-encoded content with filename and MIME type.

Archiving

"Archive those DMARC report emails"

Removes messages from inbox while keeping them in the account.

Available Tools

The MCP provides these tools to AI assistants:

Account Management

  • add_account - Add a Gmail account via OAuth (max 10 accounts)
  • list_accounts - List all connected accounts with status
  • remove_account - Remove a Gmail account

Unified Operations

  • get_messages - Get unified message stream from all accounts
  • search - Cross-account search with Gmail query syntax
  • get_message - Get details of a specific message
  • summary - Get overview of all accounts (unread counts, recent subjects)

Email Operations

  • send - Send email from a specific account
    • Supports format: plain (default), html, or markdown
    • Supports attachments: Array of {filename, content, mimeType}
  • reply - Reply to a message (auto-detects correct account)
    • Supports format and attachments same as send
  • archive_message - Archive a single message
  • archive_messages - Archive multiple messages

Send Tool Parameters

{
  account: string;        // Email address to send from
  to: string[];          // Recipient email addresses
  subject: string;       // Email subject
  body: string;          // Email body content
  cc?: string[];         // CC recipients
  bcc?: string[];        // BCC recipients
  format?: 'plain' | 'html' | 'markdown';  // Email format (default: plain)
  attachments?: Array<{
    filename: string;    // Name of the file
    content: string;     // Base64 encoded content
    mimeType: string;    // MIME type (e.g., "application/pdf")
  }>;
}

Architecture

Project Structure

unified-gmail-mcp/
├── src/
│   ├── index.ts              # MCP server entry point
│   ├── auth/
│   │   ├── oauth.ts          # OAuth 2.0 flow with callback server
│   │   └── token-store.ts    # SQLite token storage (10 account limit)
│   ├── gmail/
│   │   ├── client.ts         # Gmail API wrapper with MIME support
│   │   └── types.ts          # TypeScript interfaces
│   ├── unified/
│   │   ├── aggregator.ts     # Parallel fetch and merge logic
│   │   └── summary.ts        # Account summaries
│   └── tools/
│       ├── accounts.ts       # Account management tools
│       ├── messages.ts       # Unified message tools
│       └── send.ts           # Send and reply tools
├── dist/                     # Compiled JavaScript
└── package.json

Data Storage

OAuth tokens are stored locally in SQLite:

Default Location: ~/.unified-gmail-mcp/accounts.db Custom Location: Set GMAIL_MCP_DATA_DIR environment variable

Schema:

CREATE TABLE accounts (
  email TEXT PRIMARY KEY,
  access_token TEXT NOT NULL,
  refresh_token TEXT NOT NULL,
  token_expiry INTEGER NOT NULL
)

Key Design Decisions

  1. Parallel API Calls - Uses Promise.all() to fetch from multiple accounts simultaneously
  2. Automatic Token Refresh - Tokens refreshed automatically when expired (or within 60 seconds of expiry)
  3. Chronological Sorting - Messages sorted by date after aggregation for unified timeline
  4. Minimal Caching - Fresh API calls ensure data accuracy
  5. Per-Account Limits - Request limits divided among accounts for balanced representation
  6. MIME Multipart - Proper email structure for HTML + attachments
  7. Markdown Rendering - Uses marked for beautiful HTML conversion with inline styles

Development

Build

npm run build

Watch Mode

npm run dev

Project Requirements

  • TypeScript 5.6+
  • Node.js 18+
  • See package.json for all dependencies

Troubleshooting

"redirect_uri_mismatch" Error

Cause: OAuth client misconfiguration

Solution:

  1. Verify you're using Web application OAuth client (NOT Desktop)
  2. Confirm http://localhost:8089/callback is in Authorized redirect URIs
  3. Make sure it's in the OAuth client settings, not the Branding section

"Gmail API has not been used" Error

Cause: Gmail API not enabled in Google Cloud project

Solution:

  1. Go to Google Cloud Console > APIs & Services > Library
  2. Search for "Gmail API"
  3. Click Enable

"Maximum of 10 accounts reached" Error

Cause: You've already added 10 Gmail accounts

Solution: Remove an existing account before adding a new one:

"Remove my [email protected] account"

Accounts Showing Disconnected

Cause: Token refresh failure

Solution:

  1. Remove the account: "Remove my [email protected] account"
  2. Re-add the account: "Add my Gmail account"
  3. Ensure you grant all permissions during OAuth

Port Already in Use (8089)

Cause: Previous OAuth session still active

Solution:

  • Wait 5 minutes for timeout, or
  • Manually kill process using port 8089

Reset All Accounts

Delete the token database and restart:

macOS/Linux:

rm -rf ~/.unified-gmail-mcp/

Windows:

Remove-Item -Recurse -Force $env:USERPROFILE\.unified-gmail-mcp\

Security Considerations

  • OAuth tokens stored locally in SQLite (not encrypted at rest)
  • Refresh tokens are long-lived - protect the accounts.db file
  • OAuth callback server runs temporarily on localhost:8089 during auth
  • No data sent to external servers except Google's APIs
  • All communication with Gmail API uses HTTPS

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE for details.

Credits

Built with:

Changelog

v1.1.0

  • New: HTML email support (format: 'html')
  • New: Markdown email support (format: 'markdown') with auto-conversion to styled HTML
  • New: Attachment support for send and reply
  • New: 10 account limit with clear error messages
  • New: Configurable data directory via GMAIL_MCP_DATA_DIR environment variable
  • New: npm package support - install via npm install -g unified-gmail-mcp or use with npx

v1.0.0

  • Initial release
  • Unified inbox across multiple Gmail accounts
  • Send, reply, and archive functionality
  • OAuth 2.0 authentication

Support


Made with ❤️ for the MCP community