Connect to Gmail for email operations via OAuth
MCP server for Gmail - list, send, delete, summarize emails and labels, with optional semantic search via RAG.
Maintainer of this project? Claim this page to edit the listing.
1.0.0Add to Favorites
Why it matters
Enable AI agents and applications to perform basic Gmail operations securely through OAuth 2.0 authentication, allowing automated email management and communication workflows.
Outcomes
What it gets done
Authenticate with Gmail accounts using OAuth 2.0 security
Read and retrieve email messages from Gmail
Send new email messages through Gmail
Manage Gmail inbox operations and organization
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-gmail | bash Overview
Gmail MCP Server
Gmail MCP Server exposes the Gmail API as MCP tools for listing, sending, deleting, and summarizing emails and managing labels, with optional RAG-based semantic search over indexed emails. Use it for conversational inbox management once Google Cloud OAuth is set up; semantic search additionally requires running a local Chroma DB instance.
What it does
Gmail MCP Server integrates with the Gmail API to let an AI assistant list, delete, summarize, and send emails and manage labels. It supports OAuth authentication against a Google Cloud project and an optional Retrieval-Augmented Generation (RAG) mode that embeds fetched emails into a local Chroma DB for semantic search.
In RAG mode, emails fetched through global-search-emails, summarize-top-k-emails, or get-unread-emails are automatically embedded (using Xenova) and indexed into Chroma DB, after which vector-search-emails can find semantically related emails using natural-language queries rather than exact keyword matches.
When to use - and when NOT to
Use this connector when you want an assistant to triage an inbox - summarizing top emails, searching by sender/subject/date/label, sending replies with attachments, or managing labels - directly from a chat interface.
Do not use it without completing the Google Cloud OAuth setup (creating a project, enabling the Gmail API, configuring an OAuth consent screen, and generating client credentials) since authentication is required before any tool works. Skip the RAG features entirely unless you also run a local Chroma DB instance - semantic search only covers emails already fetched through the other tools.
Inputs and outputs
Tools take structured parameters like recipient/subject/body for send-email, message or label IDs for delete operations, and search filters (subject, sender, recipient, date range, keyword, label) for global-search-emails. Outputs are Gmail profile data, lists of emails/labels, or confirmation of send/delete/create actions.
Capabilities
get-gmail-profile: get Gmail profile details for a userIdsend-email: send an email with optional HTML body and base64-encoded attachmentscreate-label/list-gmail-labels/delete-gmail-label: manage Gmail labelsdelete-email: delete an email by message IDsummarize-top-k-emails: summarize the top k inbox emailsget-unread-emails: fetch unread emails (default max 10)global-search-emails: search by subject, sender/recipient, date range, keyword, and labelvector-search-emails: semantic search over indexed emails using vector embeddings (requires RAG/Chroma DB)
How to install
Create a Google Cloud project, enable the Gmail API, configure an OAuth consent screen, and create an OAuth Client ID for a Web App. Download and rename the credentials to gcp-oauth-keys.json in the repo root, then:
npm install
npm run build
node dist/mcp.js auth
Configure the client (VS Code or Claude Desktop):
{
"mcpServers": {
"gmail-mcp-server": {
"type": "stdio",
"command": "node",
"args": ["<absolute path to dist/mcp.js>"],
"env": { "GMAIL_OAUTH_PATH": "<absolute path to gmail-server-credentials.json>", "ENABLE_RAG": "false" }
}
}
}
For semantic search, also run docker run -v ./chroma-data:/data -p 8000:8000 chromadb/chroma and set ENABLE_RAG=true.
Who it's for
Professionals who want an AI assistant to manage their Gmail inbox - reading, searching, summarizing, and sending email - conversationally.
Source README
Gmail MCP server
This MCP server integrates with Gmail APIs to list, delete, summarize, and send emails and labels.
Prerequisites
- Node.js & npm: Ensure you have Node.js (v18 or higher recommended) and npm installed. Download Node.js
- Docker (for RAG/Chroma DB): If you want to use RAG features, install Docker: Get Docker
Getting started
Setup Google cloud project
- Create a Google Cloud project
- Enable the Gmail API
- Configure an OAuth consent screen
- If have workspace account then make it private
- Otherwise set some test users (emails against which want to test) to test before app is verified.
- Create an OAuth Client ID for application type "Web App"
- Download the JSON file of your client's OAuth keys
- Rename the key file to
gcp-oauth-keys.jsonand place into the root of the repo.
Install dependencies
- Run
npm installfrom the root directory to install all required dependencies.
How to Run
- Build the project:
- Run
npm run buildfrom the root repo directory.
- Run
- Authenticate:
- Run
node dist/mcp.js auth - This will open an authentication flow in your system browser
- Note down the token generated is only valid for
1 hrso relogin if get any error likeError: No refresh token is set. - Credentials will be saved in the root of this repo with file name
gmail-server-credentials.json
- Run
MCP Server Configuration Examples
VS Code settings.json
To use this server in VS Code, add the following to your settings.json:
{
"mcpServers": {
"gmail-mcp-server": {
"type": "stdio",
"command": "node",
"args": ["<absolute path to dist/mcp.js>"],
"env": {
"GMAIL_OAUTH_PATH": "<absolute path to gmail-server-credentials.json>",
"ENABLE_RAG": "false" // mark as true if want to use rag
}
}
}
}
Claude Desktop claude_desktop_config.json
To use this server in Claude Desktop, add the following to your claude_desktop_config.json:
{
"mcpServers": {
"gmail-mcp-server": {
"type": "stdio",
"command": "node",
"args": ["<absolute path to dist/mcp.js>"],
"env": {
"GMAIL_OAUTH_PATH": "<absolute path to gmail-server-credentials.json>",
"ENABLE_RAG": "false" // mark as true if want to use rag
}
}
}
}
Replace the placeholders (<absolute path ...>) with the actual full paths on your system for clarity and reliability.
Environment Variables
GMAIL_OAUTH_PATH: Absolute path to your Gmail OAuth credentials JSON file (e.g.,gmail-server-credentials.json).ENABLE_RAG: Set totrueto enable Retrieval-Augmented Generation (RAG) features; otherwise, set tofalse.
Tools
get-gmail-profile: Get Gmail profile details based on userId
userId: The user Gmail ID (string, required)
send-email: Send an email to a given email address (supports attachments and HTML)
to: Recipient email address (string, required)subject: Email subject (string, required)body: Email body (string, required)isHtml: Send as HTML email (boolean, optional, default: false)attachments: Array of attachments (base64 encoded, optional)filename: Attachment filename (string, required)mimeType: MIME type (string, required)content: Base64 encoded content (string, required)
create-label: Create a new Gmail label
name: Label name (string, required)
delete-email: Delete an email by message ID
messageId: ID of the email message (string, required)
summarize-top-k-emails: Summarize the top k emails in the inbox
k: Number of top emails to summarize (number, required)
get-unread-emails: Get unread emails from the inbox
maxResults: Maximum number of unread emails to fetch (number, optional, default: 10)
global-search-emails: Search emails by subject, sender/recipient, time range, keyword, and label
subject: Subject to search for (string, optional)sender: Sender email address (string, optional)recipient: Recipient email address (string, optional)after: Start date (YYYY/MM/DD) (string, optional)before: End date (YYYY/MM/DD) (string, optional)keyword: Keyword in body/snippet (string, optional)label: Gmail label to filter by (string, optional)maxResults: Maximum results (number, optional, default: 10)
list-gmail-labels: List all Gmail labels for the authenticated user
- No parameters required
delete-gmail-label: Delete an gmail label by label ID
labelId: ID of the label (string, required)
vector-search-emails: Semantic search for emails using vector embeddings (RAG)
query: The search query (string, required)k: Number of top results to return (number, optional, default: 10)
Running with Retrieval-Augmented Generation (RAG)
To enable semantic search and RAG features:
Run Chroma DB locally
Start a local Chroma DB instance for embedding storage and retrieval. You can use Docker:
docker run -v ./chroma-data:/data -p 8000:8000 chromadb/chroma- This command mounts a local directory (
./chroma-data) to the container's/datadirectory, ensuring your Chroma DB data persists even if the container is stopped or removed. - If you do not use the
-voption, your data will be lost when the container is deleted.
- This command mounts a local directory (
Or follow the Chroma DB documentation for other setup options.
Reference:
Indexing emails for embeddings
- Whenever you use any of the following tools:
global-search-emailssummarize-top-k-emailsget-unread-emails
- The emails fetched will be automatically indexed and embedded into Chroma DB for future semantic search.
- Whenever you use any of the following tools:
Performing vector search
- Use the
vector-search-emailstool to semantically search your indexed emails using natural language queries.
- Use the
Note:
- Ensure Chroma DB is running before using RAG features.
- Only emails fetched through the above tools are indexed for semantic search.
- For best results, first fetch new emails to keep the index updated.
RAG Flow: Embedding, Indexing, and Searching Emails
Below is a simplified Mermaid flowchart for how RAG is used to embed, index, and search emails:
flowchart TD
User[User] --> LLM["LLM (calls MCP tools)"]
LLM --> Query["User submits semantic<br/>search query<br/><b>(Triggered from LLM)</b>"]
%% Query Flow
Query --> CheckIndexed{"Emails already<br/>indexed?"}
CheckIndexed -- No --> Fetch["Fetch emails<br/>from Gmail API"]
Fetch --> Embed["Generate embeddings<br/>using xenova"]
Embed --> Index["Index embeddings<br/>in Chroma DB"]
Index --> Searchable["Emails are now<br/>searchable semantically"]
Searchable --> QEmbed["Generate embedding<br/>for query"]
CheckIndexed -- Yes --> QEmbed
QEmbed --> QSearch["Query Chroma DB<br/>for similar emails"]
QSearch --> Result["Return matching emails"]
- LLM Role: The user interacts with the LLM, which interprets the query and calls the appropriate MCP server tools (such as semantic search or email fetch).
- Embedding: When emails are fetched, their content is converted into vector embeddings using Xenova.
- Indexing: These embeddings are stored in Chroma DB for fast retrieval.
- Semantic Search: When the LLM uses
vector-search-emails, the query is embedded and compared to indexed emails to find the most relevant matches.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.