@web4w3/gmail-mcp-server
v1.0.5
Published
MCP server for Gmail read/delete/mark operations over IMAP and POP3
Readme
Gmail MCP Server (IMAP + POP3)
This project provides an MCP server for Gmail with support for:
- Read emails
- Delete emails
- Mark emails as read/unread
- Protocol selection:
imaporpop3 - No send-email capability included
Features
MCP tools exposed by this server:
gmail_list_emailsgmail_get_emailgmail_delete_emailgmail_mark_emailgmail_list_folders(IMAP only)gmail_move_email(IMAP only)
Requirements
- Node.js 20+
- Gmail account with App Password enabled
- Enable 2FA on Gmail
- Create an App Password
Quick install (recommended)
npx -y @web4w3/gmail-mcp-serverNo cloning or build step needed. The package is pre-compiled and available on npm as @web4w3/gmail-mcp-server.
Setup (build from source)
- Install dependencies:
npm install- Configure environment variables:
cp .env.example .envFill values in .env.
Build and Run
npm run build
npm startFor development:
npm run devEnvironment Variables
GMAIL_USER: Gmail addressGMAIL_APP_PASSWORD: Google app passwordGMAIL_PROTOCOL: default protocol (imaporpop3, default:imap)GMAIL_MAILBOX: mailbox folder for IMAP (default:INBOX)GMAIL_HOST_IMAP: IMAP host (default:imap.gmail.com)GMAIL_PORT_IMAP: IMAP port (default:993)GMAIL_HOST_POP3: POP3 host (default:pop.gmail.com)GMAIL_PORT_POP3: POP3 port (default:995)POP3_MARKS_FILE: local file used to persist POP3 read/unread marksMCP_TRANSPORT:stdio(default) orhttpMCP_HTTP_PORT: port for HTTP mode (default:3101)MCP_HTTP_TOKEN: Bearer token required on every request in HTTP mode (required whenMCP_TRANSPORT=http)
Protocol Notes
- IMAP: Supports server-side read/unread flags, deletion, folder listing, and email moving. Folders are Gmail labels.
- POP3: Does not support folders or moving emails. Read/unread marks are stored locally in
POP3_MARKS_FILE. Deletions are performed on the maildrop viaDELEand committed atQUIT.
Note: gmail_list_folders and gmail_move_email only work with IMAP protocol. POP3 will return empty folder list and reject move operations.
MCP Client Example
Example MCP client config entry:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": ["-y", "@web4w3/gmail-mcp-server"],
"env": {
"GMAIL_USER": "[email protected]",
"GMAIL_APP_PASSWORD": "app_password"
}
}
}
}Remote (HTTP) mode
By default the server speaks MCP over stdio for a client on the same machine. To host it instead (for example on an always-on home server behind a tunnel):
MCP_TRANSPORT=http MCP_HTTP_PORT=3101 MCP_HTTP_TOKEN=<redacted> npm startThe server then listens for Streamable HTTP MCP requests on /mcp and
requires the token as Authorization: Bearer <token> on every request.
The endpoint is stateless; each request is independent. Keep it behind a
private tunnel or a TLS-terminating proxy — do not expose it to the open
internet without one.
curl -X POST http://localhost:3101/mcp \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'Integration with Email Analytics Agent
This server is designed to work with the Email Analytics Agent, which provides:
- Intelligent email grouping by sender domain
- Interactive folder assignment
- Rule learning for automatic email organization
Security
- Never commit
.envor app passwords. - Use Google App Passwords only.
- This server intentionally does not include any send-email action.
