Skip to main content

MCP server for Gmail integration

Project description

Gmail MCP Server

An MCP (Model Context Protocol) server that provides Gmail integration capabilities to MCP clients like Claude Desktop.

Features

  • View recent emails from your Gmail inbox
  • Search emails using Gmail's search syntax
  • Secure OAuth2 authentication with Gmail API

Setup

1. Google Cloud Project Setup

  1. Create a Google Cloud Project at https://console.cloud.google.com/
  2. Enable the Gmail API
  3. Create OAuth 2.0 credentials:
    • Application type: Desktop application
    • Download the credentials as credentials.json

2. Installation

# Create a conda environment
conda create -n mcp-gmail python=3.12
conda activate mcp-gmail

# Install the package
cd gmail-mcp-server
pip install -e .

3. Configuration for Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "gmail": {
      "command": "/path/to/conda/envs/mcp-gmail/bin/python",
      "args": ["-m", "gmail_mcp_server.server"],
      "env": {
        "PYTHONPATH": "/path/to/gmail-mcp-server/src",
        "GMAIL_CREDENTIALS_FILE": "/path/to/credentials.json",
        "GMAIL_TOKEN_FILE": "/path/to/token.json"
      }
    }
  }
}

Replace /path/to/ with your actual paths. The token file will be created automatically when you first authenticate.

4. First Run

When you first try to access Gmail through Claude, you'll be prompted to authorize the application in your browser. After authorization, your credentials will be saved to the token file for future use.

Available Resources

  • gmail://inbox/recent - Returns your 10 most recent emails

Available Tools

  • search_emails
    • Description: Search Gmail emails with a query
    • Parameters:
      • query (required): Gmail search query (uses Gmail's standard search syntax)
      • max_results (optional): Maximum number of results to return (default: 10)

Example search:

Could you show me any emails from sanrio in the last two days?

Security

This server requires OAuth2 authentication with Gmail:

  • You'll be prompted to authorize access in your browser on first use
  • Credentials are stored locally in the specified token file
  • Access can be revoked at any time through your Google Account settings
  • Only read access to Gmail is requested (no write permissions)

Environment Variables

  • GMAIL_CREDENTIALS_FILE (required): Path to your Google OAuth credentials file
  • GMAIL_TOKEN_FILE (required): Path where the authentication token will be saved

For testing, you can run the server directly:

GMAIL_CREDENTIALS_FILE="/path/to/credentials.json" \
GMAIL_TOKEN_FILE="/path/to/token.json" \
python -m gmail_mcp_server.server

Development

The server uses the Model Context Protocol to provide:

  • Resource access to recent emails
  • Tool support for email search
  • Secure OAuth2 authentication flow
  • Automatic token refresh

Logging

The server logs detailed information about its operations to stderr, including:

  • Server startup information
  • Authentication status
  • Resource and tool usage
  • Any errors or issues

Contributing

Pull requests are welcome! Please ensure to:

  • Update documentation for any new features
  • Add appropriate error handling
  • Test OAuth flow with new features
  • Follow existing code style

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_gmail_mcp_server-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iflow_mcp_gmail_mcp_server-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_gmail_mcp_server-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_gmail_mcp_server-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_gmail_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 48dbcceca680ef13fb45bfb8d73a7e4f8d862d188e8eddb92a6350d1a620123f
MD5 38f756df62674b6de3e7f27d058f606d
BLAKE2b-256 a37cbecc16143652d5c85202d413add252b357288c265cbf7edbc158ef1ee84e

See more details on using hashes here.

File details

Details for the file iflow_mcp_gmail_mcp_server-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_gmail_mcp_server-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_gmail_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d97ca2d2a687d5691fc9e7f5fc887454f1df67ecf764fa55189aa036e47506a
MD5 40e5ee671ac54c30477a7ddb2f46fc5c
BLAKE2b-256 7c16b5a9e5e4c872bf1dd0e69754f2e9b9fe8c26338638cf9e841b8136593046

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page