Tool: execute_sql_readonly
Run a read-only SQL query in the project and return the result. Prefer this tool over execute_sql if possible.
This tool is restricted to only SELECT statements. INSERT, UPDATE, and DELETE statements and stored procedures aren't allowed. If the query doesn't include a SELECT statement, an error is returned. For information on creating queries, see the GoogleSQL documentation.
Example Queries:
-- Count the number of penguins in each island.
SELECT island, COUNT(*) AS population
FROM bigquery-public-data.ml_datasets.penguins GROUP BY island
-- Evaluate a bigquery ML Model.
SELECT * FROM ML.EVALUATE(MODEL `my_dataset.my_model`)
-- Evaluate BigQuery ML model on custom data
SELECT *
FROM ML.EVALUATE(MODEL `my_dataset.my_model`, (SELECT * FROM `my_dataset.my_table`))
-- Predict using BigQuery ML model:
SELECT *
FROM ML.PREDICT(MODEL `my_dataset.my_model`, (SELECT * FROM `my_dataset.my_table`))
-- Forecast data using AI.FORECAST
SELECT *
FROM AI.FORECAST(TABLE `project.dataset.my_table`, data_col => 'num_trips',
timestamp_col => 'date', id_cols => ['usertype'], horizon => 30)
Queries executed using the execute_sql_readonly tool will always have the job label goog-mcp-server: true automatically set in addition to any custom labels provided in the request. Queries are charged to the project specified in the project_id field.
The following code sample shows how to use curl to call the execute_sql_readonly MCP tool.
| Curl Request |
|---|
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 }' |
Input Schema
Runs a BigQuery SQL query synchronously and returns query results if the query completes within a specified timeout.
QueryRequest
| JSON representation |
|---|
{ "projectId": string, "query": string, "dryRun": boolean, "labels": { string: string, ... } } |
| Fields | |
|---|---|
projectId |
Required. Project that will be used for query execution and billing. |
query |
Required. The query to execute in the form of a GoogleSQL query. |
dryRun |
Optional. If set to true, BigQuery doesn't run the job. Instead, if the query is valid, BigQuery returns statistics about the job such as how many bytes would be processed. If the query is invalid, an error returns. The default value is false. |
labels |
Optional. The labels associated with this query. Labels can be used to organize and group query jobs. Label keys and values can be no longer than 63 characters, can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label keys must start with a letter and each label in the map must have a different key. An object containing a list of |
LabelsEntry
| JSON representation |
|---|
{ "key": string, "value": string } |
| Fields | |
|---|---|
key |
|
value |
|
Output Schema
Response for a BigQuery SQL query.
QueryResponse
| JSON representation |
|---|
{ "schema": { object ( |
| Fields | |
|---|---|
schema |
The schema of the results. Present only when the query completes successfully. |
rows[] |
An object with as many results as can be contained within the maximum permitted reply size. To get any additional rows, you can call GetQueryResults and specify the jobReference returned above. |
jobComplete |
Whether the query has completed or not. If rows or totalRows are present, this will always be true. If this is false, totalRows will not be available. |
errors[] |
Output only. The first errors or warnings encountered during the running of the job. The final message includes the number of errors that caused the process to stop. Errors here do not necessarily mean that the job has completed or was unsuccessful. For more information about error messages, see Error messages. |
queryId |
Output only. The ID of the query. |
totalBytesBilled |
Output only. The total number of bytes billed for the query. Only applies if the project is configured to use on-demand pricing. |
totalSlotMs |
Output only. Number of slot ms the user is actually billed for. |
numDmlAffectedRows |
Output only. The number of rows affected by a DML statement. |
totalBytesProcessed |
Output only. The total number of bytes processed for this query. |
TableSchema
| JSON representation |
|---|
{ "fields": [ { object ( |
| Fields | |
|---|---|
fields[] |
Describes the fields in a table. |
foreignTypeInfo |
Optional. Specifies metadata of the foreign data type definition in field schema ( |
TableFieldSchema
| JSON representation |
|---|
{ "name": string, "type": string, "mode": string, "fields": [ { object ( |
| Fields | |
|---|---|
name |
Required. The field name. The name must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_), and must start with a letter or underscore. The maximum length is 300 characters. |
type |
Required. The field data type. Possible values include:
Use of RECORD/STRUCT indicates that the field contains a nested schema. |
mode |
Optional. The field mode. Possible values include NULLABLE, REQUIRED and REPEATED. The default value is NULLABLE. |
fields[] |
Optional. Describes the nested schema fields if the type property is set to RECORD. |
description |
Optional. The field description. The maximum length is 1,024 characters. |
policyTags |
Optional. The policy tags attached to this field, used for field-level access control. If not set, defaults to empty policy_tags. |
dataGovernanceTagsInfo |
Optional. Specifies the data governance tags on this field. This field works with other column-level security fields as follows:
|
dataPolicies[] |
Optional. Data policies attached to this field, used for field-level access control. |
dataPolicyList |
Optional. Specifies data policies attached to this field, used for field-level access control. When set, this will be the source of truth for data policy information. |
maxLength |
Optional. Maximum length of values of this field for STRINGS or BYTES. If max_length is not specified, no maximum length constraint is imposed on this field. If type = "STRING", then max_length represents the maximum UTF-8 length of strings in this field. If type = "BYTES", then max_length represents the maximum number of bytes in this field. It is invalid to set this field if type ≠ "STRING" and ≠ "BYTES". |
precision |
Optional. Precision (maximum number of total digits in base 10) and scale (maximum number of digits in the fractional part in base 10) constraints for values of this field for NUMERIC or BIGNUMERIC. It is invalid to set precision or scale if type ≠ "NUMERIC" and ≠ "BIGNUMERIC". If precision and scale are not specified, no value range constraint is imposed on this field insofar as values are permitted by the type. Values of this NUMERIC or BIGNUMERIC field must be in this range when:
Acceptable values for precision and scale if both are specified:
Acceptable values for precision if only precision is specified but not scale (and thus scale is interpreted to be equal to zero):
If scale is specified but not precision, then it is invalid. |
scale |
Optional. See documentation for precision. |
timestampPrecision |
Optional. Precision (maximum number of total digits in base 10) for seconds of TIMESTAMP type. Possible values include: * 6 (Default, for TIMESTAMP type with microsecond precision) * 12 (For TIMESTAMP type with picosecond precision) |
roundingMode |
Optional. Specifies the rounding mode to be used when storing values of NUMERIC and BIGNUMERIC type. |
collation |
Optional. Field collation can be set only when the type of field is STRING. The following values are supported:
|
defaultValueExpression |
Optional. A SQL expression to specify the default value for this field. |
rangeElementType |
Optional. The subtype of the RANGE, if the type of this field is RANGE. If the type is RANGE, this field is required. Values for the field element type can be the following:
|
foreignTypeDefinition |
Optional. Definition of the foreign data type. Only valid for top-level schema fields (not nested fields). If the type is FOREIGN, this field is required. |
generatedColumn |
Optional. Definition of how values are generated for the field. Only valid for top-level schema fields (not nested fields). |
StringValue
| JSON representation |
|---|
{ "value": string } |
| Fields | |
|---|---|
value |
The string value. |
PolicyTagList
| JSON representation |
|---|
{ "names": [ string ] } |
| Fields | |
|---|---|
names[] |
A list of policy tag resource names. For example, "projects/1/locations/eu/taxonomies/2/policyTags/3". At most 1 policy tag is currently allowed. |
DataGovernanceTagsInfo
| JSON representation |
|---|
{ "dataGovernanceTags": { string: string, ... } } |
| Fields | |
|---|---|
dataGovernanceTags |
Optional. The data governance tags added to this field are used for field-level access control. Only one data governance tag is currently supported on a field. Tag keys are globally unique. Tag key is expected to be in the namespaced format, for example "parent-id/pii" where parent-id is the ID of the parent organization or project resource for this tag key. Tag value is expected to be the short name, for example "sensitive". See Tag definitions for more details. For example: "parent-id/pii": "sensitive", "myProject/cost_center": "sales" An object containing a list of |
DataGovernanceTagsEntry
| JSON representation |
|---|
{ "key": string, "value": string } |
| Fields | |
|---|---|
key |
|
value |
|
DataPolicyOption
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field
|
|
name |
Data policy resource name in the form of projects/project_id/locations/location_id/dataPolicies/data_policy_id. |
DataPolicyList
| JSON representation |
|---|
{
"dataPolicies": [
{
object ( |
| Fields | |
|---|---|
dataPolicies[] |
Contains a list of data policy options. At most 9 data policies are allowed per field. |
Int64Value
| JSON representation |
|---|
{ "value": string } |
| Fields | |
|---|---|
value |
The int64 value. |
FieldElementType
| JSON representation |
|---|
{ "type": string } |
| Fields | |
|---|---|
type |
Required. The type of a field element. For more information, see |
GeneratedColumn
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field
|
|
generatedMode |
Optional. Dictates when system generated values are used to populate the field. |
Union field
|
|
generatedExpressionInfo |
Definition of the expression used to generate the field. |
GeneratedExpressionInfo
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field
|
|
generationExpression |
Optional. The generation expression (e.g. AI.EMBED(...)) used to generate the field. |
Union field
|
|
asynchronous |
Optional. Whether the column generation is done asynchronously. |
Union field
|
|
stored |
Optional. Whether the generated column is stored in the table. |
ForeignTypeInfo
| JSON representation |
|---|
{
"typeSystem": enum ( |
| Fields | |
|---|---|
typeSystem |
Required. Specifies the system which defines the foreign data type. |
Struct
| JSON representation |
|---|
{ "fields": { string: value, ... } } |
| Fields | |
|---|---|
fields |
Unordered map of dynamically typed values. An object containing a list of |
FieldsEntry
| JSON representation |
|---|
{ "key": string, "value": value } |
| Fields | |
|---|---|
key |
|
value |
|
Value
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field kind. The kind of value. kind can be only one of the following: |
|
nullValue |
Represents a JSON |
numberValue |
Represents a JSON number. Must not be |
stringValue |
Represents a JSON string. |
boolValue |
Represents a JSON boolean ( |
structValue |
Represents a JSON object. |
listValue |
Represents a JSON array. |
ListValue
| JSON representation |
|---|
{ "values": [ value ] } |
| Fields | |
|---|---|
values[] |
Repeated field of dynamically typed values. |
BoolValue
| JSON representation |
|---|
{ "value": boolean } |
| Fields | |
|---|---|
value |
The bool value. |
ErrorProto
| JSON representation |
|---|
{ "reason": string, "location": string, "debugInfo": string, "message": string } |
| Fields | |
|---|---|
reason |
A short error code that summarizes the error. |
location |
Specifies where the error occurred, if present. |
debugInfo |
Debugging information. This property is internal to Google and should not be used. |
message |
A human-readable description of the error. |
RoundingMode
Rounding mode options that can be used when storing NUMERIC or BIGNUMERIC values.
| Enums | |
|---|---|
ROUNDING_MODE_UNSPECIFIED |
Unspecified will default to using ROUND_HALF_AWAY_FROM_ZERO. |
ROUND_HALF_AWAY_FROM_ZERO |
ROUND_HALF_AWAY_FROM_ZERO rounds half values away from zero when applying precision and scale upon writing of NUMERIC and BIGNUMERIC values. For Scale: 0 1.1, 1.2, 1.3, 1.4 => 1 1.5, 1.6, 1.7, 1.8, 1.9 => 2 |
ROUND_HALF_EVEN |
ROUND_HALF_EVEN rounds half values to the nearest even value when applying precision and scale upon writing of NUMERIC and BIGNUMERIC values. For Scale: 0 1.1, 1.2, 1.3, 1.4 => 1 1.5 => 2 1.6, 1.7, 1.8, 1.9 => 2 2.5 => 2 |
GeneratedMode
Dictates when system generated values are used to populate the field.
| Enums | |
|---|---|
GENERATED_MODE_UNSPECIFIED |
Unspecified GeneratedMode will default to GENERATED_ALWAYS. |
GENERATED_ALWAYS |
Field can only have system generated values. Users cannot manually insert values into the field. |
GENERATED_BY_DEFAULT |
Use system generated values only if the user does not explicitly provide a value. |
TypeSystem
External systems, such as query engines or table formats, that have their own data types.
| Enums | |
|---|---|
TYPE_SYSTEM_UNSPECIFIED |
TypeSystem not specified. |
HIVE |
Represents Hive data types. |
NullValue
Represents a JSON null.
NullValue is a sentinel, using an enum with only one value to represent the null value for the Value type union.
A field of type NullValue with any value other than 0 is considered invalid. Most ProtoJSON serializers will emit a Value with a null_value set as a JSON null regardless of the integer value, and so will round trip to a 0 value.
| Enums | |
|---|---|
NULL_VALUE |
Null value. |
Tool Annotations
Tool annotations are sent to MCP clients to describe the basic risk of a given tool. Most clients treat these hints as untrusted, but they can be used to decide when a confirmation prompt might be sent to a user.
Along with the title string, the following boolean hints are defined as follows:
readOnlyHint: If true, the tool doesn't modify its environment. Default: false.destructiveHint: If true, then the tool can perform destructive actions. If false, then the tool can only perform additive actions. Default: true.idempotentHint: If true, then calling the tool repeatedly with the same arguments will have no additional effect on its environment. Default: false.openWorldHint: If true, then the tool can interact with an 'open world' of external entities. If false, then the tool can only interact with internal entities. For example, a web search tool would be open world, while a memory tool would not be open world.
Destructive Hint: ❌ | Idempotent Hint: ✅ | Read Only Hint: ✅ | Open World Hint: ❌