使用说明
谷歌MCP
用于Google服务的最小模型上下文协议服务器。跑过 stdio 并公开了Gmail、谷歌日历和YouTube的工具。
先决条件
- Node.js 20+
- 启用Gmail API、Google日历API和YouTube数据API v3的Google云项目
- OAuth 2.0客户端凭据(桌面应用程序类型)
OAuth设置
运行auth命令以生成刷新令牌。如果 GOOGLE_CLIENT_ID 和 GOOGLE_CLIENT_SECRET 已经在你的 .env,不需要标志:
npx google-mcp auth
否则,请明确地传递它们:
npx google-mcp auth --client-id=<your_client_id> --client-secret=<your_client_secret>
浏览器选项卡将打开,供您授予访问权限。批准后,谷歌会自动重定向回本地主机,无需粘贴代码。复制结果 GOOGLE_REFRESH_TOKEN 进入您的MCP客户端配置。
要求的范围:
gmail.readonly+gmail.modifycalendar.eventsyoutube.readonly
MCP客户端配置
{
"command": "npx",
"args": ["-y", "google-mcp"],
"env": {
"GOOGLE_CLIENT_ID": "...",
"GOOGLE_CLIENT_SECRET": "...",
"GOOGLE_REFRESH_TOKEN": "...",
"GOOGLE_PRIMARY_CALENDAR_ID": "primary",
"GOOGLE_CALENDAR_IDS": "primary,<custom-calendar-id@group.calendar.google.com>"
}
}
GOOGLE_PRIMARY_CALENDAR_ID 设置用于创建事件的日历。 GOOGLE_CALENDAR_IDS 是一个逗号分隔的日历ID列表,用于在获取事件时查询。要查找自定义日历的ID,请转到Google日历→ 设置→ 选择日历→ “集成日历”。
本地开发
克隆仓库并安装依赖项:
npm install
创建一个 .env 文件(参见 .env.example)使用您的凭据,然后:
# Run the MCP server
npm run dev
# Run the auth flow (reads GOOGLE_CLIENT_ID/SECRET from .env if set)
npm run auth
# Compile
npm run build
# Launch MCP Inspector
npm run inspect
调试
确保 .env 从以下位置填充 .env.example 首先,调试配置在启动时从那里读取env-var。
暴露的MCP工具
Gmail
| 工具 | 说明 |
|---|---|
get_emails |
从邮箱获取完整的电子邮件。输入: type (默认值 UNREAD), maxCount (1–50,默认值10) |
get_email_summaries |
获取批量操作的轻量级元数据。输入: type, maxCount (1–150,默认值25) |
mark_emails_as_read |
将电子邮件标记为已读。输入: emailIds |
archive_emails |
存档电子邮件。输入: emailIds |
trash_emails |
将电子邮件移至垃圾箱。输入: emailIds |
支持的邮箱类型: INBOX, UNREAD, SENT, PROMOTIONS, SOCIAL, UPDATES.
日历
| 工具 | 说明 |
|---|---|
get_calendar_events |
获取某个时间范围内所有已配置日历中的事件。输入: fromDate, toDate (ISO 8601) |
create_calendar_event |
创建新事件。输入: summary, start, end,可选 description, location, attendees |
油管
| 工具 | 说明 |
|---|---|
search_youtube_videos |
按查询搜索视频。输入: query, maxResults (1–50,默认值10), videoDuration (any / short <4分钟/ medium 4-20分钟/ long >20分钟,默认值 any) |
暴露的MCP提示
提示是可重用的工作流模板,可由MCP客户端调用。
| 提示 | 描述 |
|---|---|
daily-briefing |
每日简报,检查未读电子邮件和今天的日历事件,然后将电子邮件标记为已读 |
youtube-research |
交互式研究助理,在YouTube上搜索某个主题的视频,并展示精心策划的结果 |
项目结构
src/
index.ts MCP server entry point + CLI dispatcher
auth.ts OAuth auth subcommand
registry/
toolRegistry.ts Tool registration logic
promptRegistry.ts Prompt registration logic
prompts/ MCP prompt definitions
services/
gmail/ Gmail queries, actions, MCP tools
calendar/ Calendar queries, actions, MCP tools
youtube/ YouTube search, MCP tools
shared/auth.ts OAuth client factory
build/ Compiled output
