Gmail MCP Server
Provides tools for listing recent emails, drafting replies, and sending authorized emails through the Gmail API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Gmail MCP ServerList my 10 most recent emails"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Gmail MCP Server π¬
A local Model Context Protocol (MCP) server that connects AI assistants (like Claude) directly to your Gmail account. It lets an AI read your inbox, save drafts, and send emails β but only when you explicitly approve it.
π€ What Does This Server Do?
This server acts as a secure bridge between an AI assistant and your Gmail. Instead of giving an AI full access to your email, it exposes exactly 3 controlled tools:
Tool | What It Does | Can It Send Email? |
| Reads the last 10 emails in your inbox (subject, sender, date only β no body) | β No |
| Creates a draft in your Gmail Drafts folder | β No β structurally impossible |
| Sends an email via Gmail | β Yes β but only if you provide a secret token |
π Why Is It Safe?
list_recent_emailsuses read-only Gmail scope. It cannot modify anything.draft_replycallsdrafts.createβ the Gmail API endpoint for creating drafts. The code does not containmessages.sendanywhere. An AI cannot accidentally send an email through this tool.send_confirmed_emailrequires a secret token that only you know. Without it, the request is blocked in Python code before Gmail is ever contacted.
Related MCP server: Gmail MCP Server
β Prerequisites
Before starting, make sure you have:
Python 3.10 or newer β check with
python --versionNode.js β needed to run the MCP Inspector. Download from https://nodejs.org
A Google account (the Gmail you want to connect)
A Google Cloud project with the Gmail API enabled (see Step 1 below)
π Setup Guide
Step 1 β Enable Gmail API on Google Cloud (One-Time Setup)
This gives your server permission to talk to Gmail.
Click "Select a project" β "New Project" β give it any name β Create
In the left menu go to APIs & Services β Library
Search for "Gmail API" β click it β click Enable
Go to APIs & Services β OAuth consent screen
Choose External β click Create
Fill in an App name (e.g.
Gmail MCP) and your email β click Save and Continue through all stepsOn the Test Users page β click "+ Add Users" β add your Gmail address β Save
Go to APIs & Services β Credentials
Click "+ Create Credentials" β choose "OAuth 2.0 Client ID"
Application type: Desktop app β click Create
Click "Download JSON" on the newly created credential
Rename the downloaded file to
credentials.jsonand place it in this project folder:
gmail-mcp-server/
βββ credentials.json β put it hereβ οΈ
credentials.jsonis in.gitignoreand will never be committed to GitHub. Keep it private.
Step 2 β Clone the Repository
git clone https://github.com/adel-noufal/Gmail-Mcp-Server-Automation.git
cd Gmail-Mcp-Server-AutomationStep 3 β Create a Python Virtual Environment
# Create the virtual environment
python -m venv .venv
# Activate it (Windows PowerShell)
.\.venv\Scripts\Activate.ps1
# If you get a permissions error, run this first:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserOn Mac/Linux:
source .venv/bin/activate
Step 4 β Install Dependencies
pip install -r requirements.txtThis installs the MCP library, Google API client, and authentication libraries.
Step 5 β Set Your Secret Approval Token
This token is your personal key that allows the send_confirmed_email tool to actually send. Choose any secret string you like.
# Windows PowerShell
$env:MCP_APPROVAL_TOKEN="your_secret_token_here"On Mac/Linux:
export MCP_APPROVAL_TOKEN="your_secret_token_here"
β οΈ You must set this every time you open a new terminal. To make it permanent, add it to your system environment variables.
Step 6 β Run the Server with MCP Inspector
The MCP Inspector is a browser-based tool that lets you test your server visually without needing to connect a full AI assistant.
npx -y @modelcontextprotocol/inspector .venv\Scripts\python server.pyOn Mac/Linux:
npx -y @modelcontextprotocol/inspector .venv/bin/python server.py
Then open your browser and go to:
http://localhost:5173Step 7 β Authenticate with Google (First Run Only)
When you run the server for the first time, a browser window will open automatically asking you to log in to Google.
Select your Google account
You may see a warning "Google hasn't verified this app" β click "Advanced" β "Go to [App Name] (unsafe)"
Click Allow on the permissions screen
The browser will show "Authentication successful" β you can close it
A token.json file is now saved locally. You will not need to log in again unless you delete this file.
π§ͺ Testing the Tools
Once the Inspector is open at http://localhost:5173, you'll see all 3 tools listed. Here's how to test each one:
Tool 1 β list_recent_emails
Click the tool β click Run (no parameters needed)
You'll see a list of your last 10 inbox emails with subject, sender, and date
Tool 2 β draft_reply
Fill in the parameters:
to: friend@example.com
subject: Hello from MCP!
body: This is a test draft created by my Gmail MCP server.Click Run
Open Gmail β go to Drafts β you'll see the email sitting there, unsent β
Tool 3 β send_confirmed_email
With a wrong token (to test the security gate):
to: friend@example.com
subject: Test
body: Hello!
approval_token: wrongtokenClick Run β you'll get
"status": "blocked"β The gate works.
With the correct token (to actually send):
to: friend@example.com
subject: Hello from MCP!
body: This email was sent by my Gmail MCP server!
approval_token: your_secret_token_hereClick Run β email is sent β
βοΈ Connect to Claude or Another AI Assistant
To connect this server to an AI assistant like Claude, add this block to your MCP configuration file:
{
"mcpServers": {
"gmail-mcp": {
"command": "C:\\path\\to\\gmail-mcp-server\\.venv\\Scripts\\python.exe",
"args": [
"C:\\path\\to\\gmail-mcp-server\\server.py"
],
"env": {
"MCP_APPROVAL_TOKEN": "your_secret_token_here"
}
}
}
}Replace C:\\path\\to\\gmail-mcp-server with the actual path to your project folder.
π Project Structure
gmail-mcp-server/
βββ server.py # Main MCP server β defines all 3 tools
βββ auth.py # Handles Google OAuth 2.0 login
βββ requirements.txt # Python dependencies
βββ credentials.json.template # Template showing the credentials.json format
βββ .gitignore # Excludes credentials.json and token.json from git
βββ LICENSE # MIT License
βββ README.md # This file
credentials.jsonandtoken.jsonare never committed β they contain your private Google credentials.
β Troubleshooting
Problem | Solution |
| Make sure you downloaded and renamed the file from Google Cloud Console and placed it in the project root |
| Run |
Browser doesn't open for Google login | Run |
| You forgot Step 5 β set the environment variable before starting the server |
Inspector shows no tools | Make sure you're running the command from inside the project folder with the venv activated |
π License
This project is licensed under the MIT License β see the LICENSE file for details.
This server cannot be deployed
Maintenance
Related MCP Connectors
Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organizβ¦
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflowβ¦
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
Email infrastructure for AI agents β send, receive, search, and reply to email over MCP.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables reading, sending, archiving, and managing Gmail emails and labels through Google OAuth authentication, acting as an OAuth proxy to the Gmail API.89 npm11MIT
- FlicenseNot gradedqualityNot gradedmaintenanceEnables interaction with Gmail through the Gmail API, allowing users to list, read, search emails, create and send drafts, and get email summaries through natural language commands with OAuth2 authentication.-
- AlicenseAqualityDmaintenanceEnables sending emails and creating drafts through the Gmail API with OAuth 2.0 authentication.28 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to send, read, list, and reply to emails via the Gmail API.Apache 2.0