Gmail MCP Server
A local MCP server that provides tool-level access to Gmail, allowing Claude to search, read, send, and manage emails using the Gmail API.
README
Gmail MCP Server
A local MCP server that gives Claude native, tool-level access to Gmail. Runs locally via stdio transport — all tokens and credentials stay on your machine.
Prerequisites
- Python 3.14+
- uv for dependency management
- A Google account with the Gmail API enabled
Quick Start
# Clone the repo
git clone https://github.com/stevesimpson418/gmail-mcp-server.git
cd gmail-mcp-server
# Install dependencies (creates .venv/ in the project directory)
uv sync
New to uv?
uv syncreadspyproject.toml, creates a.venv/virtualenv inside the project folder, and installs all dependencies into it. You don't need to activate it —uv run <command>handles that automatically.
Setting up Gmail
1. Create a Google Cloud project
Go to the Google Cloud Console and create a new project (or select an existing one).
2. Enable the Gmail API
Navigate to APIs & Services > Library, search for Gmail API, and click Enable.
3. Configure the OAuth consent screen
Before creating credentials, Google requires you to configure the OAuth consent screen. Go to APIs & Services > OAuth consent screen (or Google Auth Platform if prompted).
- Click Get Started (or Configure Consent Screen)
- Fill in the required fields:
- App name — a name for your own reference (e.g. "Gmail MCP Server")
- User support email — your email address
- Select an Audience:
- Internal — only available if you're in a Google Workspace organisation
- External — select this for personal Google accounts. The app starts in testing mode, which is fine for personal use — you just need to add yourself as a test user
- Contact information — your email (Google uses this to notify you of project changes)
- Click Save
About testing mode: External apps in testing mode are limited to users you explicitly add to the test user list. This is perfectly fine for a local MCP server — you only need your own account. Tokens for test users expire after 7 days, requiring re-consent. If this becomes inconvenient, you can publish the app (no verification needed for sensitive scopes used with fewer than 100 users in testing mode, but publishing removes the 7-day expiry).
4. Add test users
Go to APIs & Services > OAuth consent screen > Test users (or Audience in the new Google Auth Platform UI) and add your Google account email address.
5. Add OAuth scopes
Go to APIs & Services > OAuth consent screen > Scopes (or Data Access in the new UI) and add the following scope:
<!-- markdownlint-disable MD013 -->
| Scope | Why it's needed |
|---|---|
https://www.googleapis.com/auth/gmail.modify |
Read messages, modify labels (archive, star, mark read/unread, apply/remove labels), manage drafts, send emails, and move messages to trash. This is the minimum single scope that covers all server operations — narrower scopes like gmail.readonly or gmail.send don't cover label modification or trash. |
<!-- markdownlint-enable MD013 -->
This server does not request mail.google.com (full unrestricted access) — gmail.modify
is scoped to read/write operations and cannot permanently delete messages.
6. Create OAuth 2.0 credentials
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Application type: Desktop app
- Give it a name for your own reference (e.g. "Gmail MCP — My Laptop")
- Click Create, then Download JSON
- Save the file as
credentials/gmail_credentials.jsonin this project
Security note: The
credentials/directory is gitignored — your credentials and tokens will never be committed to the repository.
7. Run the OAuth consent flow
uv run gmail-mcp-auth
A browser window will open — sign in with the Google account you added as a test user and
grant the requested permissions. The token is saved to credentials/token.json and
auto-refreshes after this.
To use custom paths:
uv run gmail-mcp-auth --credentials /path/to/creds.json --token /path/to/token.json
Adding to Claude Desktop
Add the following to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS).
Tip: Run
uv run which pythonfrom the project directory to get the exact path forcommand.
{
"mcpServers": {
"gmail": {
"command": "/Users/you/gmail-mcp-server/.venv/bin/python",
"args": ["-m", "gmail_mcp.server"],
"env": {
"GMAIL_CREDENTIALS_PATH": "/Users/you/gmail-mcp-server/credentials/gmail_credentials.json",
"GMAIL_TOKEN_PATH": "/Users/you/gmail-mcp-server/credentials/token.json"
}
}
}
}
The env block tells the server where to find your credentials at runtime. No .env file is
needed — the config passes these values directly.
Restart Claude Desktop after saving. You should see all Gmail tools in the tools menu.
Adding to Claude Code CLI
Use the claude mcp add command to register the server. This works from any directory.
claude mcp add --scope user gmail-mcp-server \
--transport stdio \
--env GMAIL_CREDENTIALS_PATH=/path/to/gmail-mcp-server/credentials/gmail_credentials.json \
--env GMAIL_TOKEN_PATH=/path/to/gmail-mcp-server/credentials/token.json \
-- /path/to/gmail-mcp-server/.venv/bin/python -m gmail_mcp.server
Replace /path/to/gmail-mcp-server with the actual path where you cloned the repo.
Tip: Run
uv run which pythonfrom the project directory to get the exact.venv/bin/pythonpath for the command.
The --scope user flag saves to ~/.claude.json so the server is available across all projects.
Without it, the command defaults to local scope (tied to whatever directory you run it from).
To scope it to a single project instead, use --scope project which writes to .mcp.json in
the project root.
To verify the server is registered:
claude mcp list
Restart Claude Code after adding. The Gmail tools should appear in the /mcp menu.
Note: Claude Code CLI uses a different configuration from Claude Desktop. The
claude mcp addcommand is the recommended way to register MCP servers — do not add them to~/.claude/settings.jsonas that file is used for permissions and hooks only.
Updating
To pull the latest version and update dependencies:
cd /path/to/gmail-mcp-server
git pull
uv sync
Restart Claude Desktop or Claude Code CLI after updating.
If a new version changes OAuth scopes, you'll need to re-consent by running
uv run gmail-mcp-auth again.
Available Tools
| Tool | Description |
|---|---|
search_gmail(query, max_results?) |
Search messages using Gmail query syntax (e.g. is:unread in:inbox) |
read_gmail_message(message_id) |
Read a full message including body text |
read_gmail_thread(thread_id) |
Read all messages in a thread |
list_gmail_labels() |
List all labels (system and user-created) |
list_gmail_attachments(message_id) |
List attachments on a message |
read_gmail_attachment(message_id, attachment_id, filename, mime_type) |
Read attachment content inline |
archive_gmail_messages(message_ids) |
Archive messages (remove from inbox) |
bulk_archive_gmail(query) |
Search and archive all matching messages in one call |
apply_gmail_label(message_ids, label_name) |
Apply a label to messages |
remove_gmail_label(message_ids, label_name) |
Remove a label from messages |
create_gmail_label(name, text_color?, background_color?) |
Create a new label |
mark_gmail_read(message_ids) |
Mark messages as read |
mark_gmail_unread(message_ids) |
Mark messages as unread |
star_gmail_message(message_ids) |
Star messages |
mark_gmail_important(message_ids) |
Mark messages as important |
create_gmail_draft(to, subject, body, thread_id?, cc?) |
Create a draft email |
send_gmail(to, subject, body, cc?) |
Send an email directly |
send_gmail_draft(draft_id) |
Send a previously created draft |
trash_gmail_messages(message_ids) |
Move messages to trash (recoverable for 30 days) |
Usage Examples
Triage your inbox:
1. search_gmail(query="is:unread in:inbox") → see what's new
2. read_gmail_message(message_id="msg_123") → read the full message
3. archive_gmail_messages(message_ids=["msg_123"]) → archive after reading
Bulk cleanup:
bulk_archive_gmail(query="from:noreply@marketing.com in:inbox")
bulk_archive_gmail(query="is:unread in:inbox older_than:7d subject:newsletter")
Draft a reply:
create_gmail_draft(
to="alice@example.com",
subject="Re: Meeting",
body="Sounds good, see you then!",
thread_id="thread_abc"
)
Development
# Install dev dependencies
uv sync --dev
# Run tests
uv run pytest -v
# Run tests with coverage
uv run pytest --cov=gmail_mcp --cov-report=term-missing
# Lint
uv run ruff check src/ tests/
# Format
uv run ruff format src/ tests/
# Install git hooks
lefthook install
Local .env file
When running the server manually outside Claude Desktop/Code (e.g., for development or
debugging), you can create a .env file in the project root so the server picks up
credential paths without passing environment variables:
GMAIL_CREDENTIALS_PATH=credentials/gmail_credentials.json
GMAIL_TOKEN_PATH=credentials/token.json
This is only needed for local development. The Claude Desktop and Claude Code CLI configs
pass these values directly via the env block.
Packaging & Distribution
This server is currently distributed as source via git. To install:
git clone https://github.com/stevesimpson418/gmail-mcp-server.git
cd gmail-mcp-server
uv sync
This is the standard distribution model for local-stdio MCP servers today. The project is already configured for wheel builds via hatchling, so future distribution options include:
- PyPI — publish to PyPI, then install with
uv tool install gmail-mcp-serverorpip install gmail-mcp-server. Would require adding a publish workflow to CI. - uvx — once on PyPI,
uvx gmail-mcp-serverruns the server without cloning the repo. Claude Desktop/Code config would point to the uvx-managed binary instead of a local.venv.
Releases
This project uses release-please for automated versioning and releases. The version is determined by Conventional Commits:
fix:commits bump the patch version (e.g. 0.1.0 → 0.1.1)feat:commits bump the minor version (e.g. 0.1.1 → 0.2.0)BREAKING CHANGEin the commit footer bumps the major version
When commits land on main, release-please opens (or updates) a Release PR that:
- Bumps the version in
pyproject.toml - Updates
CHANGELOG.mdwith grouped entries
Merging the Release PR creates a git tag and GitHub Release automatically.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.