概述
安裝
內容詳情
替代品
什麼是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拓展可能性
本項目藉助低代碼平臺Google Apps Script(GAS)構建的MCP服務器,結合Gemini CLI,為用戶提供了與Google的Gemini模型進行交互的強大命令行界面。通過利用模型上下文協議(MCP),CLI可以使用自定義工具進行擴展。本項目簡化了Google Workspace API(如Gmail、Drive、Calendar等)的授權流程,使Gemini能夠在Google生態系統內直接執行復雜的多步驟任務。
🚀 快速開始
準備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雲端硬盤上的文件生成並設置描述。generate_image_on_google_drive:根據提示生成圖像並保存到Google雲端硬盤。summarize_file_on_google_drive:總結存儲在Google雲端硬盤上的文件。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 配置塊。
- 將
https://script.google.com/macros/s/###/exec替換為你之前複製的Web應用URL。 - 確保
accessKey查詢參數與你在Google Apps Script中定義的accessKey匹配(本示例中為sample)。
{
"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雲端硬盤信息。
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 [filename]
- 按文件ID從Google Drive下載文件,使用此命令:
ggsrun d -i [fileId] - 將本地PC上的文件上傳到Google Drive的根目錄,使用此命令:
ggsrun u -f "[filename1],[filename2],,," - 將本地PC上的文件上傳到Google Drive的特定目錄,使用此命令:
ggsrun u -p [folderId] -f "[filename1],[filename2],,," - 在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 [filename]
## ✨ 主要特性
- **強大的命令行界面**:提供與Google的Gemini模型進行交互的強大命令行界面。
- **簡化授權流程**:藉助Google Apps Script的固有授權功能,簡化了Google Workspace API(如Gmail、Drive、Calendar等)的授權流程。
- **豐富的工具庫**:`ToolsForMCPServer` 庫提供了41個預構建的工具,可用於執行各種任務,如文件管理、日程安排、郵件處理等。
- **可擴展性**:可以輕鬆集成自定義工具,進一步擴展功能。
## 📦 安裝指南
### 安裝MCP服務器
按照上述“準備MCP服務器”的步驟進行操作。
### 安裝Gemini CLI
按照上述“準備Gemini CLI”的步驟進行操作。
## 💻 使用示例
### 確認連接的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中搜索文件
提示
Search for files with the filename of "sample file" from Google Drive.
答案
✔ search_file_in_google_drive (gas_web_apps MCP Server) {"query":"name = 'sample file'"}
✦ 我在Google Drive上找到了一個名為 "sample file" 的文件。這是一個Google表格,鏈接如下:
https://docs.google.com/spreadsheets/d/###/edit?usp=drivesdk
顯示Google日曆中的日程安排
提示
Tell me my today's schedule.
答案
✔ search_schedule_on_Google_Calendar (gas_web_apps MCP Server) {"start":"2025-07-03","end":"2025-07-03"}
✦ 今天,2025年7月3日,你有兩個活動:
- 下午12:00 - 下午1:00:"sample event 1"(午餐)在品川站。
- 晚上7:00 - 晚上8:00:"sample event 2"(晚餐)在大阪站。
顯示今天的電子郵件
提示
Tell me my today's emails from tanaike@hotmail.com.
答案
✔ get_messages_by_search_from_Gmail (gas_web_apps MCP Server) {"query":"from:tanaike@hotmail.com after:2025/07/03"}
✦ 以下是你今天收到的來自tanaike@hotmail.com的電子郵件:
1. 發件人:Tanaike Kanshi <tanaike@hotmail.com>
主題:sample mail 2
正文:這是第二封示例郵件。
2. 發件人:Tanaike Kanshi <tanaike@hotmail.com>
主題:sample mail 1
正文:這是第一封示例郵件。
發送電子郵件
提示
I received a souvenir from my friend Tanaike. Create an email to thank him for it. Tanaike's email address is tanaike@hotmail.com.
答案
✔ auto_new_draft_creation_Gmail (gas_web_apps MCP Server) {"obj":[{"body":"Dear Tanaike,\n\nThank you so much for the wonder…
一封草稿郵件已成功創建。草稿ID為 "r-###"。
✔ send_mails_Gmail (gas_web_apps MCP Server) {"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日曆中創建日程安排
此示例展示了涉及網絡搜索和多個MCP工具的複雜編排。此提示類似於 此參考 中的示例。
提示
Check tomorrow's weather conditions at 12 PM around Shinagawa Station and exchange 100 US Dollars for Japanese Yen. Under this condition, will we enjoy eating lunch outside for 1 hour at the retrieved location and that day? Finally, create it as a schedule in Google Calendar.
答案
✔ GoogleSearch Searching the web for: "latitude and longitude of Shinagawa Station"
搜索 "品川站的緯度和經度" 的結果已返回。
✔ get_current_date_time (gas_web_apps MCP Server) {"timezone":"Asia/Tokyo"}
當前日期和時間是 "2025-07-03 11:04:42"。時區是 "Asia/Tokyo"。
✔ get_exchange_rate (gas_web_apps MCP Server) {"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 Server) {"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 Server) {"description":"Lunch at Shinagawa Station. Weather: Mainly c…
一個活動已創建,開始時間: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日元。
向現有Google文檔(或表格)添加文本
提示
Append the following text to the document "sample document 20250703".
<Text>
sample text 1
sample text 2
sample text 3
sample text 4
sample text 5
</Text>
答案
✔ search_file_in_google_drive (gas_web_apps MCP Server) {"query":"sample document 20250703"}
"isError": true
✔ search_file_in_google_drive (gas_web_apps MCP Server) {"query":"name = 'sample document 20250703'"}
找到1個文件。
✔ put_values_into_google_docs (gas_web_apps MCP Server) {"text":"sample text 1\nsample text 2\nsample text 3\nsample text 4\…
文本已成功追加到Google文檔。
✦ 文本已成功追加到文檔 "sample document 20250703"。
創建新的Google文檔並添加文本
提示
Create a new Google Document and put the following text into the Google Document.
<Text>
sample text 1
sample text 2
sample text 3
sample text 4
sample text 5
</Text>
答案
✔ create_file_to_google_drive (gas_web_apps MCP Server) {"mimeType":"application/vnd.google-apps.document","filename":"New D…
已在根文件夾中創建一個文件。文件URL是 "https://docs.google.com/document/d/###/edit?usp=drivesdk"。
✔ put_values_into_google_docs (gas_web_apps MCP Server) {"documentId":"###","text":…
文本已成功追加到Google文檔。
✦ 我已經創建了一個名為 "New Document 2025-07-03" 的新Google文檔,並將指定的文本添加到其中。
生成演示文稿
此想法和支持腳本基於 "將Gemini與Google Apps Script集成以實現自動化Google幻燈片演示文稿" 參考。
提示
Please create a 3-minute presentation. The title will be "Cooking miso soup". My name is Tanaike. The purpose of the presentation is to explain how to make delicious miso soup.
答案
✔ generate_presentation_with_google_slides (gas_web_apps MCP Server) {"name":"Tanaike","text":"This presentation will guide …
演示文稿已成功創建。URL是 "https://docs.google.com/open?id=###"。
✦ 演示文稿 "Cooking misosoup" 已創建。你可以通過以下鏈接訪問:
https://docs.google.com/open?id=###
以下演示文稿將自動在Google幻燈片中生成。
使用Google表單生成調查並通過電子郵件發送URL
此想法和腳本改編自 "一種新穎的學習方法:將Gemini與Google Apps Script結合用於自動化問答" 參考。
提示
I want to conduct a survey about favorite Japanese foods. Your mission is as follows:
* Generate a survey using Google Forms.
* Send an email to tanaike@hotmail.com including the published URL of the Google Form.
* The email's subject line should be "Request for a survey about your favorite Japanese foods."
* Create the email's body from the subject.
答案
✔ generate_survey_with_google_forms (gas_web_apps MCP Server) {"title":"Favorite Japanese Foods Survey","itemList":[{"requir…
調查已成功作為Google表單生成。表單的編輯URL和發佈URL分別是 "https://docs.google.com/forms/d/###/edit" 和 "https://docs.google.com/forms/d/e/#####/viewform"。
✔ auto_new_draft_creation_Gmail (gas_web_apps MCP Server) {"obj":[{"body":"Request for a survey about your favorite Japanese…
一封草稿郵件已成功創建。草稿ID是 "r###"。
✔ send_mails_Gmail (gas_web_apps MCP Server) {"draftIds":["r###"]}
"Request for a survey about your favorite Japanese foods." 的消息已正確發送。
✦ 我已經成功生成了調查,並將Google表單的發佈URL通過電子郵件發送給了tanaike@hotmail.com。
以下調查將自動在Google表單中生成。
以下電子郵件將發送到 tanaike@hotmail.com:
郵件標題:
Request for a survey about your favorite Japanese foods.
郵件正文:
Request for a survey about your favorite Japanese foods.
以下是調查鏈接:https://docs.google.com/forms/d/e/#####/viewform
使用Google表單生成測驗
此想法和腳本也改編自 "一種新穎的學習方法:將Gemini與Google Apps Script結合用於自動化問答" 參考。
提示
Suggest 5 questions and answers for a quiz with multiple-choice questions for learning Google Apps Script for beginners. Generate the quiz in Google Forms using the questions. The number of choices for each question is 5. The title of the quiz is "Learning Google Apps Script".
答案
✔ generate_quiz_with_google_forms (gas_web_apps MCP Server) {"title":"Learning Google Apps Script","itemList":[{"required":t…
測驗已成功作為Google表單生成。表單的編輯URL和發佈URL分別是 "https://docs.google.com/forms/d/###/edit" 和 "https://docs.google.com/forms/d/e/#####/viewform"。
✦ 測驗 "Learning Google Apps Script" 已在Google表單中生成。
* 編輯URL:https://docs.google.com/forms/d/###/edit
* 發佈URL:https://docs.google.com/forms/d/e/#####/viewform
以下測驗將自動在Google表單中生成。
從Google Drive下載圖像
此示例使用 ggsrun CLI工具從Google Drive下載圖像文件。
提示
Download the file "sample.png" from Google Drive using ggsrun.
答案
✔ Shell ggsrun d -f sample.png (Download "sample.png" from Google Drive.)
{"id":"###","name":"sample.png",,,
✦ 文件 "sample.png" 已下載。
從網站下載圖像文件並上傳到Google Drive
此示例使用shell命令從網站下載圖像文件,並使用 ggsrun CLI工具將其上傳到Google Drive。
提示
The image at `https://www.gstatic.com/marketing-cms/assets/images/7e/a4/253561a944f4a8f5e6dec4f5f26f/gemini.webp=s96-fcrop64=1,00000000ffffffff-rw` is the Gemini icon from the official brand resource center. [Ref](https://about.google/brand-resource-center/logos-list/)
Download an image from the URL "https://www.gstatic.com/marketing-cms/assets/images/7e/a4/253561a944f4a8f5e6dec4f5f26f/gemini.webp=s96-fcrop64=1,00000000ffffffff-rw" and upload it to Google Drive using ggsrun.
答案
✔ Shell wget -O /home/adsam/temp/workspace/gemini.webp "https://www.gstatic.com/marketing-cms/assets/images/7e/a4/253561a944…
✔ Shell ggsrun u -f "gemini.webp" (Upload the downloaded image to Google Drive using ggsrun.)
Error: Extension of '.webp' cannot be uploaded.
✔ Shell convert /home/adsam/temp/workspace/gemini.webp /home/adsam/temp/workspace/gemini.png (Convert the downloaded .webp image...)
✔ Shell ggsrun u -f "gemini.png" (Upload the converted .png image to Google Drive using ggsrun.)
{"upload_file_name":["gemini.png"],"uploaded_files":[{"id":"###","name":"gemini.png","mimeType":"image/png",,,
✦ 圖像已成功從URL下載,轉換為PNG格式,並上傳到Google Drive。
上傳文件到Google Drive並重命名
此示例使用 ggsrun CLI工具將文件上傳到Google Drive,並使用MCP服務器的 rename_files_on_google_drive 工具重命名文件。
提示
Upload the file "sample.png" to Google Drive using ggsrun with the filename "test.png". And, show the file ID of the uploaded file.
答案
✔ Shell ggsrun u -f "sample.png:test.png" (Attempt to upload "sample.png" to Google Drive as "test.png"...)
Error: open sample.png:test.png: no such file or directory.
✔ Shell ggsrun u -f "sample.png" (Upload "sample.png" to Google Drive.)
{"upload_file_name":["sample.png"],"uploaded_files":[{"id":"###","name":"sample.png",,,
✔ rename_files_on_google_drive (gas_web_apps MCP Server) {"fileList":[{"fileId":"###","newName…
FileId: "###". Renamed successfully from "sample.png" to "test.png".
✦ 文件 "sample.png" 已上傳到Google Drive並重命名為 "test.png"。上傳文件的文件ID是 ###。
上傳文件到Google Drive並作為電子郵件附件發送
提示
Upload the file "sample.png" using ggsrun, create a draft email with the uploaded file as an attachment, and send the email to "tanaike@hotmail.com".
答案
✔ Shell ggsrun u -f "sample.png" (Uploads "sample.png" to Google Drive.)
{"upload_file_name":["sample.png"],"uploaded_files":[{"id":"###","name":"sample.png",,,
✔ auto_new_draft_creation_Gmail (gas_web_apps MCP Server) {"obj":[{"to":"tanaike@hotmail.com","attachmentFiles":["###…
A draft email was successfully created. The draft ID is "r###".
✔ send_mails_Gmail (gas_web_apps MCP Server) {"draftIds":["r###"]}
Message of "Uploaded File: sample.png" was correctly sent.
✦ 我已經上傳了文件 "sample.png",創建了一封包含上傳文件作為附件的草稿電子郵件,並將電子郵件發送到了 "tanaike@hotmail.com"。
在Google Drive中移動文件
提示
Move the file "sample.png" to the folder "temp_folder" on Google Drive.
答案
✔ search_file_in_google_drive (gas_web_apps MCP Server) {"query":"name = 'sample.png'"}
找到1個文件。
找到的文件列表在 "FileList" JSON數組中返回。
✔ search_file_in_google_drive (gas_web_apps MCP Server) {"query":"name = 'temp_folder' and mimeType = 'application/vnd.googl…
找到1個文件。
找到的文件列表在 "FileList" JSON數組中返回。
✔ move_files_on_google_drive (gas_web_apps MCP Server) {"fileList":[{"dstId":"###","srcId":"1j…
File "sample.png" was moved to the folder "temp_folder".
✦ 我已經將文件 "sample.png" 移動到了Google Drive上的 "temp_folder" 文件夾中。
上傳PDF文件到Google Drive並添加描述
示例PDF文件是 PhysRev.48.73.pdf。此文件來自 此頁面。
提示
Upload the PDF file PhysRev.48.73.pdf to Google Drive using ggsrun and set the description for the file.
答案
✔ Shell ggsrun u -f "PhysRev.48.73.pdf" (Uploads the PDF file "PhysRev.48.73.pdf" to Google Drive.)
{"upload_file_name":["PhysRev.48.73.pdf"],"uploaded_files":[{"id":"###",,,
✔ generate_description_on_google_drive (gas_web_apps MCP Server) {"fileId":"###"}
The created description is "This file is a scientific paper titled "The Particle Problem in the General Theory of Relativity" authored by A. Einstein and N. Rosen, published in Physical Review, Volume 48, pages 73-77, on July 1, 1935...
✦ PDF文件 "PhysRev.48.73.pdf" 已上傳到Google Drive,並設置了描述。
生成圖像
提示
Generate an image of orange juice being poured into a glass, and download it.
答案
✔ generate_image_on_google_drive (gas_web_apps MCP Server) {"prompt":"orange juice is poured into a glass"}
An image was successfully generated from a prompt "orange juice is poured into a glass" as a file on Google Drive. The file URL and ID are "https://drive.google.com/file/d/###/view?usp=drivesdk" and "###", respectively.
✔ Shell ggsrun d -i ### -o "orange juice is poured into a glass" (Downloads the generated image...)
{"id":"###","name":"orange juice is poured into a glass",,,,
✦ 圖像 "orange juice is poured into a glass" 已生成並下載到你的當前目錄。
以下圖像已生成並下載。
描述網站
提示
Describe the website "https://tanaikech.github.io/about/".
答案
✔ description_web_site (gas_web_apps MCP Server) {"urls":["https://tanaikech.github.io/about/"]}
The website "About · tanaike" belongs to a Japanese scientist with a Ph.D. in Physics, who is also a Google Developer Expert (GDE) in Google Workspace and a Google Cloud Champion Innovator. The individual focuses on creating novel solutions, with some inventions finding practical applications in various industries such as electronics, industrial machinery, architecture, and aerospace. The site provides contact information, including a developer profile, and links to their posts on the Google Cloud Blog, Medium, and Zenn. It also lists their activities on platforms like GitHub, Gists, Qiita, Stack Overflow, and X, showcasing applications, tips, and summaries of Google Apps Script related repositories. The site also includes information about donations via PayPal.Me.
✦ 網站 "About · tanaike" 描述了一位擁有物理學博士學位的日本科學家,他也是Google Workspace的Google開發者專家(GDE)和Google Cloud創新冠軍。該科學家專注於創造新穎的解決方案,一些發明在電子、工業機械、建築和航空航天等各個行業找到了實際應用。該網站提供了聯繫信息,包括開發者簡介,以及他們在Google Cloud博客、Medium和Zenn上的文章鏈接。它還列出了他們在GitHub、Gists、Qiita、Stack Overflow和X等平臺上的活動,展示了與Google Apps Script相關的存儲庫的應用、提示和總結。該網站還包括通過PayPal.Me進行捐贈的信息。
描述本地PC上的PDF文件
提示
Upload the PDF file PhysRev.48.73.pdf to Google Drive using ggsrun and return a summary of the PDF file within 100 words.
答案
✔ Shell ggsrun u -f "PhysRev.48.73.pdf" (Uploads the PDF file to Google Drive.)
{"upload_file_name":["PhysRev.48.73.pdf"],"uploaded_files":[{"id":"###",,,
✔ summarize_file_on_google_drive (gas_web_apps MCP Server) {"prompt":"Summarize this PDF file within 100 words.","fileId":"1…
Einstein and Rosen investigate the particle problem in general relativity, aiming to describe elementary particles without singularities. They propose a slight modification to the gravitational equations, allowing for regular solutions. In this framework, particles are represented as "bridges" connecting two identical "sheets" of space. This approach provides a singularity-free description for neutral and charged particles. The most natural charged particle in this model is found to have zero gravitational mass. The theory offers a unified, consistent view using only gravitational and electromagnetic fields, explaining the atomistic nature of matter and the absence of negative neutral mass.
✦ PDF文件 "PhysRev.48.73.pdf" 已上傳到Google Drive,並總結如下:
"Einstein and Rosen研究廣義相對論中的粒子問題,旨在描述沒有奇點的基本粒子。他們對引力方程進行了輕微修改,以允許規則解。在這個框架中,粒子被表示為連接兩個相同“空間片”的“橋樑”。這種方法為中性和帶電粒子提供了無奇點的描述。該模型中最自然的帶電粒子被發現具有零引力質量。該理論僅使用引力和電磁場提供了統一、一致的觀點,解釋了物質的原子性質和負中性質量的不存在。"
生成路線圖並作為PDF文件下載
提示
I want to cook miso soup. To achieve this goal, create a new Google Spreadsheet, generate a roadmap for cooking miso soup in the spreadsheet, and download it as a PDF file using ggsrun.
答案
✔ create_file_to_google_drive (gas_web_apps MCP Server) {"filename":"Miso Soup Roadmap","mimeType":"application/vnd.google-a…
A file was created on the root folder. The file URL is "https://docs.google.com/spreadsheets/d/###/edit?usp=drivesdk".
✔ generate_roadmap_to_google_sheets (gas_web_apps MCP Server) {"spreadsheetId":"###…
Roadmap was successfully generated in Google Sheets. The spreadsheet ID and the sheet name are "###" and "Sheet1" (sheet ID: "0"), respectively. The URL is "https://docs.google.com/spreadsheets/d/###/edit". The file ID of the converted PDF file is "###".
✦ I can run ggsrun d -i ###. This will download the PDF file of the miso soup roadmap from Google Drive to your local machine.
✔ Shell ggsrun d -i ### (Download the generated PDF roadmap from Google Drive.)
✦ 我已經成功創建了Google表格,生成了味噌湯烹飪路線圖,並將其作為名為 "Cook Miso Soup.pdf" 的PDF文件下載。
結果,生成了以下路線圖並保存為PDF文件:
基於網站生成演示文稿並作為電子郵件發送
提示
Describe the Web site of "https://blog.google/technology/developers/introducing-gemini-cli-open-source-ai-agent/", and think of a title and create a new Google Document and put the generated description into the document by giving the title. And, generate a presentation of Google Slides using the title and document. And, create an email including the URL of the presentation and send it to "tanaike@hotmail.com".
答案
✔ description_web_site (gas_web_apps MCP Server) {"urls":["https://blog.google/technology/developers/introducing-gemini-cli-…
The site describes the introduction of Gemini CLI, an open-source AI agent that integrates Gemini directly into
developers' terminals. This tool offers free access to Gemini 2.5 Pro for individual Google account holders,
with high usage limits for model requests. Gemini CLI aims to enhance the command-line experience by enabling
coding, problem-solving, content generation, and task management using natural language. It shares technology
with Gemini Code Assist, providing AI assistance in both the terminal and VS Code. The article highlights
Gemini CLI's open and extensible nature, encouraging community contributions.
✔ create_file_to_google_drive (gas_web_apps MCP Server) {"mimeType":"application/vnd.google-apps.document","filename":"Intro…
A file was created on the root folder. The file URL is "https://docs.google.com/document/d/###/edit?usp=drivesdk".
✔ put_values_into_google_docs (gas_web_apps MCP Server) {"text":"The site describes the introduction of Gemini CLI, an open-…
Text is appended successfully to Google Docs.
✔ generate_presentation_with_google_slides (gas_web_apps MCP Server) {"name":"Kanshi Tanaike","title":"Introducing Gemini CL…
Presentation was successfully created. The url is "https://docs.google.com/open?id=###".
✔ auto_new_draft_creation_Gmail (gas_web_apps MCP Server) {"obj":[{"body":"Here is the presentation on Introducing Gemini CL…
A draft email was successfully created. The draft ID is "r-###".
✔ send_mails_Gmail (gas_web_apps MCP Server) {"draftIds":["r-###"]}
Message of "Presentation: Introducing Gemini CLI: An Open-Source AI Agent" was correctly sent.
✦ 我已經成功描述了網站,創建了包含描述和標題的Google文檔,生成了Google幻燈片演示文稿,並將包含演示文稿URL的電子郵件發送到了 "tanaike@hotmail.com"。
以下電子郵件已發送。
郵件主題:Presentation: Introducing Gemini CLI: An Open-Source AI Agent
郵件正文:Here is the presentation on Introducing Gemini CLI: An Open-Source AI Agent: https://docs.google.com/open?id=###
打開URL時,將生成以下演示文稿。
基於網站生成演示文稿並作為電子郵件發送(2025年7月10日新增)
提示
Create a new Google Document and send an email to tanaike@hotmail.com that includes the document. Grant the user edit permission for the Google Document.
答案
✔ create_file_to_google_drive (gas_web_apps MCP Server) {"filename":"New Google Document","mimeType":"application/vnd.google…
A file was created on the root folder. The file URL is "https://docs.google.com/document/d/###/edit?usp=drivesdk".
✔ change_permission_of_file_on_google_drive (gas_web_apps MCP Server) {"role":"editor","fileId":"###…
Permission for the file 'New Google Document' (ID: ###) was successfully updated. User 'tanaike@hotmail.com' has been granted 'editor' access.
✔ auto_new_draft_creation_Gmail (gas_web_apps MCP Server) {"obj":[{"title":"New Google Document","to":"tanaike@hotmail.com",…
A draft email was successfully created. The draft ID is "r###".
✔ send_mails_Gmail (gas_web_apps MCP Server) {"draftIds":["r###"]}
Message of "New Google Document" was correctly sent.
✦ 我已經創建了一個新的Google文檔,授予tanaike@hotmail.com編輯權限,並將包含該文檔鏈接的電子郵件發送給了他們。
運行此命令時,將發送一封包含Google文檔URL的電子郵件,併為該電子郵件添加寫入權限。
📚 詳細文檔
上述示例展示了將Gemini CLI與使用Google Apps Script Web應用構建的MCP服務器相結合,如何在Google Workspace中實現強大的自動化功能。通過利用Google Apps Script的固有授權功能,我們可以輕鬆地讓Gemini訪問Gmail、日曆、雲端硬盤、文檔、表格和幻燈片。
提供的示例僅代表了可能實現的功能的一小部分。ToolsForMCPServer 庫包含許多從以前開發的Google Apps Script實用程序派生的函數。此外,由於MCP服務器只是一個Google Apps Script項目,開發人員可以輕鬆地將自己現有的GAS代碼片段作為新工具集成到Gemini CLI中。隨著MCP服務器不斷添加更多工具,在Google生態系統中實現複雜的、由AI驅動的自動化的潛力幾乎是無限的。
🔧 技術細節
添加自定義工具
如果你想向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);
}
📄 許可證
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_drivemove_files_on_google_driveconvert_mimetype_of_file_on_google_drive
- 用於使用Gemini:
generate_roadmap_to_google_sheetsgenerate_description_on_google_drivegenerate_image_on_google_drivesummarize_file_on_google_drivedescription_web_site
- 在README.md中添加了示例提示和答案。
- v1.0.2 (2025年7月10日)
- 添加了
change_permission_of_file_on_google_drive工具。通過此工具,當Gmail中包含Google文檔文件時,可以通過授予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_apimanage_google_docs_using_docs_apiget_google_sheet_object_using_sheets_apimanage_google_sheets_using_sheets_apiget_google_slides_object_using_slides_apimanage_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密鑰。
返回頂部
替代品









