Skip to main content

MCP Server to connect to Google Workspace (Gmail & Calendar)

Project description

mcp-google-workspace MCP server

MCP server to interact with Google Workspace products (Gmail and Calendar).

Example prompts

Right now, this MCP server supports Gmail and Calendar integration with the following capabilities:

  1. General
  • Multiple google accounts
  1. Gmail
  • Get your Gmail user information
  • Query emails with flexible search (e.g., unread, from specific senders, date ranges, with attachments)
  • Retrieve complete email content by ID
  • Create new draft emails with:
    • Recipients, subject, and body
    • Optional CC recipients
    • HTML formatting support
    • File attachments
  • Send emails directly (not as drafts) with all the above features
  • Delete draft emails
  • Reply to existing emails with:
    • Support for HTML formatting and attachments
    • Option to send immediately or save as draft
  • Retrieve multiple emails at once by their IDs
  • Save multiple attachments from emails to your local system
  • List all Gmail labels (system and custom)
  • Create custom labels for email organization
  • Modify email labels:
    • Add or remove labels from messages
    • Archive emails (remove INBOX label)
    • Mark emails as read/unread
    • Star or mark emails as important
    • Apply custom labels
  • Move emails to trash (with automatic deletion after 30 days)
  • Batch operations for labeling and moving multiple emails
  1. Calendar
  • Manage multiple calendars
  • Get calendar events within specified time ranges
  • Create calendar events with:
    • Title, start/end times
    • Optional location and description
    • Optional attendees
    • Custom timezone support
    • Notification preferences
  • Delete calendar events

Example prompts you can try:

  • Retrieve my latest unread messages

  • Search my emails from the Scrum Master

  • Retrieve all emails from accounting

  • Take the email about ABC and summarize it

  • Write a nice response to Alice's last email and upload a draft.

  • Reply to Bob's email with a Thank you note. Store it as draft

  • Create a draft email with the quarterly report attached

  • Send an HTML-formatted newsletter to the team with images attached

  • Draft a professional email with my resume and cover letter attached

  • List all my Gmail labels

  • Create a new label called "Important Projects"

  • Archive all read emails from last month

  • Mark all emails from John as important

  • Move all promotional emails to trash

  • Apply the "Work" label to all emails from my company domain

  • What do I have on my agenda tomorrow?

  • Check my private account's Family agenda for next week

  • I need to plan an event with Tim for 2hrs next week. Suggest some time slots.

Quickstart

Install

Installing via PyPI

To install mcp-google-workspace:

pip install mcp-google-workspace

Or with uv:

uv pip install mcp-google-workspace

Oauth 2

Google Workspace (G Suite) APIs require OAuth2 authorization. Follow these steps to set up authentication:

  1. Create OAuth2 Credentials:

    • Go to the Google Cloud Console
    • Create a new project or select an existing one
    • Enable the Gmail API and Google Calendar API for your project
    • Go to "Credentials" → "Create Credentials" → "OAuth client ID"
    • Select "Desktop app" or "Web application" as the application type
    • Configure the OAuth consent screen with required information
    • Add authorized redirect URIs (include http://localhost:4100/code for local development)
  2. Required OAuth2 Scopes:

   [
     "openid",
     "https://mail.google.com/",
     "https://www.googleapis.com/auth/calendar",
     "https://www.googleapis.com/auth/userinfo.email"
   ]
  1. Then create a .gauth.json in your working directory with client
{
    "web": {
        "client_id": "$your_client_id",
        "client_secret": "$your_client_secret",
        "redirect_uris": ["http://localhost:4100/code"],
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token"
    }
}
  1. Create a .accounts.json file with account information
{
    "accounts": [
        {
            "email": "alice@bob.com",
            "account_type": "personal",
            "extra_info": "Additional info that you want to tell Claude: E.g. 'Contains Family Calendar'"
        }
    ]
}

You can specifiy multiple accounts. Make sure they have access in your Google Auth app. The extra_info field is especially interesting as you can add info here that you want to tell the AI about the account (e.g. whether it has a specific agenda)

Note: When you first execute one of the tools for a specific account, a browser will open, redirect you to Google and ask for your credentials, scope, etc. After a successful login, it stores the credentials in a local file called .oauth.{email}.json . Once you are authorized, the refresh token will be used.

Claude Code

To add this MCP server to Claude Code, run the following command:

claude mcp add mcp-google-workspace -- uvx mcp-google-workspace --gauth-file ~/.config/mcp-google/.gauth.json --accounts-file ~/.config/mcp-google/.accounts.json

After adding the server, restart Claude:

claude restart

You can customize the paths to your configuration files as needed. For local development, use:

claude mcp add mcp-google-workspace -- uv --directory /path/to/google-mcp run mcp-google-workspace --accounts-file /path/to/.accounts.json --credentials-dir /path/to/credentials

Claude Desktop

On MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json

On Windows: %APPDATA%/Claude/claude_desktop_config.json

Development/Unpublished Servers Configuration
{
  "mcpServers": {
    "mcp-google-workspace": {
      "command": "uv",
      "args": [
        "--directory",
        "<dir_to>/google-mcp",
        "run",
        "mcp-google-workspace"
      ]
    }
  }
}

Note: You can also use the uv run mcp-google-workspace --accounts-file /path/to/custom/.accounts.json to specify a different accounts file or --credentials-dir /path/to/custom/credentials to specify a different credentials directory.

{
  "mcpServers": {
    "mcp-google-workspace": {
      "command": "uv",
      "args": [
        "--directory",
        "<dir_to>/google-mcp",
        "run",
        "mcp-google-workspace",
        "--accounts-file",
        "/path/to/custom/.accounts.json",
        "--credentials-dir",
        "/path/to/custom/credentials"
      ]
    }
  }
}
Published Servers Configuration
{
  "mcpServers": {
    "mcp-google-workspace": {
      "command": "uvx",
      "args": [
        "mcp-google-workspace",
        "--accounts-file",
        "/path/to/custom/.accounts.json",
        "--credentials-dir",
        "/path/to/custom/credentials"
      ]
    }
  }
}

Configuration Options

The MCP server can be configured with several command-line options to specify custom paths for authentication and account information:

  • --gauth-file: Specifies the path to the .gauth.json file containing OAuth2 client configuration. Default is ./.gauth.json.
  • --accounts-file: Specifies the path to the .accounts.json file containing information about the Google accounts. Default is ./.accounts.json.
  • --credentials-dir: Specifies the directory where OAuth credentials are stored after successful authentication. Default is the current working directory with a subdirectory for each account as .oauth.{email}.json.

These options allow for flexibility in managing different environments or multiple sets of credentials and accounts, especially useful in development and testing scenarios.

Example usage:

uv run mcp-google-workspace --gauth-file /path/to/custom/.gauth.json --accounts-file /path/to/custom/.accounts.json --credentials-dir /path/to/custom/credentials

This configuration is particularly useful when you have multiple instances of the server running with different configurations or when deploying to environments where the default paths are not suitable.

Development

Building and Publishing

To prepare the package for distribution:

  1. Sync dependencies and update lockfile:
uv sync
  1. Build package distributions:
uv build

This will create source and wheel distributions in the dist/ directory.

  1. Publish to PyPI:
uv publish

Note: You'll need to set PyPI credentials via environment variables or command flags:

  • Token: --token or UV_PUBLISH_TOKEN
  • Or username/password: --username/UV_PUBLISH_USERNAME and --password/UV_PUBLISH_PASSWORD

Debugging

Since MCP servers run over stdio, debugging can be challenging. For the best debugging experience, we strongly recommend using the MCP Inspector.

You can launch the MCP Inspector via npm with this command:

npx @modelcontextprotocol/inspector uv --directory /path/to/google-mcp run mcp-google-workspace

Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging.

You can also watch the server logs with this command:

tail -n 20 -f ~/Library/Logs/Claude/mcp-server-mcp-google-workspace.log

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

mcp_google_workspace-0.6.0.tar.gz (93.9 kB view details)

Uploaded Source

Built Distribution

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

mcp_google_workspace-0.6.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_google_workspace-0.6.0.tar.gz.

File metadata

File hashes

Hashes for mcp_google_workspace-0.6.0.tar.gz
Algorithm Hash digest
SHA256 7b4267b3b126971d8b55e7aacd397d28cf0e33c8c3756fd62240b6c7a83cbb5a
MD5 d5d725c81e858a16507a7e38c2d2736c
BLAKE2b-256 20e5c00bc2301751af5d13755acf27f1d287205fde91994beca2ecc56357ca39

See more details on using hashes here.

File details

Details for the file mcp_google_workspace-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_google_workspace-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d49ecb15a3a5de2ac5effd751169f41d2d5899969f01ed69d8a76960d3d7956c
MD5 08dde96ce080e26fdc600c25c20bf87d
BLAKE2b-256 f0b1dc591dcd1c9163f28b239d7519856f3463ed714f05f138dd68375abe72ac

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