工具:get_values
從試算表傳回一系列值。對應於 REST API 中的 spreadsheets.values.get:https://developers.google.com/workspace/sheets/api/reference/rest/v4/spreadsheets.values/get
下列範例示範如何使用 curl 叫用 get_values MCP 工具。
| Curl 要求 |
|---|
curl --location 'https://sheetsmcp.googleapis.com/mcp' \ --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "get_values", "arguments": { // provide these details according to the tool MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
輸入內容的結構定義
GetValuesRequest
| JSON 表示法 |
|---|
{ "spreadsheetId": string, "range": string } |
| 欄位 | |
|---|---|
spreadsheetId |
必填。要從中擷取資料的試算表 ID。 |
range |
必填。要從中擷取值的範圍的 A1 標示法或 R1C1 標示法。 |
輸出內容的結構定義
試算表範圍內的資料。https://developers.google.com/workspace/sheets/api/reference/rest/v4/spreadsheets.values
值範圍
| JSON 表示法 |
|---|
{ "range": string, "values": [ array ] } |
| 欄位 | |
|---|---|
range |
以 A1 標示法表示的值範圍。 |
values[] |
讀取的資料。這是陣列的陣列,外層陣列代表所有資料,每個內層陣列代表一列。內部陣列中的每個項目都對應一個儲存格。系統不會納入空白的結尾資料列和資料欄。 |
ListValue
| JSON 表示法 |
|---|
{ "values": [ value ] } |
| 欄位 | |
|---|---|
values[] |
動態型別值的重複欄位。 |
值
| JSON 表示法 |
|---|
{ "nullValue": null, "numberValue": number, "stringValue": string, "boolValue": boolean, "structValue": { object }, "listValue": array } |
| 欄位 | |
|---|---|
聯集欄位 kind。值的類型。kind 只能是下列其中一項: |
|
nullValue |
代表 JSON |
numberValue |
代表 JSON 數字。不得為 |
stringValue |
代表 JSON 字串。 |
boolValue |
代表 JSON 布林值 (JSON 中的 |
structValue |
代表 JSON 物件。 |
listValue |
代表 JSON 陣列。 |
結構
| JSON 表示法 |
|---|
{ "fields": { string: value, ... } } |
| 欄位 | |
|---|---|
fields |
動態型別值的無序對應。 這個物件中包含 |
FieldsEntry
| JSON 表示法 |
|---|
{ "key": string, "value": value } |
| 欄位 | |
|---|---|
key |
|
value |
|
NullValue
代表 JSON null。
NullValue 是哨兵,使用只有一個值的列舉,代表 Value 型別聯集的空值。
如果 NullValue 類型的欄位值不是 0,則視為無效。大多數 ProtoJSON 序列化程式都會發出 Value,並將 null_value 設為 JSON null (不論整數值為何),因此會來回傳輸至 0 值。
| 列舉 | |
|---|---|
NULL_VALUE |
空值。 |
工具註解
破壞性提示:❌ | 等冪提示:✅ | 唯讀提示:✅ | 開放世界提示:✅
授權範圍
需要下列其中一種 OAuth 範圍:
https://www.googleapis.com/auth/drive.readonlyhttps://www.googleapis.com/auth/spreadsheets.readonlyhttps://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/drive.filehttps://www.googleapis.com/auth/spreadsheets