gmail-mcp-server

Hlake7/gmail-mcp-server

3.1

If you are the rightful owner of gmail-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This guide provides instructions for setting up a Gmail MCP server to enable Claude to manage Gmail accounts.

Gmail MCP Server Setup Guide

This guide will help you set up your own Gmail MCP (Model Context Protocol) server to allow Claude to access and manage your Gmail account.

What This Does

This MCP server gives Claude the ability to:

  • List and search your emails
  • Read email content and details
  • Send new emails
  • Manage Gmail labels (add, remove, create)
  • Mark emails as read/unread
  • Delete emails
  • List all available labels

Prerequisites

  • Node.js (v16 or higher)
  • A Google account with Gmail
  • Claude Desktop app or MCP-compatible client

Setup Instructions

1. Clone and Setup the Project

# Clone or copy the gmail-mcp-server folder
cd path/to/your/projects
git clone https://github.com/yourusername/gmail-mcp-server.git
cd gmail-mcp-server
npm install

2. Google Cloud Console Setup

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Gmail API:
    • Go to "APIs & Services" > "Library"
    • Search for "Gmail API"
    • Click on it and press "Enable"

3. Create OAuth 2.0 Credentials

  1. Go to "APIs & Services" > "Credentials"
  2. Click "Create Credentials" > "OAuth 2.0 Client IDs"
  3. If prompted, configure the OAuth consent screen first:
    • Choose "External" user type
    • Fill in required fields (App name, User support email, Developer contact)
    • Add your email to test users
  4. For the OAuth 2.0 Client ID:
    • Application type: "Desktop application"
    • Name: "Gmail MCP Server" (or whatever you prefer)
  5. Download the JSON file and save it as credentials.json in your project root

4. Configure the MCP Server

  1. Copy the example environment file:

    cp .env.example .env
    
  2. Update .env with your settings (optional):

    GMAIL_CREDENTIALS_PATH=./credentials.json
    GMAIL_TOKEN_PATH=./token.json
    PORT=3000
    

5. First-Time Authentication

  1. Run the server for the first time:

    npm start
    
  2. The server will open a browser window for Google OAuth

  3. Sign in with your Google account

  4. Grant the requested permissions

  5. The server will save your authentication token automatically

6. Configure Claude Desktop

Add the MCP server to your Claude Desktop configuration:

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

{
  "mcpServers": {
    "gmail": {
      "command": "node",
      "args": ["C:\\full\\path\\to\\your\\gmail-mcp-server\\server.js"],
      "cwd": "C:\\full\\path\\to\\your\\gmail-mcp-server",
      "env": {
        "GMAIL_CREDENTIALS_PATH": "C:\\full\\path\\to\\your\\gmail-mcp-server\\credentials.json"
      }
    }
  }
}

Windows Example:

{
  "mcpServers": {
    "gmail": {
      "command": "node",
      "args": ["C:\\Users\\YourName\\Projects\\gmail-mcp-server\\server.js"],
      "cwd": "C:\\Users\\YourName\\Projects\\gmail-mcp-server",
      "env": {
        "GMAIL_CREDENTIALS_PATH": "C:\\Users\\YourName\\Projects\\gmail-mcp-server\\credentials.json"
      }
    }
  }
}

7. Restart Claude Desktop

Close and reopen Claude Desktop. You should now see Gmail tools available in your conversations.

Testing the Setup

Try asking Claude:

  • "List my recent emails"
  • "Show me unread emails"
  • "Send an email to [someone]"

File Structure

gmail-mcp-server/
ā”œā”€ā”€ server.js            # Main server file
ā”œā”€ā”€ package.json         # Dependencies
ā”œā”€ā”€ credentials.json     # Google OAuth credentials (you create this)
ā”œā”€ā”€ token.json          # OAuth token (auto-generated)
ā”œā”€ā”€ .env                # Environment variables (optional)
ā”œā”€ā”€ .env.example        # Environment template
ā”œā”€ā”€ .gitignore          # Git ignore file
└── README.md           # This file

Security Notes

  • Never commit credentials.json or token.json to version control
  • The .gitignore file is configured to exclude these sensitive files
  • Keep your OAuth credentials secure and don't share them
  • Consider using a dedicated Google account for testing

Troubleshooting

Authentication Issues

  • Make sure the Gmail API is enabled in Google Cloud Console
  • Check that your OAuth consent screen is properly configured
  • Verify the credentials.json file is in the correct location

Permission Errors

  • Ensure your Google account has the necessary permissions
  • Try re-running the authentication flow by deleting token.json

Claude Integration Issues

  • Verify the path in claude_desktop_config.json is correct
  • Make sure Claude Desktop is fully restarted after configuration changes
  • Check that Node.js is in your system PATH

Available Gmail Scopes

The server requests these Gmail permissions:

  • https://www.googleapis.com/auth/gmail.readonly - Read emails
  • https://www.googleapis.com/auth/gmail.send - Send emails
  • https://www.googleapis.com/auth/gmail.modify - Modify emails (labels, read status)

Support

If you run into issues:

  1. Check the console output for error messages
  2. Verify all setup steps were completed
  3. Make sure all dependencies are installed
  4. Try deleting token.json and re-authenticating

Contributing

Feel free to submit issues, fork the repository, and create pull requests for any improvements.

License

This project is licensed under the ISC License.