MCP Tools Reference: bigquery.googleapis.com

工具:execute_sql

在專案中執行 SQL 查詢並傳回結果。

這項工具僅適用於 SELECT 陳述式。不允許使用 INSERTUPDATEDELETE 陳述式和預存程序。如果查詢未包含 SELECT 陳述式,系統會傳回錯誤。如要瞭解如何建立查詢,請參閱 GoogleSQL 說明文件

如果查詢會叫用遠端函式Python UDFexecute_sql 工具也可能會產生副作用。

使用 execute_sql 工具執行的所有查詢都會有標籤,指出工具是來源。您可以使用這個標籤,透過標籤和值組合 goog-mcp-server: true 篩選查詢。

查詢費用會計入 project_id 欄位中指定的專案。

下列範例示範如何使用 curl 叫用 execute_sql MCP 工具。

Curl 要求
                  
curl --location 'https://bigquery.googleapis.com/mcp' \
--header 'content-type: application/json' \
--header 'accept: application/json, text/event-stream' \
--data '{
  "method": "tools/call",
  "params": {
    "name": "execute_sql",
    "arguments": {
      // provide these details according to the tool's MCP specification
    }
  },
  "jsonrpc": "2.0",
  "id": 1
}'
                

輸入結構定義

同步執行 BigQuery SQL 查詢,並在查詢於指定的逾時時間內完成時傳回查詢結果。

JSON 表示法
{
  "projectId": string,
  "query": string,
  "dryRun": boolean
}
欄位
projectId

string

這是必要旗標,用於查詢執行和帳單的專案。

query

string

這是必要旗標,要執行的查詢,格式為 GoogleSQL 查詢。

dryRun

boolean

(選用步驟) 如果設為 true,BigQuery 不會執行工作。如果查詢有效,BigQuery 會傳回工作統計資料,例如將處理多少位元組的資料。如果查詢無效,系統會傳回錯誤。預設值為 false。

輸出內容的結構定義

BigQuery SQL 查詢的回應。

JSON 表示法
{
  "schema": {
    object (TableSchema)
  },
  "rows": [
    {
      object
    }
  ],
  "jobComplete": boolean,
  "errors": [
    {
      object (ErrorProto)
    }
  ]
}
欄位
schema

object (TableSchema)

結果的架構。只有在查詢順利完成時才會顯示。

rows[]

object (Struct format)

結果數量在所允許回覆大小上限內的物件。如要取得其他資料列,可以呼叫 GetQueryResults 並指定上述傳回的 jobReference。

jobComplete

boolean

查詢工作是否已完成。如果有出現列或 totalRow,此屬性一律都會為 true。如果為 false,則不會出現 totalRow。

errors[]

object (ErrorProto)

僅供輸出。工作執行期間遇到的第一個錯誤或警告。最終訊息會顯示導致程序停止的錯誤數量。這裡的錯誤不一定代表工作已完成或失敗。如要進一步瞭解錯誤訊息,請參閱「錯誤訊息」。

JSON 表示法
{
  "fields": [
    {
      object (TableFieldSchema)
    }
  ],
  "foreignTypeInfo": {
    object (ForeignTypeInfo)
  }
}
欄位
fields[]

object (TableFieldSchema)

說明資料表中的欄位。

foreignTypeInfo

object (ForeignTypeInfo)

(選用步驟) 在欄位結構定義 (TableFieldSchema.foreign_type_definition) 中,指定外部資料類型定義的中繼資料。

JSON 表示法
{
  "name": string,
  "type": string,
  "mode": string,
  "fields": [
    {
      object (TableFieldSchema)
    }
  ],
  "description": string,
  "policyTags": {
    object (PolicyTagList)
  },
  "dataPolicies": [
    {
      object (DataPolicyOption)
    }
  ],
  "nameAlternative": [
    string
  ],
  "maxLength": string,
  "precision": string,
  "scale": string,
  "timestampPrecision": string,
  "roundingMode": enum (RoundingMode),
  "collation": string,
  "defaultValueExpression": string,
  "rangeElementType": {
    object (FieldElementType)
  },
  "foreignTypeDefinition": string
}
欄位
name

string

這是必要旗標,欄位名稱。名稱只能包含英文字母 (a-z、A-Z)、數字 (0-9) 或底線 (_),且開頭須為英文字母或底線,長度上限為 300 個半形字元。

type

string

這是必要旗標,欄位資料類型。可能的值包括:

  • STRING
  • BYTES
  • INTEGER (或 INT64)
  • FLOAT (或 FLOAT64)
  • BOOLEAN (或 BOOL)
  • TIMESTAMP
  • DATE
  • 時間
  • DATETIME
  • GEOGRAPHY
  • NUMERIC
  • BIGNUMERIC
  • JSON
  • RECORD (或 STRUCT)
  • RANGE

使用 RECORD/STRUCT 表示欄位包含巢狀結構定義。

mode

string

(選用步驟) 欄位模式。可能的值包括 NULLABLE、REQUIRED 和 REPEATED。預設值為 NULLABLE。

fields[]

object (TableFieldSchema)

(選用步驟) 如果 type 屬性設為 RECORD,則說明巢狀結構定義欄位。

description

string

(選用步驟) 欄位說明。長度上限為 1,024 個半形字元。

policyTags

object (PolicyTagList)

(選用步驟) 附加至這個欄位的政策標記,用於欄位層級的存取權控管。如未設定,預設為空白的 policy_tags。

dataPolicies[]

object (DataPolicyOption)

(選用步驟) 附加至這個欄位的資料政策,用於欄位層級的存取權控管。

nameAlternative[]

string

請勿使用這個欄位。

maxLength

string (int64 format)

(選用步驟) 這個欄位的值長度上限 (適用於 STRINGS 或 BYTES)。

如未指定 max_length,這個欄位就不會受到長度上限限制。

如果 type = "STRING",則 max_length 代表這個欄位中字串的 UTF-8 長度上限。

如果 type =「BYTES」,則 max_length 代表這個欄位的位元組數上限。

如果類型不是「STRING」和「BYTES」,則設定這個欄位無效。

precision

string (int64 format)

(選用步驟) NUMERIC 或 BIGNUMERIC 欄位值的精度 (以 10 為底的總位數上限) 和小數位數 (以 10 為底的小數部分位數上限) 限制。

如果類型 ≠「NUMERIC」且 ≠「BIGNUMERIC」,則設定精確度或比例無效。

如果未指定精確度和比例,只要值符合類型規定,這個欄位就不會受到任何值範圍限制。

當 NUMERIC 或 BIGNUMERIC 欄位的值符合下列條件時,必須介於這個範圍內:

  • 指定精確度 (P) 和比例 (S):[-10P-S + 10-S, 10P-S - 10-S]
  • 指定精確度 (P),但未指定比例 (因此比例會解讀為等於零):[-10P + 1, 10P - 1]。

如果同時指定有效位數和小數位數,可接受的值如下:

  • 如果 type =「NUMERIC」:1 ≤ precision - scale ≤ 29 且 0 ≤ scale ≤ 9。
  • 如果 type =「BIGNUMERIC」:1 ≤ precision - scale ≤ 38 且 0 ≤ scale ≤ 38。

如果只指定精確度,但未指定小數位數 (因此小數位數會解讀為零),則精確度可接受的值如下:

  • 如果 type =「NUMERIC」:1 ≤ precision ≤ 29。
  • 如果 type =「BIGNUMERIC」:1 ≤ precision ≤ 38。

如果指定了 scale,但未指定 precision,則無效。

scale

string (int64 format)

(選用步驟) 如要瞭解精確度,請參閱說明文件。

timestampPrecision

string (Int64Value format)

(選用步驟) TIMESTAMP 類型秒數的精確度 (以 10 為底的總位數上限)。

可能的值包括:* 6 (預設值,適用於微秒精確度的 TIMESTAMP 類型) * 12 (適用於皮秒精確度的 TIMESTAMP 類型)

roundingMode

enum (RoundingMode)

(選用步驟) 指定儲存 NUMERIC 和 BIGNUMERIC 類型的值時要使用的捨入模式。

collation

string

(選用步驟) 只有在欄位類型為 STRING 時,才能設定欄位對照。支援的值如下:

  • 「und:ci」:不確定的語言代碼,不區分大小寫。
  • '':空字串。預設為會區分大小寫。
defaultValueExpression

string

(選用步驟) 指定這個欄位預設值的 SQL 運算式。

rangeElementType

object (FieldElementType)

(選用步驟) 如果這個欄位的類型為 RANGE,則為 RANGE 的子類型。如果類型為 RANGE,則必須填寫這個欄位。欄位元素類型的值可以是下列項目:

  • DATE
  • DATETIME
  • TIMESTAMP
foreignTypeDefinition

string

(選用步驟) 外來資料類型的定義。僅適用於頂層架構欄位 (不適用於巢狀欄位)。如果類型為 FOREIGN,則必須填寫這個欄位。

JSON 表示法
{
  "value": string
}
欄位
value

string

字串值。

JSON 表示法
{
  "names": [
    string
  ]
}
欄位
names[]

string

政策標記資源名稱清單。例如「projects/1/locations/eu/taxonomies/2/policyTags/3」。目前最多只能有 1 個政策標記。

JSON 表示法
{

  // Union field _name can be only one of the following:
  "name": string
  // End of list of possible types for union field _name.
}
欄位

聯集欄位 _name

_name 只能是下列其中一個設定:

name

string

資料政策資源名稱,格式為 projects/project_id/locations/location_id/dataPolicies/data_policy_id。

JSON 表示法
{
  "value": string
}
欄位
value

string (int64 format)

int64 值。

JSON 表示法
{
  "type": string
}
欄位
type

string

這是必要旗標,欄位元素的類型。詳情請參閱 TableFieldSchema.type

JSON 表示法
{
  "typeSystem": enum (TypeSystem)
}
欄位
typeSystem

enum (TypeSystem)

這是必要旗標,指定定義外部資料類型的系統。

JSON 表示法
{
  "fields": {
    string: value,
    ...
  }
}
欄位
fields

map (key: string, value: value (Value format))

動態型別值的無序對應。

包含 "key": value 組合清單的物件,範例:{ "name": "wrench", "mass": "1.3kg", "count": "3" }

JSON 表示法
{
  "key": string,
  "value": value
}
欄位
key

string

value

value (Value format)

JSON 表示法
{

  // Union field kind can be only one of the following:
  "nullValue": null,
  "numberValue": number,
  "stringValue": string,
  "boolValue": boolean,
  "structValue": {
    object
  },
  "listValue": array
  // End of list of possible types for union field kind.
}
欄位
聯集欄位 kind。值的類型。kind 只能是下列其中一個設定:
nullValue

null

表示空值。

numberValue

number

代表雙精度浮點數值。

stringValue

string

表示字串值。

boolValue

boolean

表示布林值。

structValue

object (Struct format)

代表結構化值。

listValue

array (ListValue format)

代表重複的 Value

JSON 表示法
{
  "values": [
    value
  ]
}
欄位
values[]

value (Value format)

動態型別值的重複欄位。

JSON 表示法
{
  "value": boolean
}
欄位
value

boolean

布林值。

JSON 表示法
{
  "reason": string,
  "location": string,
  "debugInfo": string,
  "message": string
}
欄位
reason

string

簡短的錯誤代碼,可摘要說明錯誤。

location

string

指明發生錯誤的位置 (如果有的話)。

debugInfo

string

偵錯資訊。這個屬性是 Google 內部屬性,不應使用。

message

string

使用者容易理解的錯誤說明。

工具註解

破壞性提示:✅ | 等冪提示:❌ | 唯讀提示:❌ | 開放世界提示:✅