MCP Tools Reference: spanner.googleapis.com

Tool:execute_sql

Execute SQL statement using a given session. * execute_sql tool can be used to execute DQL as well as DML statements. * Use commit tool to commit result of a DML statement. * DDL statements are only supported using update_database_schema tool.

The following sample demonstrate how to usecurl to invoke theexecute_sql MCP tool.

Curl Request
curl--location'https://spanner.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'sMCPspecification}},"jsonrpc":"2.0","id":1}'

Input Schema

The request forExecuteSql.

ExecuteSqlRequest

JSON representation
{"session":string,"sql":string,"seqno":string,// Union fieldtransaction can be only one of the following:"singleUseTransaction":boolean,"readOnlyTransaction":boolean,"readWriteTransaction":boolean,"existingTransactionId":string// End of list of possible types for union fieldtransaction.}
Fields
session

string

Required. The session in which the SQL query is executed. Format:projects/{project}/instances/{instance}/databases/{database}/sessions/{session}

sql

string

Required. The SQL query to execute.

seqno

string (int64 format)

Optional. Sequence number of the request within a transaction. The sequence number must be monotonically increasing within the transaction. If a request arrives for the first time with an out-of-order sequence number, the transaction can be aborted.

Union fieldtransaction. The transaction in which the SQL query is executed. If not set, a single use transaction will be used. For DML, use read_write_transaction or specify existing_transaction_id for previously created read-write transaction when multiple statements are part of transaction.transaction can be only one of the following:
singleUseTransaction

boolean

Use a single use transaction for query execution.

readOnlyTransaction

boolean

Begin a new read-only transaction.

readWriteTransaction

boolean

Begin a new read-write transaction.

existingTransactionId

string (bytes format)

Use an existing transaction.

A base64-encoded string.

Output Schema

Results forexecute_sql tool

ResultSet

JSON representation
{"metadata":{object (ResultSetMetadata)},"rows":[array],"precommitToken":{object (MultiplexedSessionPrecommitToken)}}
Fields
metadata

object (ResultSetMetadata)

Metadata about the result set, such as row type information.

rows[]

array (ListValue format)

Each element inrows is a row whose format is defined by [metadata.row_type][ResultSetMetadata.row_type]. The ith element in each row matches the ith field in [metadata.row_type][ResultSetMetadata.row_type]. Elements are encoded based on type as describedhere.

precommitToken

object (MultiplexedSessionPrecommitToken)

Optional. A precommit token is included if the read-write transaction is on a multiplexed session. Pass the precommit token with the highest sequence number from this transaction attempt to theCommit request for this transaction.

ResultSetMetadata

JSON representation
{"rowType":{object (StructType)},"transaction":{object (Transaction)},"undeclaredParameters":{object (StructType)}}
Fields
rowType

object (StructType)

Indicates the field names and types for the rows in the result set. For example, a SQL query like"SELECT UserId, UserName FROM Users" could return arow_type value like:

"fields": [  { "name": "UserId", "type": { "code": "INT64" } },  { "name": "UserName", "type": { "code": "STRING" } },]
transaction

object (Transaction)

If the read or SQL query began a transaction as a side-effect, the information about the new transaction is yielded here.

undeclaredParameters

object (StructType)

A SQL query can be parameterized. In PLAN mode, these parameters can be undeclared. This indicates the field names and types for those undeclared parameters in the SQL query. For example, a SQL query like"SELECT * FROM Users where UserId = @userId and UserName = @userName " could return aundeclared_parameters value like:

"fields": [  { "name": "UserId", "type": { "code": "INT64" } },  { "name": "UserName", "type": { "code": "STRING" } },]

StructType

JSON representation
{"fields":[{object (Field)}]}
Fields
fields[]

object (Field)

The list of fields that make up this struct. Order is significant, because values of this struct type are represented as lists, where the order of field values matches the order of fields in theStructType. In turn, the order of fields matches the order of columns in a read request, or the order of fields in theSELECT clause of a query.

Field

JSON representation
{"name":string,"type":{object (Type)}}
Fields
name

string

The name of the field. For reads, this is the column name. For SQL queries, it is the column alias (e.g.,"Word" in the query"SELECT 'hello' AS Word"), or the column name (e.g.,"ColName" in the query"SELECT ColName FROM Table"). Some columns might have an empty name (e.g.,"SELECT UPPER(ColName)"). Note that a query result can contain multiple fields with the same name.

type

object (Type)

The type of the field.

Type

JSON representation
{"code":enum (TypeCode),"arrayElementType":{object (Type)},"structType":{object (StructType)},"typeAnnotation":enum (TypeAnnotationCode),"protoTypeFqn":string}
Fields
code

enum (TypeCode)

Required. TheTypeCode for this type.

arrayElementType

object (Type)

Ifcode ==ARRAY, thenarray_element_type is the type of the array elements.

structType

object (StructType)

Ifcode ==STRUCT, thenstruct_type provides type information for the struct's fields.

typeAnnotation

enum (TypeAnnotationCode)

TheTypeAnnotationCode that disambiguates SQL type that Spanner will use to represent values of this type during query processing. This is necessary for some type codes because a singleTypeCode can be mapped to different SQL types depending on the SQL dialect.type_annotation typically is not needed to process the content of a value (it doesn't affect serialization) and clients can ignore it on the read path.

protoTypeFqn

string

Ifcode ==PROTO orcode ==ENUM, thenproto_type_fqn is the fully qualified name of the proto type representing the proto/enum definition.

Transaction

JSON representation
{"id":string,"readTimestamp":string,"precommitToken":{object (MultiplexedSessionPrecommitToken)}}
Fields
id

string (bytes format)

id may be used to identify the transaction in subsequentRead,ExecuteSql,Commit, orRollback calls.

Single-use read-only transactions do not have IDs, because single-use transactions do not support multiple requests.

A base64-encoded string.

readTimestamp

string (Timestamp format)

For snapshot read-only transactions, the read timestamp chosen for the transaction. Not returned by default: seeTransactionOptions.ReadOnly.return_read_timestamp.

A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example:"2014-10-02T15:01:23.045123456Z".

Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples:"2014-10-02T15:01:23Z","2014-10-02T15:01:23.045123456Z" or"2014-10-02T15:01:23+05:30".

precommitToken

object (MultiplexedSessionPrecommitToken)

A precommit token is included in the response of a BeginTransaction request if the read-write transaction is on a multiplexed session and a mutation_key was specified in theBeginTransaction. The precommit token with the highest sequence number from this transaction attempt should be passed to theCommit request for this transaction.

Timestamp

JSON representation
{"seconds":string,"nanos":integer}
Fields
seconds

string (int64 format)

Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be between -62135596800 and 253402300799 inclusive (which corresponds to 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).

nanos

integer

Non-negative fractions of a second at nanosecond resolution. This field is the nanosecond portion of the duration, not an alternative to seconds. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be between 0 and 999,999,999 inclusive.

MultiplexedSessionPrecommitToken

JSON representation
{"precommitToken":string,"seqNum":integer}
Fields
precommitToken

string (bytes format)

Opaque precommit token.

A base64-encoded string.

seqNum

integer

An incrementing seq number is generated on every precommit token that is returned. Clients should remember the precommit token with the highest sequence number from the current transaction attempt.

ListValue

JSON representation
{"values":[value]}
Fields
values[]

value (Value format)

Repeated field of dynamically typed values.

Value

JSON representation
{// Union fieldkind 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 fieldkind.}
Fields
Union fieldkind. The kind of value.kind can be only one of the following:
nullValue

null

Represents a null value.

numberValue

number

Represents a double value.

stringValue

string

Represents a string value.

boolValue

boolean

Represents a boolean value.

structValue

object (Struct format)

Represents a structured value.

listValue

array (ListValue format)

Represents a repeatedValue.

Struct

JSON representation
{"fields":{string:value,...}}
Fields
fields

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

Unordered map of dynamically typed values.

An object containing a list of"key": value pairs. Example:{ "name": "wrench", "mass": "1.3kg", "count": "3" }.

FieldsEntry

JSON representation
{"key":string,"value":value}
Fields
key

string

value

value (Value format)

Tool Annotations

Destructive Hint: ✅ | Idempotent Hint: ❌ | Read Only Hint: ❌ | Open World Hint: ❌

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-11 UTC.