mcp-gmail
Allows reading, sending, deleting, and managing Gmail messages and labels via the Gmail API.
Click on "Install 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., "@mcp-gmailshow me unread emails from last week"
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.
mcp-gmail
An MCP (Model Context Protocol) server that connects Claude with Gmail through the Google Gmail API.
Quick Start
Install dependencies:
npm install.Set up Google Cloud credentials — see Google Cloud Console Setup.
Configure environment — copy
.env.exampleto.env.developmentand add your Google OAuth credentials.Build:
npm run build.Configure Claude Desktop with
dist/mcp-server/index.jsand yourGMAIL_CLIENT_ID/GMAIL_CLIENT_SECRET(see Configuration).Start the auth server:
npm run dev:auth(separate process; handles OAuth onlocalhost:3334).Authenticate — use the
authenticatetool in Claude, follow the URL, sign in. Tokens are saved to~/.mcp-gmail-tokens.json.
Installation
Prerequisites
Node.js 22.0.0 or higher
npm
A Google account for Cloud Console access
Install Dependencies
npm installGoogle Cloud Console Setup
1. Create a project
Open the Google Cloud Console.
Click the project dropdown at the top → New Project.
Name it (e.g.
mcp-gmail) → Create.Make sure the new project is selected in the dropdown.
2. Enable the Gmail API
Go to APIs & Services → Library.
Search for Gmail API → click it → Enable.
3. Configure the OAuth consent screen
For a brand-new project, Google now gates this behind a one-time "Google Auth Platform" wizard. If you see "Google Auth Platform not configured yet" with a Get Started button, follow 3a. Otherwise jump to 3b.
3a. First-time setup (Get Started wizard)
Go to APIs & Services → OAuth consent screen → click Get Started.
App Information: App name (e.g.
MCP Gmail), user support email (your Gmail address) → Next.Audience: select External → Next.
Contact Information: developer contact email (your Gmail address) → Next.
Finish: agree to the Google API Services User Data Policy → Continue → Create.
3b. Publish the app
Go to APIs & Services → OAuth consent screen → Audience (or the "Audience" tab on the new Google Auth Platform page).
Under Publishing status, click Publish App → Confirm.
This avoids the 7-day refresh-token expiry that applies to apps left in testing mode.
Your app stays "unverified" — that's fine for personal use; you'll see a one-time "advanced → continue" warning during sign-in.
3c. Configure data access (scopes)
This step is mandatory and easy to miss. If a scope isn't pre-declared here, Google silently drops it from the consent screen and the resulting tokens only carry the scopes Google adds by default (openid, userinfo.email). Any Gmail API call would then return 403 — the auth flow appears to succeed but the token can't read mail.
Go to APIs & Services → OAuth consent screen → Data Access (or the "Data Access" tab on the new Google Auth Platform page) → Add or remove scopes.
In the filter, search for Gmail API and tick the scopes you want. The default this server requests is:
https://www.googleapis.com/auth/gmail.modify— read, send, delete, and manage messages and labels (restricted scope).
If you override
GMAIL_SCOPES, add every scope you intend to request here as well.Click Update → Save.
gmail.modifyis a Google "restricted" scope. For personal use on an unverified app this is fine (you'll see an "advanced → continue" warning during sign-in and a cap of ~100 test users). Google only requires CASA verification if you ever publish the app to a wider audience.
After changing scopes here, delete ~/.mcp-gmail-tokens.json and re-run the authenticate tool so the consent screen prompts again with the new scope set.
4. Create OAuth credentials
Go to APIs & Services → Credentials.
Click Create Credentials → OAuth 2.0 Client ID.
Application type: Web application.
Name: anything (e.g.
mcp-gmail).Under Authorized redirect URIs, add:
http://localhost:3334/auth/callback(must matchGMAIL_REDIRECT_URI— see Configuration)
Click Create.
Copy the Client ID and Client Secret from the confirmation dialog — you'll put them in
.env.developmentasGMAIL_CLIENT_IDandGMAIL_CLIENT_SECRET. There's nocredentials.jsonto download; the secret lives in env vars, never on disk in the repo.
Configuration
Environment Variables
Name | Required | Default | Purpose |
| yes | — | Google Cloud OAuth 2.0 Client ID (looks like |
| yes | — | OAuth 2.0 Client Secret from the same credential. |
| no |
| OAuth redirect URI. Must match the value registered in Google Cloud Console. |
| no |
| Space-separated OAuth scopes requested for the access token. |
| no |
| Port the auth server listens on. Must match the port in |
| no | — | Dev convention. |
Notes:
If you change
GMAIL_AUTH_PORT, updateGMAIL_REDIRECT_URI(and the registered redirect URI in Google Cloud Console) to match.Use
GMAIL_CLIENT_IDandGMAIL_CLIENT_SECRETconsistently across.env.developmentand the Claude Desktop config.
Claude Desktop Configuration
Run npm run build first so dist/mcp-server/index.js exists, then add to your Claude Desktop config:
{
"mcpServers": {
"mcp-gmail": {
"command": "node",
"args": ["/path/to/mcp-gmail/dist/mcp-server/index.js"],
"env": {
"GMAIL_CLIENT_ID": "your-client-id",
"GMAIL_CLIENT_SECRET": "your-client-secret"
}
}
}
}A starter is in claude-config-sample.json.
Running From Source (Dev)
cp .env.example .env.development
# edit .env.development with your Google OAuth credentials, then:
npm run dev:mcp # MCP server
npm run dev:auth # OAuth server on :3334The dev:mcp, dev:auth and inspect npm scripts run with NODE_ENV=development, and src/config.ts calls process.loadEnvFile('./.env.${NODE_ENV}') at startup — so it picks up .env.development from the CWD automatically. Claude Desktop does not set NODE_ENV, so the file is ignored in production; env vars must come from the Claude Desktop config env block.
Authentication
The OAuth flow runs out-of-band via the standalone auth server:
Start the auth server:
npm run dev:auth(listens onhttp://localhost:3334).In Claude, call the
authenticatetool — it returns a sign-in URL.Open the URL, sign in with the Google account you want to access, and grant the requested scopes.
Tokens (including a refresh token) are saved to
~/.mcp-gmail-tokens.json.The MCP server reads that file and refreshes tokens transparently when they expire.
To force re-authentication (or if the refresh token is revoked), delete ~/.mcp-gmail-tokens.json and re-run the authenticate tool.
Scope troubleshooting. If Gmail API calls return 403 after a successful sign-in, inspect the scope field in ~/.mcp-gmail-tokens.json — Google only grants scopes that are pre-declared on the OAuth consent screen → Data Access tab (see step 3c). If gmail.modify is missing from scope, add it to Data Access, delete the token file, and re-authenticate.
Security Model
Secrets (
GMAIL_CLIENT_SECRET) come from env vars only; never committed..env*files are gitignored except.env*.exampletemplates.OAuth tokens live in
~/.mcp-gmail-tokens.json(mode 0600 when written). The MCP server reads, refreshes, and rewrites this file but never logs token values.The auth server binds to
localhost:3334only and accepts a single OAuth callback at a time; pending CSRF state entries expire after 10 minutes.If the token file is lost, revoked, or you want to switch Google accounts, delete
~/.mcp-gmail-tokens.jsonand re-authenticate.
Development
npm run dev:mcp # tsx watch mode, MCP server (NODE_ENV=development)
npm run dev:auth # tsx watch mode, OAuth server (NODE_ENV=development)
npm run start:mcp # build then run MCP server from dist/
npm run start:auth # build then run auth server from dist/
npm run inspect # MCP Inspector against TS source (NODE_ENV=development)
npm test # vitest
npm run typecheck # tsc --noEmit
npm run lint:check # Biome lint + format check
npm run lint:fix # Biome auto-fix (uses --unsafe)
npm run lint:md # prettier + markdownlint for *.mdMaintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/knowledgeislands/mcp-gmail'
If you have feedback or need assistance with the MCP directory API, please join our Discord server