概述
安装
内容详情
替代品
什么是MCP服务器?
MCP服务器是一种通过Model Context Protocol (MCP)与AI模型(如Gemini)进行交互的工具。它允许AI模型调用外部服务和API,从而执行复杂任务。如何使用MCP服务器?
通过将Google Apps Script项目部署为Web App,并配置Gemini CLI连接到该服务器,用户可以轻松地让Gemini调用Google Workspace服务(如Gmail、Drive、Calendar等)。适用场景
适用于自动化日常任务,例如管理日历事件、发送邮件、处理文档和文件等。适合希望利用AI增强生产力的开发者和普通用户。主要功能
如何使用
使用案例
常见问题
相关资源
安装
{
"theme": "Default",
"selectedAuthType": "###",
"mcpServers": {
"gas_web_apps": {
"command": "npx",
"args": [
"mcp-remote",
"https://script.google.com/macros/s/###/exec?accessKey=sample"
],
"env": {}
}
}
}🚀 带有MCP服务器的Gemini CLI:借助Google Apps Script拓展可能性
带有MCP服务器的Gemini CLI证实,使用低代码平台Google Apps Script(GAS)构建的MCP服务器拥有巨大的潜力。如果你已经为GAS创建了代码片段,那么可以通过将它们用作MCP服务器,以新的方式重新激活和/或利用这些代码片段。Gemini CLI和其他MCP客户端将有助于实现这一目标。
🚀 快速开始
本部分详细介绍如何使用Google Apps Script部署MCP服务器,并配置Gemini CLI以使用该服务器。
准备MCP服务器
1. 创建Google Apps Script项目
首先,创建一个新的独立Google Apps Script项目。独立项目不绑定到特定的Google表格、文档或表单,非常适合创建通用的Web服务。你可以通过访问script.google.com来创建一个。参考
2. 安装库
为了简化MCP服务器的构建,我们将使用预先构建的Google Apps Script库。这些库封装了复杂的MCP处理逻辑,并提供了现成的工具,使主脚本保持简洁。
本示例使用两个Google Apps Script库:
- MCPApp:管理MCP服务器的生命周期和通信协议。
- ToolsForMCPServer:提供一套预先构建的工具,用于与Google Workspace服务(Gmail、Drive、Calendar等)进行交互。
库项目密钥和安装步骤
- 打开你刚刚创建的项目的脚本编辑器。
- 安装MCPApp:
- 安装指南
- 项目密钥:
1TlX_L9COAriBlAYvrMLiRFQ5WVf1n0jChB6zHamq2TNwuSbVlI5sBUzh - 标识符:
MCPApp - 仓库:https://github.com/tanaikech/MCPApp
- 安装ToolsForMCPServer:
- 安装指南
- 项目密钥:
1lnE7UL1jQgPDbTB9yjhiwZM0SaS9MObhzvWUWb_t8FisO6A3bLepvM2j - 标识符:
ToolsForMCPServer - 仓库:https://github.com/tanaikech/ToolsForMCPServer
3. 编写脚本
请将以下脚本复制并粘贴到脚本编辑器中(替换任何现有代码),然后保存项目。
这是使用此库的基本脚本:
const apiKey = "###"; // Gemini API的API密钥
/**
* 当MCP客户端访问Web应用时,此函数会自动运行。
*/
const doPost = e => main(e);
function main(eventObject) {
const m = ToolsForMCPServer;
m.apiKey = apiKey;
const object = { eventObject, items: m.getTools() };
return new MCPApp
.mcpApp({ accessKey: "sample" })
.setServices({ lock: LockService.getScriptLock() })
.server(object);
}
注意:
- 如果你打算使用以下工具,必须取消脚本中
apiKey行的注释,并提供有效的Gemini API密钥:- generate_roadmap_to_google_sheets:在Google表格中创建路线图。
- generate_description_on_google_drive:为Google Drive上的文件生成并设置描述。
- generate_image_on_google_drive:根据提示生成图像并保存到Google Drive。
- summarize_file_on_google_drive:总结存储在Google Drive上的文件。
- description_web_site:根据网站URL提供网站描述。
- 如果发生与Drive API相关的错误,请在高级Google服务中启用Drive API。
- 如果你想使用API的批量更新方法管理文档、表格和幻灯片,请在高级Google服务中启用Docs API、Sheets API和Slides API。
显示所有工具
运行此脚本时,库中的所有工具将以JSON对象的形式显示:
function showAlltools() {
const res = ToolsForMCPServer.getToolList();
console.log(res);
}
过滤工具
当你想使用特定工具时,也可以使用以下脚本。
此脚本仅使用get_exchange_rate工具:
function main(eventObject) {
const enables = ["get_exchange_rate"];
const m = ToolsForMCPServer;
m.apiKey = apiKey;
const object = { eventObject, items: m.getTools({ enables }) };
return new MCPApp
.mcpApp({ accessKey: "sample" })
.setServices({ lock: LockService.getScriptLock() })
.server(object);
}
此脚本使用除get_exchange_rate工具之外的所有工具:
function main(eventObject) {
const disables = ["get_exchange_rate"];
const m = ToolsForMCPServer;
m.apiKey = apiKey;
const object = { eventObject, items: m.getTools({ disables }) };
return new MCPApp
.mcpApp({ accessKey: "sample" })
.setServices({ lock: LockService.getScriptLock() })
.server(object);
}
4. 部署Web应用
为了让Gemini CLI能够与我们的脚本进行通信,我们必须将其部署为Web应用。这将创建一个唯一的URL,作为我们的MCP服务器端点。
你可以在官方文档中找到详细信息。
请按照以下步骤在脚本编辑器中部署Web应用:
- 在脚本编辑器的右上角,点击部署 -> 新建部署。
- 点击选择类型 -> Web应用。
- 在部署配置下的字段中输入Web应用的描述。
- 为**“以谁的身份执行”选择“我”**。这一点至关重要,因为它允许脚本以你的权限运行,以访问你的Google服务。
- 为**“谁可以访问”选择“任何人”**。这使得该URL可以从互联网上调用。访问由不可猜测的URL和脚本中定义的
accessKey控制。 - 点击部署。
- 授权必要的范围后,复制Web应用URL。它看起来类似于
https://script.google.com/macros/s/###/exec。这就是你的MCP服务器端点。
重要提示:当你修改Apps Script代码时,必须创建一个新的部署版本来发布更改。点击部署 > 管理部署,选择你的活动部署,点击铅笔图标,然后从版本下拉菜单中选择**“新版本”**。更多信息请点击这里
准备Gemini CLI
1. 安装Gemini CLI
按照官方文档在你的系统上安装Gemini CLI。参考
2. 修改settings.json
要将Gemini CLI连接到你的新Apps Script服务器,你需要编辑其设置文件。该文件通常位于macOS/Linux上的~/.gemini/settings.json或Windows上的%USERPROFILE%\.gemini\settings.json。
添加如下所示的mcpServers配置块:
{
"theme": "Default",
"selectedAuthType": "###",
"mcpServers": {
"gas_web_apps": {
"command": "npx",
"args": [
"mcp-remote",
"https://script.google.com/macros/s/###/exec?accessKey=sample"
],
"env": {}
}
}
}
"gas_web_apps":你的服务器的本地标识符。"command"和"args":这些告诉Gemini CLI如何调用mcp-remote工具,该工具处理与你的Web应用URL的通信。
如果你从未安装过mcp-remote,请进行安装。参考
3. 传输文件内容(2025年7月9日新增)
最近,我发布了一篇题为“使用带有Google Apps Script构建的MCP服务器的Gemini CLI处理文件内容”的报告。参考在这篇报告中,我得出结论,在后台使用Drive API在Gemini CLI和Google Drive之间传输文件内容比直接在提示中嵌入base64数据更有效。因此,为了便于这种有效的传输,我使用了ggsrun,一个CLI工具。
3.1. ggsrun设置指南
要使用此方法,你首先需要设置ggsrun。
- 下载
ggsrun:从ggsrun发布页面获取最新版本。主仓库在此链接。 - 创建Google Cloud项目:访问Google Cloud Platform资源管理器,点击创建项目。
- 启用Drive API:在你的新项目中,导航到API和服务 > 已启用的API和服务。搜索并启用Drive API。
- 创建凭据:导航到API和服务 > 凭据。
- 配置OAuth客户端ID:点击创建凭据,选择OAuth客户端ID,然后选择Web应用程序。
- 设置重定向URI:在“已授权的重定向URI”下,添加
http://localhost:8080。 - 创建并下载凭据:点击创建,然后下载JSON。重要提示:将下载的文件重命名为
client_secret.json,并将其放在你的工作目录中。 - 对
ggsrun进行身份验证:- 打开包含
client_secret.json的目录中的终端。 - 运行命令
ggsrun auth。 - 复制终端中显示的URL,粘贴到浏览器中,并授权请求的范围。
- 从浏览器的地址栏中复制授权码,并将其粘贴回终端。
- 打开包含
要验证设置是否成功,运行ggsrun di以显示你的Google Drive的信息。
3.2. 为ggsrun配置Gemini CLI
要使Gemini CLI能够使用ggsrun,请将以下工具定义添加到你的GEMINI.md文件中。该文件通常位于macOS/Linux上的~/.gemini/GEMINI.md或Windows上的%USERPROFILE%\.gemini\GEMINI.md。
# 使用ggsrun在本地PC和Google Drive之间传输文件内容
* GitHub仓库:[https://github.com/tanaikech/ggsrun](https://github.com/tanaikech/ggsrun)
* 要按文件名从Google Drive下载文件,请使用此命令:
```bash
ggsrun d -f [文件名]
- 要按文件ID从Google Drive下载文件,请使用此命令:
ggsrun d -i [文件ID] - 要将文件从本地PC上传到Google Drive的根目录,请使用此命令:
ggsrun u -f "[文件名1],[文件名2],,," - 要将文件从本地PC上传到Google Drive的特定目录,请使用此命令:
ggsrun u -p [文件夹ID] -f "[文件名1],[文件名2],,," - 要在Google Drive上搜索文件和文件夹,请使用此命令:
ggsrun sf -q "[Drive API v3的搜索查询([https://developers.google.com/workspace/drive/api/guides/search-shareddrives](https://developers.google.com/workspace/drive/api/guides/search-shareddrives))]" - 要在Google Drive上搜索文件和文件夹,请使用此命令:
ggsrun ls -s [文件名]
## ✨ 主要特性
- **强大的命令行界面**:Gemini CLI提供了一个强大的命令行界面,用于与Google的Gemini模型进行交互。
- **集成MCP协议**:通过利用模型上下文协议(MCP),CLI可以使用自定义工具进行扩展。
- **简化授权**:借助Google Apps Script的固有授权功能,可轻松让Gemini访问Gmail、Calendar、Drive、Docs、Sheets和Slides等Google Workspace服务。
- **丰富的工具库**:`ToolsForMCPServer`库提供了41个预构建的工具,涵盖了文件管理、日程安排、邮件处理、文档操作等多个方面。
## 📦 安装指南
### 安装MCP服务器
按照上述“准备MCP服务器”部分的步骤进行操作,包括创建Google Apps Script项目、安装库、编写脚本和部署Web应用。
### 安装Gemini CLI
按照官方文档在你的系统上安装Gemini CLI。[参考](https://github.com/google-gemini/gemini-cli)
### 配置Gemini CLI
按照上述“准备Gemini CLI”部分的步骤进行操作,包括修改`settings.json`文件和配置`ggsrun`。
## 💻 使用示例
### 基础用法
以下是一些使用Gemini CLI与Google Apps Script MCP服务器交互的示例:
#### 确认连接的MCP服务器
**提示**:
```text
> /mcp
当你的设置正确时,将返回以下结果: 答案:
ℹ 已配置的MCP服务器:
🟢 gas_web_apps - 就绪 (41个工具)
- get_exchange_rate
- get_current_weather
- get_specific_date_weather
- get_current_date_time
- search_schedule_on_Google_Calendar
- create_schedule_to_Google_Calendar
- get_values_from_google_docs
- put_values_into_google_docs
- get_google_doc_object_using_docs_api
- manage_google_docs_using_docs_api
- search_file_in_google_drive
- get_file_from_google_drive
- put_file_to_google_drive
- create_file_to_google_drive
- rename_files_on_google_drive
- move_files_on_google_drive
- convert_mimetype_of_file_on_google_drive
- change_permission_of_file_on_google_drive
- generate_survey_with_google_forms
- generate_quiz_with_google_forms
- get_massages_by_time_from_Gmail
- get_massages_by_search_from_Gmail
- get_attachment_files_from_Gmail
- add_label_to_Gmail
- auto_reply_draft_creation_Gmail
- auto_new_draft_creation_Gmail
- send_mails_Gmail
- remove_mails_Gmail
- get_values_from_google_sheets
- put_values_to_google_sheets
- search_values_from_google_sheets
- get_google_sheet_object_using_sheets_api
- manage_google_sheets_using_sheets_api
- generate_presentation_with_google_slides
- get_google_slides_object_using_slides_api
- manage_google_slides_using_slides_api
- generate_description_on_google_drive
- generate_image_on_google_drive
- summarize_file_on_google_drive
- generate_roadmap_to_google_sheets
- description_web_site
搜索Google Drive中的文件
提示:
从Google Drive中搜索文件名为“sample file”的文件。
答案:
✔ search_file_in_google_drive (gas_web_apps MCP服务器) {"query":"name = 'sample file'"}
✦ 我在Google Drive上找到了一个名为“sample file”的文件。这是一个Google表格,其链接如下:
https://docs.google.com/spreadsheets/d/###/edit?usp=drivesdk
显示Google日历中的日程安排
提示:
告诉我今天的日程安排。
答案:
✔ search_schedule_on_Google_Calendar (gas_web_apps MCP服务器) {"start":"2025-07-03","end":"2025-07-03"}
✦ 今天,2025年7月3日,你有两个活动:
- 下午12:00 - 下午1:00:“示例活动1”(午餐),地点在品川站。
- 晚上7:00 - 晚上8:00:“示例活动2”(晚餐),地点在大阪站。
显示今天的邮件
提示:
告诉我今天来自tanaike@hotmail.com的邮件。
答案:
✔ get_messages_by_search_from_Gmail (gas_web_apps MCP服务器) {"query":"from:tanaike@hotmail.com after:2025/07/03"}
✦ 以下是你今天来自tanaike@hotmail.com的邮件:
1. 发件人:Tanaike Kanshi <tanaike@hotmail.com>
主题:示例邮件2
正文:这是第2封示例邮件。
2. 发件人:Tanaike Kanshi <tanaike@hotmail.com>
主题:示例邮件1
正文:这是第1封示例邮件。
发送邮件
提示:
我收到了朋友Tanaike送的纪念品。创建一封邮件感谢他。Tanaike的邮箱地址是tanaike@hotmail.com。
答案:
✔ auto_new_draft_creation_Gmail (gas_web_apps MCP服务器) {"obj":[{"body":"Dear Tanaike,\n\nThank you so much for the wonder…
一封草稿邮件已成功创建。草稿ID为 "r-###"。
✔ send_mails_Gmail (gas_web_apps MCP服务器) {"draftIds":["r-###"]}
“感谢你的纪念品!”的消息已正确发送。
✦ 我已经向Tanaike发送了一封邮件,感谢他的纪念品。
以下邮件将自动发送到tanaike@hotmail.com:
Dear Tanaike,
Thank you so much for the wonderful souvenir! I really appreciate your
thoughtfulness.
Best regards,
Kanshi Tanaike
高级用法
检查天气并在Google日历中创建日程安排
提示:
检查明天下午12点品川站附近的天气状况,并将100美元兑换成日元。在这种情况下,我们是否可以在当天在检索到的地点外出享用1小时的午餐?最后,将其作为日程安排添加到Google日历中。
答案:
✔ GoogleSearch 正在网络上搜索:“品川站的纬度和经度”
“品川站的纬度和经度”的搜索结果已返回。
✔ get_current_date_time (gas_web_apps MCP服务器) {"timezone":"Asia/Tokyo"}
当前日期和时间是 "2025-07-03 11:04:42"。时区是 "Asia/Tokyo"。
✔ get_exchange_rate (gas_web_apps MCP服务器) {"currency_from":"USD","currency_to":"JPY"}
来自API的原始数据是 {"amount":1.0,"base":"USD","date":"2025-07-02","rates":{"JPY":144.15}}。详细结果如下。最新的从 "USD" 到 "JPY" 的汇率是 144.15。
✔ get_current_weather (gas_web_apps MCP服务器) {"date":"2025-07-04 12:00","longitude":139.73917,"latitude":35.62861,"timezo…
主要为晴天,部分多云,有阴天
✦ 明天下午12点品川站附近的天气预计主要为晴天,部分多云,有阴天。100美元的汇率是14415日元(1美元 = 144.15日元)。
考虑到天气状况,在户外吃午餐可能会很愉快,但也有可能会阴天。
✔ create_schedule_to_Google_Calendar (gas_web_apps MCP服务器) {"description":"在品川站吃午餐。天气:主要为晴天,部分多云,有阴天…
已创建一个活动,开始时间:2025-07-04 12:00:00,结束时间:2025-07-04 13:00:00,标题:品川站户外午餐,描述:在品川站吃午餐。天气:主要为晴天,部分多云,有阴天。汇率:1美元 = 144.15日元。
✦ 2025年7月4日明天下午12:00到下午1:00在品川站户外吃午餐的日程安排已添加到你的Google日历中。描述中包括了天气预报(主要为晴天,部分多云,有阴天)和汇率(1美元 = 144.15日元)。
以下活动将自动添加到Google日历中:
日期:2025年7月4日,下午12:00到下午1:00
标题:品川站户外午餐
描述:在品川站吃午餐。天气:主要为晴天,部分多云,有阴天。汇率:1美元 = 144.15日元。
📚 详细文档
工具列表
在当前阶段(2025年7月17日),ToolsForMCPServer为MCP服务器提供了以下41个工具:
| 工具名称 | 描述 |
|---|---|
get_exchange_rate(currency_date, currency_from, currency_to) |
获取给定日期两种货币之间的当前汇率。 |
get_current_weather(latitude, longitude, timezone) |
获取指定纬度、经度和时区的当前天气。 |
get_specific_date_weather(date, latitude, longitude, timezone) |
获取指定日期、纬度、经度和时区的天气。 |
get_current_date_time(timezone) |
返回给定时区的当前日期和时间。 |
search_schedule_on_Google_Calendar(end, start, search) |
在指定日期范围内搜索Google日历中的日程安排和活动,可选择使用搜索字符串。 |
create_schedule_to_Google_Calendar(description, endDatetime, startDatetime, title) |
在Google日历中创建一个活动(日程安排),包括标题、描述、开始和结束日期时间。 |
get_values_from_google_docs(documentId, documentUrl, markdown, tabId, tabIndex, tabName) |
从Google文档中检索文本内容,可选择以Markdown格式从特定标签中获取。 |
put_values_into_google_docs(documentId, documentUrl, index, tabId, tabIndex, tabName, text) |
在指定索引处或文档末尾将文本追加或插入到Google文档的特定标签中。 |
get_google_doc_object_using_docs_api(documentId) |
使用Docs API获取Google文档对象。 |
manage_google_docs_using_docs_api(documentId, requests) |
使用Docs API管理Google文档。 |
search_file_in_google_drive(query) |
使用搜索查询在Google Drive中搜索文件。 |
get_file_from_google_drive(filename) |
按文件名从Google Drive下载文件,返回base64编码的数据。 |
put_file_to_google_drive(base64Data, filename, mimeType) |
将base64编码的数据作为文件上传到Google Drive,指定文件名和MIME类型。 |
create_file_to_google_drive(filename, mimeType) |
在Google Drive上创建一个指定文件名和MIME类型的空文件。 |
rename_files_on_google_drive(fileList) |
使用文件ID和新名称重命名Google Drive上的文件。 |
move_files_on_google_drive(fileList) |
使用源和目标ID将文件和文件夹移动到Google Drive上的不同文件夹。 |
convert_mimetype_of_file_on_google_drive(dstMimeType, fileIds) |
转换Google Drive上文件的MIME类型。 |
change_permission_of_file_on_google_drive |
用于修改Google Drive上特定文件或文件夹对给定用户的访问权限。 |
generate_survey_with_google_forms(itemList, title) |
使用给定的标题和问题列表,使用Google Forms生成调查。 |
generate_quiz_with_google_forms(itemList, title) |
使用给定的标题和问题列表(包括正确答案),使用Google Forms生成测验。 |
get_massages_by_time_from_Gmail(after, excludedMessageIds) |
检索指定时间之后收到的Gmail邮件,可选择排除某些邮件ID。 |
get_massages_by_search_from_Gmail(query, excludedMessageIds) |
使用搜索查询检索Gmail邮件,可选择排除某些邮件ID。 |
get_attachment_files_from_Gmail(messageId) |
从Gmail邮件中检索附件文件,返回其Google Drive文件ID。 |
add_label_to_Gmail(obj) |
为指定的Gmail线程添加标签。 |
auto_reply_draft_creation_Gmail(obj) |
为指定的邮件在Gmail中自动创建草稿回复邮件,可选择添加附件。 |
auto_new_draft_creation_Gmail(obj) |
在Gmail中自动创建新的草稿邮件,指定收件人、标题、正文和可选附件。 |
send_mails_Gmail(draftIds) |
发送Gmail中先前创建的草稿邮件。 |
remove_mails_Gmail(messageIds) |
删除指定的Gmail邮件。 |
get_values_from_google_sheets(range, sheetId, sheetIndex, sheetName, spreadsheetId, spreadsheetUrl) |
从指定范围或工作表中检索Google表格中的值。 |
put_values_to_google_sheets(range, sheetId, sheetIndex, sheetName, spreadsheetId, spreadsheetUrl, values) |
将值放入Google表格的指定范围或工作表的最后一行。 |
search_values_from_google_sheets(spreadsheetId, spreadsheetUrl, searchText) |
使用正则表达式在Google表格中搜索所有单元格。 |
get_google_sheet_object_using_sheets_api(spreadsheetId) |
使用Sheets API获取Google表格对象。 |
manage_google_sheets_using_sheets_api(spreadsheetId, requests) |
使用Sheets API管理Google表格。 |
generate_presentation_with_google_slides(name, presentationTime, text, title) |
使用给定的标题、演讲者姓名、演讲时间和描述,使用Google Slides创建并生成演示文稿。 |
get_google_slides_object_using_slides_api(presentationId) |
使用Slides API获取Google幻灯片对象。 |
manage_google_slides_using_slides_api(presentationId, requests) |
使用Slides API管理Google幻灯片。 |
generate_description_on_google_drive(fileId) |
为Google Drive上的文件生成描述并设置。 |
generate_image_on_google_drive(prompt) |
根据提示生成图像并保存为Google Drive上的文件。 |
summarize_file_on_google_drive(fileId, prompt) |
根据给定的提示总结Google Drive上的文件。 |
generate_roadmap_to_google_sheets(description, exportPDF, goal, sheetId, sheetIndex, sheetName, spreadsheetId, spreadsheetUrl) |
在Google表格中生成路线图,可选择导出为PDF。 |
description_web_site(urls) |
根据网站URL描述网站。 |
自定义工具
你可以向MCP服务器添加自定义工具。请参考以下脚本:
/**
* 如果你想添加自定义工具,请使用以下脚本。
* 这是一个简单的示例。请根据你的情况修改以下脚本。
*/
function getCustomTools() {
const functions = {
params_: {
function_name1: {
description: "###",
parameters: {}
},
function_name2: {
description: "###",
parameters: {}
}
},
function_name1: (object) => { },
function_name2: (object) => { },
};
// 用于MCP
const itemsForMCP = [
{
"type": "initialize",
"value": {
"protocolVersion": "2024-11-05", // 或 "2025-03-26"
"capabilities": { "tools": { "listChanged": false } },
"serverInfo": { "name": "gas_web_apps", "version": "1.0.0" }
}
},
...Object.keys(functions.params_).map(f => (
{
"type": "tools/list",
"function": functions[f],
"value": {
name: f,
description: functions.params_[f].description,
inputSchema: functions.params_[f].parameters,
}
}))
];
// return itemsForMCP;
return itemsForMCP;
}
const apiKey = "###"; // Gemini API的API密钥
/**
* 当MCP客户端访问Web应用时,此函数会自动运行。
*/
const doPost = e => main(e);
function main(eventObject) {
const m = ToolsForMCPServer;
m.apiKey = apiKey;
const object = { eventObject, items: [...m.getTools(), ...getCustomTools()] };
return new MCPApp
.mcpApp({ accessKey: "sample" })
.setServices({ lock: LockService.getScriptLock() })
.server(object);
}
🔧 技术细节
模型上下文协议(MCP)
Gemini CLI通过模型上下文协议(MCP)与MCP服务器进行通信。MCP允许CLI使用自定义工具扩展其功能,从而实现与各种Google Workspace服务的交互。
Google Apps Script
MCP服务器是使用Google Apps Script构建的。Google Apps Script是一种基于JavaScript的编程语言,允许用户在Google Workspace环境中自动化任务和创建自定义应用程序。通过使用Google Apps Script,我们可以利用其固有的授权功能,轻松访问Gmail、Calendar、Drive、Docs、Sheets和Slides等Google服务。
库的使用
为了简化MCP服务器的构建,我们使用了两个Google Apps Script库:
- MCPApp:管理MCP服务器的生命周期和通信协议。
- ToolsForMCPServer:提供一套预先构建的工具,用于与Google Workspace服务进行交互。
错误处理和授权
在使用过程中,可能会遇到与Drive API、Docs API、Sheets API和Slides API相关的错误。如果发生此类错误,需要在高级Google服务中启用相应的API。此外,某些工具需要有效的Gemini API密钥才能正常工作,如generate_roadmap_to_google_sheets、generate_description_on_google_drive等。
📄 许可证
本项目采用MIT许可证。
作者
更新历史
- v1.0.0 (2025年7月3日)
- 初始版本发布。
- v1.0.1 (2025年7月9日)
getServer方法名称更改为getTools,但getServer仍然可以使用。- 添加了以下方法:
- 用于Gmail管理:
- get_attachment_files_from_Gmail
- 用于Google Drive管理:
- rename_files_on_google_drive
- move_files_on_google_drive
- convert_mimetype_of_file_on_google_drive
- 用于使用Gemini:
- generate_roadmap_to_google_sheets
- generate_description_on_google_drive
- generate_image_on_google_drive
- summarize_file_on_google_drive
- description_web_site
- 在README.md中添加了示例提示和答案。
- v1.0.2 (2025年7月10日)
- 添加了
change_permission_of_file_on_google_drive工具。通过此工具,当Gmail中包含Google文档文件时,可以通过授予文件权限来发送邮件。
- 添加了
- v1.0.3 (2025年7月11日)
- 更新了
get_current_weather工具。 - 添加了新工具
get_specific_date_weather。
- 更新了
- v1.0.4 (2025年7月11日)
- 更新了
getSheet_函数。
- 更新了
- v1.0.5 (2025年7月16日)
- 添加了新工具
search_values_from_google_sheets。
- 添加了新工具
- v1.0.6 (2025年7月17日)
- 添加了以下6个新工具:
- get_google_doc_object_using_docs_api
- manage_google_docs_using_docs_api
- get_google_sheet_object_using_sheets_api
- manage_google_sheets_using_sheets_api
- get_google_slides_object_using_slides_api
- manage_google_slides_using_slides_api
- v1.0.7 (2025年7月19日)
- 添加了
getToolList方法,用于检索库中当前的所有工具。 - 可以使用
enables或disables作为数组参数对getTools方法进行工具过滤。如果使用enables,则仅使用enables数组中指定的工具;如果使用disables,则使用除disables数组中指定的工具之外的所有工具;如果既不使用enables也不使用disables,则使用所有工具。
- 添加了
- v1.0.8 (2025年7月23日)
- 将Gemini CLI从v0.1.12更新到v0.1.13时出现问题。参考幸运的是,Google已经意识到这个问题,我正在等待解决方案。在此期间,我收到了相关邮件,因此为Gemini CLI v0.1.13更新了ToolsForMCPServer。详细更新如下:我确认在使用Gemini CLI v0.1.13测试时,ToolsForMCPServer v1.0.8中的所有工具都能正常工作。
- 从每个工具的架构中移除了
oneOf。 - 根据此报告,现在在MCP服务器端生成请求体。因此,在使用
manage_google_docs_using_docs_api、manage_google_sheets_using_sheets_api和manage_google_slides_using_slides_api工具时,请使用你的Gemini API密钥。
返回顶部
替代品









