Gmail MCP Connector

Gmail MCP Connector

A Gmail MCP server running on Cloudflare Workers that enables reading, searching, labeling, drafting, sending, and managing Gmail messages, including fetching raw attachment bytes, with per-user OAuth authorization.

Category
访问服务器

README

Gmail MCP Connector

A full Gmail MCP connector running as a Cloudflare Worker. It reads, searches, labels, drafts, sends, and manages Gmail — including minting short-lived download URLs for attachments so the raw bytes can be fetched out-of-band without ever entering the model's context, a key capability this connector adds over generic Gmail integrations.

Authorization follows the MCP authorization spec (OAuth 2.1): each user who connects runs the OAuth handshake themselves, and the client holds the token — this connector is multi-user and does not use a shared account secret.

How auth works

This Worker plays two OAuth roles at once (via @cloudflare/workers-oauth-provider):

  • To the MCP client, it is the authorization server + resource server. It issues its own token to the client and validates that token on every /api/mcp request.
  • To Google, it is an OAuth client. It bridges the user to Google's consent screen and obtains a separate Google token.

Per the spec, the client's token is never passed through to Google. Each user's Google tokens are stored encrypted in KV (in the grant props) and used to call Gmail on their behalf. The client only ever holds the Worker's token.

MCP client ──token(A)──▶ Worker (RS/AS) ──token(B)──▶ Google/Gmail
           ◀─issues A──               ◀──issues B──
                           token A never forwarded to Google

Endpoints

Endpoint Purpose
POST /api/mcp MCP JSON-RPC endpoint (requires a valid access token)
GET /attachment?ticket=<id> Redeem a one-time attachment download ticket; streams the raw bytes (no auth header — the ticket is the credential)
GET /authorize Authorization UI — bridges the user to Google consent
GET /oauth/callback/google Google redirect target; completes the grant
POST /token, POST /register Token + dynamic client registration (library-served)
GET /.well-known/oauth-protected-resource RFC 9728 metadata (library-served)
GET /.well-known/oauth-authorization-server RFC 8414 metadata (library-served)

Setup

  1. Create a KV namespace for token storage and put its id in wrangler.toml:

    wrangler kv namespace create OAUTH_KV
    # paste the returned id into the [[kv_namespaces]] block in wrangler.toml
    
  2. Create a Google OAuth client (type: Web application) in the Google Cloud console, and enable the Gmail API. Add this authorized redirect URI:

    {your-worker-origin}/oauth/callback/google
    

    (e.g. https://gmail-mcp.your-subdomain.workers.dev/oauth/callback/google, or your custom domain.)

  3. Set the client secrets:

    wrangler secret put GOOGLE_CLIENT_ID
    wrangler secret put GOOGLE_CLIENT_SECRET
    

    No GOOGLE_REFRESH_TOKEN — tokens are now obtained per-user at connect time.

  4. (Optional) Set BASE_URL in wrangler.toml if you serve behind a custom domain. If left empty, the Worker derives redirect URIs from the incoming request origin.

  5. Deploy:

    wrangler deploy
    
  6. Connect a client. Add {your-worker-origin}/api/mcp as a custom MCP server. The client performs dynamic client registration + the OAuth flow automatically; you'll be sent to Google to sign in and consent on first connect.

Tools

search_threads, get_thread, get_message, get_attachment, send_email, reply_to_thread, create_draft, list_drafts, trash_message, list_labels, create_label, label_message, unlabel_message, label_thread, unlabel_thread.

Attachments

get_attachment does not return bytes — it returns a short-lived download URL:

{ "download_url": "https://<worker>/attachment?ticket=<id>", "method": "GET", "expires_in_seconds": 600 }

Do a plain HTTP GET on download_url to stream the raw bytes. No auth header is needed — the opaque, high-entropy ticket in the URL is the credential. The ticket is one-time use and expires after 10 minutes.

This keeps the attachment bytes out of the tool result (and therefore out of the model's context): the consuming agent fetches them out-of-band into its own runtime, so large attachments that would blow the MCP tool-result size cap are no longer a problem. Under the hood, minting the URL writes a ticket into OAUTH_KV carrying that grant's Google access token; the GET /attachment endpoint redeems it server-side, fetches the bytes from Gmail, and deletes the ticket. The Google access token never appears in a URL, a tool result, or logs.

If the ticket's copied access token has expired by download time (rare within the 10-minute window), the endpoint returns 401 — just call get_attachment again for a fresh URL.

Optionally pass file_name and mime_type (from get_message's attachment metadata) so the download response sets a correct Content-Type and Content-Disposition.

Development

pnpm install
./node_modules/.bin/tsc --noEmit   # typecheck
wrangler dev                       # local dev server

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选