Gmail MCP Server
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., "@Gmail MCP Servershow me my unread 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
An MCP (Model Context Protocol) server that enables AI assistants to read unread emails from Gmail and create draft replies.
Quickstart
# Install dependencies
npm install
# Copy env template and add your Google OAuth2 credentials
cp .env.example .env
# Run the OAuth2 flow to get your refresh token
npm run auth
# Build and run
npm run build
npm startThen configure the MCP client to use the server. See Setup for detailed instructions.
Related MCP server: Gmail MCP Server
Features
get_unread_emails: Retrieves all unread emails with sender, subject, body/snippet, email ID, and thread ID
create_draft_reply: Creates a properly threaded draft reply to any email
get_space_picture_of_the_day: (Optional) Fetches NASA Astronomy Picture of the Day (APOD) and returns a ready-to-paste “Did you know? Space Edition!” section with clear credits/references. The AI should ask before including this.
Architecture
MCP Server (
src/index.ts): Handles MCP protocol communication, tool registration, and request routingGmail Service (
src/gmail.service.ts): Encapsulates all Gmail API interactions
Process Flow
Reading Unread Emails
Query Gmail: Uses Gmail API's
messages.listwith query"is:unread"to find all unread message IDsFetch Details: For each message ID, calls
messages.getwithformat: 'metadata'to get headers and snippetExtract Information: Parses headers to get
FromandSubject, usessnippetas the email bodyReturn Structured Data: Returns array of objects with
sender,subject,body,emailId, andthreadId
Creating Draft Replies
Fetch Original: Retrieves the original message using
messages.getwithformat: 'full'to get all headersExtract Threading Info: Gets
threadId,Message-ID,Subject, andFromheaders from originalBuild Reply Email: Constructs RFC 2822 formatted email with:
To: Original sender's email addressSubject: Original subject prefixed with "Re: " (if not already present)In-Reply-To: Original Message-ID headerReferences: Original Message-ID header (for threading)Body: The provided reply text
Encode: Base64url encodes the email (Gmail API requirement)
Create Draft: Calls
drafts.createwith the encoded email andthreadIdto maintain proper threading
Email Threading
Email threading is maintained through:
threadId: Links the draft to the original email thread
In-Reply-To header: Points to the original message's Message-ID
References header: Contains the original Message-ID for email client compatibility
This ensures the draft appears as a reply in Gmail and maintains the conversation thread.
Setup
Install Dependencies:
npm installConfigure Gmail API:
Copy
.env.exampleto.envFollow the instructions in
.env.exampleto set up OAuth2 credentialsFill in
GMAIL_CLIENT_IDandGMAIL_CLIENT_SECRETfrom Google Cloud ConsoleRun
npm run authto get your refresh token (one-time setup)The refresh token will be automatically saved to your
.envfile
Build:
npm run buildRun:
npm startOr for development with auto-reload:
npm run dev
Testing
Run tests with:
npm testWatch mode:
npm run test:watchClaude Code (CLI) (for Linux)
Add the MCP server to Claude Code settings at ~/.claude/settings.json:
{
"mcpServers": {
"gmail": {
"command": "node",
"args": [
"/absolute/path/to/fac_mcp/dist/index.js"
]
}
}
}Once configured, the Gmail tools will be available in Claude Code sessions.
Note: The server automatically loads credentials from .env file
The server exposes two tools:
get_unread_emails: No parameters, returns array of unread emailscreate_draft_reply: RequiresemailId(string) andreplyBody(string). Optionalformat: "html"to create an HTML draft.
Optional Space Extension (NASA APOD)
If enabled, the server also exposes:
get_space_picture_of_the_day: Optional paramsdate(YYYY-MM-DD) andmaxDaysBack(defaults to 10, max 30). If today’s APOD fails, it automatically tries previous days.
Opt-in flow:
The AI should ask: “Would you like to include a ‘Did you know? Space Edition!’ section with today’s NASA picture of the day?”
If you say yes, it calls
get_space_picture_of_the_dayand appendsspaceEditionBlock(plain) orspaceEditionBlockHtml(HTML) after the normal reply.If using
spaceEditionBlockHtml, callcreate_draft_replywithformat: "html"so Gmail renders the image.
Space Extension Configuration
Environment variables:
ENABLE_SPACE_PICTURE_OF_THE_DAY: Optional. Defaults totrue. Set tofalseto hide/disable the space tools entirely.NASA_API_KEY: Optional. Defaults toDEMO_KEY, which works with rate limiting. Get a free key fromhttps://api.nasa.gov/.
Screenshots
with the APOD extension:
draft extract:
Known Issues
Security Vulnerability
There is a known ReDoS (Regular Expression Denial of Service) vulnerability in @modelcontextprotocol/sdk (GHSA-8r9q-7v3j-jr4g / CVE-2026-0621). The project uses the latest version of the SDK (1.25.1).
Impact: This is a denial-of-service vulnerability only - it could potentially make the server slow or unresponsive if malicious input is processed, but it does not allow unauthorized access, data exfiltration, or privilege escalation. The risk is relatively low for this MCP server since it runs locally via stdio and doesn't expose a network interface.
This server cannot be installed
Maintenance
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
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/bescka/fac_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server