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

@gongrzhe/server-gmail-mcp

v0.0.8

Published

Gmail MCP server with auto authentication support

Downloads

33

Readme

Gmail MCP Server

A Model Context Protocol (MCP) server for Gmail integration with comprehensive email management capabilities, attachments support, and OAuth2 authentication.

smithery badge

Features

  • Email Operations: Send, draft, read, search, modify, and delete emails
  • Attachment Support: Full support for sending and receiving file attachments
  • Label Management: Create, update, delete, and manage Gmail labels
  • Batch Operations: Process multiple emails efficiently in batches
  • OAuth2 Authentication: Secure authentication with auto browser launch
  • Multiple Transport Modes: Stdio, HTTP (Streamable), and SSE support
  • Session Management: Complete multi-user isolation and session-aware architecture

Quick Start

Starting the Server

# Start HTTP server on port 3000 (default)
node dist/index.js --http

# Start HTTP server on custom port
PORT=8080 node dist/index.js --http

# Start in stdio mode
node dist/index.js

The server provides these endpoints:

  • POST /mcp - Main MCP endpoint
  • GET /health - Health check with session statistics
  • GET /sessions - Session management information

Authentication

All requests require a Gmail OAuth2 access token via Authorization header:

Authorization: Bearer ya29.your_oauth_token_here

Set up Gmail API credentials and obtain OAuth2 tokens with the following scopes:

  • https://www.googleapis.com/auth/gmail.modify
  • https://www.googleapis.com/auth/gmail.readonly

Tools

The server provides 14 tools for comprehensive Gmail API access. Each tool requires Authorization: Bearer <token> header.

1. send_email

Send an email using Gmail API.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "1",
    "method": "tools/call",
    "params": {
      "name": "send_email",
      "arguments": {
        "to": ["[email protected]"],
        "subject": "Test Email",
        "body": "Hello from Gmail MCP Server!",
        "mimeType": "text/plain"
      }
    }
  }'

2. draft_email

Create a draft email.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "2",
    "method": "tools/call",
    "params": {
      "name": "draft_email",
      "arguments": {
        "to": ["[email protected]"],
        "subject": "Draft Email",
        "body": "This is a draft email",
        "htmlBody": "<p>This is a <b>draft</b> email</p>",
        "mimeType": "multipart/alternative"
      }
    }
  }'

3. read_email

Retrieve the content of a specific email.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "3",
    "method": "tools/call",
    "params": {
      "name": "read_email",
      "arguments": {
        "messageId": "1234567890abcdef"
      }
    }
  }'

4. search_emails

Search for emails using Gmail search syntax.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "4",
    "method": "tools/call",
    "params": {
      "name": "search_emails",
      "arguments": {
        "query": "from:[email protected] is:unread",
        "maxResults": 10
      }
    }
  }'

5. modify_email

Modify email labels (move to different folders).

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "5",
    "method": "tools/call",
    "params": {
      "name": "modify_email",
      "arguments": {
        "messageId": "1234567890abcdef",
        "addLabelIds": ["IMPORTANT"],
        "removeLabelIds": ["UNREAD"]
      }
    }
  }'

6. delete_email

Permanently delete an email.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "6",
    "method": "tools/call",
    "params": {
      "name": "delete_email",
      "arguments": {
        "messageId": "1234567890abcdef"
      }
    }
  }'

7. list_email_labels

Retrieve all available Gmail labels.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "7",
    "method": "tools/call",
    "params": {
      "name": "list_email_labels",
      "arguments": {}
    }
  }'

8. batch_modify_emails

Modify labels for multiple emails in batches.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "8",
    "method": "tools/call",
    "params": {
      "name": "batch_modify_emails",
      "arguments": {
        "messageIds": ["1234567890abcdef", "fedcba0987654321"],
        "addLabelIds": ["IMPORTANT"],
        "batchSize": 50
      }
    }
  }'

9. batch_delete_emails

Permanently delete multiple emails in batches.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "9",
    "method": "tools/call",
    "params": {
      "name": "batch_delete_emails",
      "arguments": {
        "messageIds": ["1234567890abcdef", "fedcba0987654321"],
        "batchSize": 50
      }
    }
  }'

10. create_label

Create a new Gmail label.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "10",
    "method": "tools/call",
    "params": {
      "name": "create_label",
      "arguments": {
        "name": "My Custom Label",
        "messageListVisibility": "show",
        "labelListVisibility": "labelShow"
      }
    }
  }'

11. update_label

Update an existing Gmail label.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "11",
    "method": "tools/call",
    "params": {
      "name": "update_label",
      "arguments": {
        "id": "Label_123456",
        "name": "Updated Label Name",
        "messageListVisibility": "hide"
      }
    }
  }'

12. delete_label

Delete a Gmail label.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "12",
    "method": "tools/call",
    "params": {
      "name": "delete_label",
      "arguments": {
        "id": "Label_123456"
      }
    }
  }'

13. get_or_create_label

Get an existing label by name or create it if it doesn't exist.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "13",
    "method": "tools/call",
    "params": {
      "name": "get_or_create_label",
      "arguments": {
        "name": "Project Alpha",
        "messageListVisibility": "show",
        "labelListVisibility": "labelShow"
      }
    }
  }'

14. download_attachment

Download an email attachment.

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "14",
    "method": "tools/call",
    "params": {
      "name": "download_attachment",
      "arguments": {
        "messageId": "1234567890abcdef",
        "attachmentId": "ANGjdJ123456",
        "filename": "document.pdf",
        "savePath": "/path/to/save"
      }
    }
  }'

List Available Tools

Get the complete list of available tools:

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer ya29.your_oauth_token_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": "tools-list",
    "method": "tools/list",
    "params": {}
  }'

Installation & Authentication

Installing via Smithery

To install Gmail AutoAuth for Claude Desktop automatically via Smithery:

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

Manual Installation

  1. Create Google Cloud Project and obtain credentials:

    • Go to Google Cloud Console
    • Create a new project or select an existing one
    • Enable the Gmail API
    • Create OAuth2 credentials (Desktop application type)
    • Download the credentials file
  2. Install the server:

    npm install -g @gongrzhe/server-gmail-mcp
  3. Configure authentication:

    • Place your OAuth2 credentials file in a secure location
    • The server will automatically launch the browser for OAuth flow
    • Tokens are stored securely for future use

Usage with Claude Desktop

Add the following to your claude_desktop_config.json:

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

Advanced Features

Session Management

  • Complete Multi-user Isolation: Each session is completely isolated
  • Session-aware Architecture: Proper response routing in concurrent environments
  • Automatic Session Cleanup: Expired sessions are automatically cleaned up

Batch Operations

  • Efficient Processing: Handle multiple emails in configurable batch sizes
  • Error Handling: Individual item failures don't stop batch processing
  • Progress Tracking: Detailed success/failure reporting

Attachment Support

  • Full MIME Support: Handle complex email structures with nested attachments
  • Security: Safe attachment processing with proper validation
  • Metadata: Complete attachment information including size, type, and filename

Health Monitoring

Check server health and session statistics:

curl http://localhost:3000/health

View active sessions:

curl http://localhost:3000/sessions

Error Handling

The server provides comprehensive error handling with specific error codes:

  • 401: Authentication errors (invalid or expired tokens)
  • 403: Permission errors (insufficient OAuth2 scopes)
  • 404: Resource not found errors
  • 500: Internal server errors

Gmail Search Syntax

When using the search_emails tool, you can use Gmail's powerful search syntax:

  • from:[email protected] - Emails from specific sender
  • to:[email protected] - Emails to specific recipient
  • subject:meeting - Emails with "meeting" in subject
  • has:attachment - Emails with attachments
  • is:unread - Unread emails
  • is:important - Important emails
  • in:inbox - Emails in inbox
  • label:work - Emails with specific label
  • after:2023/12/01 - Emails after specific date
  • before:2023/12/31 - Emails before specific date

Build

npm run build

License

This MCP server is licensed under the ISC License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the ISC License.