mcp-gsuite

mcp-gsuite

Enables AI assistants to manage Gmail (list, search, send, label emails) and Google Calendar (list, create, update, delete events) via OAuth 2.0.

Category
访问服务器

README

mcp-gsuite

MCPize

A Model Context Protocol (MCP) server for interacting with Google Workspace — Gmail & Google Calendar — via a streamable HTTP transport. Built with TypeScript, Express, and the official Google APIs Node.js client.


Features

  • 📧 Gmail — list, search, send, and label emails
  • 📅 Google Calendar — list, create, update, and delete events
  • 🔐 OAuth 2.0 — offline access via refresh tokens (no re-auth needed)
  • ⚡ Stateful sessions — each MCP client gets its own isolated session
  • 🐳 Docker-ready — includes a production-grade Dockerfile
  • ☁️ Cloud Run compatible — graceful SIGTERM/SIGINT shutdown handling

Quick Start

npm install
npm run dev     # Start with hot reload (tsx watch)

Local development:

  • MCP endpoint: http://localhost:8080/mcp
  • Health check: http://localhost:8080/health

Remote (MCPize hosted):

  • MCP endpoint: https://mcp-gsuite.mcpize.run/mcp

Prerequisites

  1. A Google Cloud project with the following APIs enabled:
    • Gmail API
    • Google Calendar API
  2. OAuth 2.0 Web Application credentials — download as credentials.json from Google Cloud Console
  3. A refresh token for offline access (see below)

credentials.json format

{
  "web": {
    "client_id": "YOUR_CLIENT_ID.apps.googleusercontent.com",
    "client_secret": "YOUR_CLIENT_SECRET",
    "redirect_uris": [
      "https://your-deployed-url/mcp",
      "http://localhost:4100/mcp"
    ],
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token"
  }
}

Getting a Refresh Token

npm run generate    # Automated OAuth flow (recommended)
# or
node get-refresh-token.js

The script will open a browser for Google sign-in and save the token to .env automatically.


Environment Variables

Copy .env.example to .env and fill in:

cp .env.example .env
Variable Description Required
GOOGLE_CLIENT_ID OAuth client ID from Google Cloud Console ✅
GOOGLE_CLIENT_SECRET OAuth client secret ✅
GOOGLE_REFRESH_TOKEN Refresh token for offline access ✅
PORT Server port (default: 8080) ❌
NODE_ENV Set to production to disable dev logging ❌

Note: The server will throw an error on startup if any of the three required credentials are missing.


Development

npm install         # Install dependencies
npm run dev         # Development mode with hot reload (tsx watch)
npm run build       # Compile TypeScript to dist/
npm start           # Run compiled server (node dist/index.js)
npm test            # Run unit tests (vitest)
npm run test:smoke  # Run smoke/connectivity test

Project Structure

├── src/
│   └── index.ts                # MCP server — all tool handlers & Express setup
├── tests/
│   └── tools.test.ts           # Vitest unit tests
├── scripts/
│   ├── list-events.mjs         # Standalone calendar event listing script
│   └── smoke-test.js           # Basic connectivity smoke test
├── get-refresh-token.js        # Automated OAuth flow helper
├── credentials.json            # Google OAuth client credentials (not committed)
├── token.json                  # Cached OAuth tokens (auto-generated, not committed)
├── package.json                # Dependencies and npm scripts
├── tsconfig.json               # TypeScript compiler configuration
├── mcpize.yaml                 # MCPize deployment manifest
├── Dockerfile                  # Container build instructions
├── .env                        # Your local secrets (not committed)
└── .env.example                # Environment variables template

MCP Tools

📧 Gmail

Tool Description Key Parameters
list_emails List recent emails from Gmail inbox maxResults (1–500, default 10), query (Gmail filter)
search_emails Search emails with Gmail query syntax query (required), maxResults (1–500, default 10)
send_email Send an email (plain text + HTML) to, subject, body, cc?, bcc?
modify_email Add or remove Gmail labels on a message id, addLabels[], removeLabels[]

Gmail search query examples:

from:someone@example.com
subject:invoice
is:unread after:2024/01/01

📅 Google Calendar

Tool Description Key Parameters
list_events List upcoming calendar events maxResults (1–250, default 10), timeMin?, timeMax?
create_event Create a new calendar event summary, start, end, location?, description?, attendees[]?
update_event Update an existing calendar event (partial patch) eventId, any of: summary, location, description, start, end, attendees[]
delete_event Delete a calendar event eventId

All datetime values must be valid ISO 8601 strings (e.g., 2024-12-25T10:00:00Z).


Architecture

The server uses stateful Streamable HTTP sessions from the MCP SDK:

  • Each new MCP initialize request creates a fresh server + transport instance
  • Sessions are tracked in memory by mcp-session-id header
  • A single authenticated OAuth2 client is shared across Gmail and Calendar API calls within a session
  • Input validation is handled via Zod schemas on all tool inputs
Client → POST /mcp (initialize) → creates session
Client → POST /mcp (tool call, mcp-session-id: <id>) → reuses session

Testing

npm test                              # Run vitest unit tests
npx @anthropic-ai/mcp-inspector      # Interactive MCP tool testing UI
npm run test:smoke                    # Smoke test against running server

Connect MCP Inspector to http://localhost:8080/mcp to test tools interactively.


Deployment

MCPize (recommended)

mcpize deploy

Configured via mcpize.yaml:

  • Runtime: TypeScript
  • Build: npm ci && npm run build
  • Start: node dist/index.js (HTTP transport on $PORT)

Docker

docker build -t mcp-gsuite .
docker run -p 8080:8080 \
  -e GOOGLE_CLIENT_ID=... \
  -e GOOGLE_CLIENT_SECRET=... \
  -e GOOGLE_REFRESH_TOKEN=... \
  mcp-gsuite

Google Cloud Run

The server handles SIGTERM gracefully for zero-downtime Cloud Run deploys.


Tech Stack

Package Version Purpose
@modelcontextprotocol/sdk ^1.23.0 MCP server + Streamable HTTP transport
googleapis ^134.0.0 Gmail & Calendar API client
express ^5.1.0 HTTP server framework
zod ^4.0.0 Runtime input validation
dotenv ^16.4.5 Environment variable loading
chalk ^5.4.1 Colored terminal output
tsx ^4.19.4 TypeScript dev runner (hot reload)

Node.js requirement: >=20.0.0


License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选