iT邦幫忙

2025 iThome 鐵人賽

DAY 30
0
生成式 AI

MCP Server 全攻略:讓 AI 動態調用工具的工作流革命系列 第 30

[30] Mcp server google sheet 將 api 返回的資料寫入 google sheet

  • 分享至 

  • xImage
  •  

我們在上一篇有介紹如何設定 gcp 獲得 credentials 以便使用任何 google mcp server,
這一篇我們會用 json 的方式來驗證並使用 mcp-google-sheet

https://ithelp.ithome.com.tw/upload/images/20251014/20141182HExuDLC7kp.png

Note: 這個是社群開發的不是官方的!請斟酌使用~

安裝與設定

首先我們需要下載 uvx
macOS / Linux

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

或著用 pip 下載

pip install uv

接著設定環境變數, 指定 google oauth credentials json 的檔案路徑:
https://ithelp.ithome.com.tw/upload/images/20251014/20141182Lg3yUKin0h.png

以及指定 token 檔案生成的路徑位置,

接著執行 mcp server:

 uvx mcp-google-sheets@latest

就會跳轉到 oauth 驗證頁面:

https://ithelp.ithome.com.tw/upload/images/20251014/20141182O1qNe6oltY.png

看到

The authentication flow has completed. You may close this window.

就完成了

接著去 cursor 設定 mcp server:

{
  "mcpServers": {
    "google-sheets": {
      "command": "uvx",
      "args": ["mcp-google-sheets@latest"],
      "env": {
        "CREDENTIALS_PATH": "/full/path/to/your/credentials.json",
        "TOKEN_PATH": "/full/path/to/your/token.json"
      }
    }
  }
}

記得檔案路徑如果是 \ 需要多加上\跳脫字符:

 "TOKEN_PATH": "C:\\Users\\Alicia\\test-mcp-google-excel-token.json"

可以看到設定成功了:

https://ithelp.ithome.com.tw/upload/images/20251014/20141182RwG6Yh6zVd.png

實作, 將 api response 寫入 google sheet

prompt:

幫我打這支api @https://jsonplaceholder.typicode.com/todos , 接著把結果新增到 google sheet, 名稱為 todo, 並且計算已完成的數量

過程:
https://ithelp.ithome.com.tw/upload/images/20251014/20141182Ra5gCcJt7r.png

https://ithelp.ithome.com.tw/upload/images/20251014/20141182CniEoABs7B.png

結果:

https://ithelp.ithome.com.tw/upload/images/20251014/2014118264Kv4LuQSQ.png

https://ithelp.ithome.com.tw/upload/images/20251014/20141182aRiasuMCiA.png


上一篇
[29] Mcp server 使用 google 服務的前置作業
系列文
MCP Server 全攻略:讓 AI 動態調用工具的工作流革命30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言