MCP Tools Reference: bigquery.googleapis.com

工具:execute_sql_readonly

在專案中執行唯讀 SQL 查詢,並傳回結果。如無特殊情況,建議您使用這項工具,而非 execute_sql

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

使用 execute_sql_readonly 工具執行的查詢會自動設定工作標籤 goog-mcp-server: true。系統會向 project_id 欄位中指定的專案收取查詢費用。

以下範例示範如何使用 curl 叫用 execute_sql_readonly 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_readonly",
    "arguments": {
      // provide these details according to the tool's MCP specification
    }
  },
  "jsonrpc": "2.0",
  "id": 1
}'
                

輸入內容的結構定義

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

QueryRequest

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

string

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

query

string

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

dryRun

boolean

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

輸出內容的結構定義

BigQuery SQL 查詢的回應。

QueryResponse

JSON 表示法
{
  "schema": {
    object (TableSchema)
  },
  "rows": [
    {
      object
    }
  ],
  "jobComplete": boolean,
  "errors": [
    {
      object (ErrorProto)
    }
  ],
  "queryId": string,
  "totalBytesBilled": string,
  "totalSlotMs": string,
  "numDmlAffectedRows": string,
  "totalBytesProcessed": string
}
欄位
schema

object (TableSchema)

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

rows[]

object (Struct format)

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

jobComplete

boolean

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

errors[]

object (ErrorProto)

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

queryId

string

僅供輸出。查詢的 ID。

totalBytesBilled

string (Int64Value format)

僅供輸出。查詢的計費位元組總數。僅適用於設為採用以量計價方案的專案。

totalSlotMs

string (Int64Value format)

僅供輸出。使用者實際需要付費的時段毫秒數。

numDmlAffectedRows

string (Int64Value format)

僅供輸出。受 DML 陳述式影響的資料列數。

totalBytesProcessed

string (Int64Value format)

僅供輸出。這項查詢處理的位元組總數。

TableSchema

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

object (TableFieldSchema)

說明資料表中的欄位。

foreignTypeInfo

object (ForeignTypeInfo)

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

TableFieldSchema

JSON 表示法
{
  "name": string,
  "type": string,
  "mode": string,
  "fields": [
    {
      object (TableFieldSchema)
    }
  ],
  "description": string,
  "policyTags": {
    object (PolicyTagList)
  },
  "dataPolicies": [
    {
      object (DataPolicyOption)
    }
  ],
  "maxLength": string,
  "precision": string,
  "scale": string,
  "timestampPrecision": string,
  "roundingMode": enum (RoundingMode),
  "collation": string,
  "defaultValueExpression": string,
  "rangeElementType": {
    object (FieldElementType)
  },
  "foreignTypeDefinition": string,
  "generatedColumn": {
    object (GeneratedColumn)
  }
}
欄位
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)

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

maxLength

string (int64 format)

選用。這個欄位的值 (STRING 或 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 類型秒數的精確度 (以十進位表示的總位數上限)。

可能的值包括:* 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,則必須填寫這個欄位。

generatedColumn

object (GeneratedColumn)

選用。定義如何為欄位產生值。僅適用於頂層架構欄位 (不適用於巢狀欄位)。

StringValue

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

string

字串值。

PolicyTagList

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

string

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

DataPolicyOption

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。

Int64Value

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

string (int64 format)

int64 值。

FieldElementType

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

string

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

GeneratedColumn

JSON 表示法
{

  // Union field _generated_mode can be only one of the following:
  "generatedMode": enum (GeneratedMode)
  // End of list of possible types for union field _generated_mode.

  // Union field definition can be only one of the following:
  "generatedExpressionInfo": {
    object (GeneratedExpressionInfo)
  }
  // End of list of possible types for union field definition.
}
欄位

聯集欄位 _generated_mode

_generated_mode 只能是下列其中一項:

generatedMode

enum (GeneratedMode)

選用。決定何時使用系統產生的值填入欄位。

聯集欄位 definition

definition 只能是下列其中一項:

generatedExpressionInfo

object (GeneratedExpressionInfo)

用於產生欄位的運算式定義。

GeneratedExpressionInfo

JSON 表示法
{

  // Union field _generation_expression can be only one of the following:
  "generationExpression": string
  // End of list of possible types for union field _generation_expression.

  // Union field _asynchronous can be only one of the following:
  "asynchronous": boolean
  // End of list of possible types for union field _asynchronous.

  // Union field _stored can be only one of the following:
  "stored": boolean
  // End of list of possible types for union field _stored.
}
欄位

聯集欄位 _generation_expression

_generation_expression 只能是下列其中一項:

generationExpression

string

選用。用於生成欄位的生成運算式 (例如 AI.EMBED(...))。

聯集欄位 _asynchronous

_asynchronous 只能是下列其中一項:

asynchronous

boolean

選用。資料欄生成作業是否以非同步方式完成。

聯集欄位 _stored

_stored 只能是下列其中一項:

stored

boolean

選用。產生的資料欄是否儲存在表格中。

ForeignTypeInfo

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" }

FieldsEntry

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

代表 JSON null

numberValue

number

代表 JSON 數字。不得為 NaNInfinity-Infinity,因為 JSON 不支援這些字元。此外,由於 JSON 格式通常不支援數字類型中的大型 Int64 值,因此也無法表示這類值。

stringValue

string

代表 JSON 字串。

boolValue

boolean

代表 JSON 布林值 (JSON 中的 truefalse 常值)。

structValue

object (Struct format)

代表 JSON 物件。

listValue

array (ListValue format)

代表 JSON 陣列。

ListValue

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

value (Value format)

動態型別值的重複欄位。

BoolValue

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

boolean

布林值。

ErrorProto

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

string

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

location

string

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

debugInfo

string

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

message

string

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

工具註解

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