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 use curl
to invoke the execute_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' s MCP specification } } , "jsonrpc" : "2.0" , "id" : 1 } ' |
Input Schema
The request for ExecuteSql
.
ExecuteSqlRequest
| JSON representation |
|---|
{ "session" : string , "sql" : string , "seqno" : string , // Union field |
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.
transaction
. 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
Output Schema
Results for execute_sql
tool
ResultSet
| JSON representation |
|---|
{ "metadata" : { object ( |
| Fields | |
|---|---|
metadata
|
Metadata about the result set, such as row type information. |
rows[]
|
Each element in |
precommitToken
|
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 the |
ResultSetMetadata
| JSON representation |
|---|
{ "rowType" : { object ( |
| Fields | |
|---|---|
rowType
|
Indicates the field names and types for the rows in the result set. For example, a SQL query like
|
transaction
|
If the read or SQL query began a transaction as a side-effect, the information about the new transaction is yielded here. |
undeclaredParameters
|
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
|
StructType
| JSON representation |
|---|
{
"fields"
:
[
{
object (
|
| Fields | |
|---|---|
fields[]
|
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 the |
Field
| JSON representation |
|---|
{
"name"
:
string
,
"type"
:
{
object (
|
| Fields | |
|---|---|
name
|
The name of the field. For reads, this is the column name. For SQL queries, it is the column alias (e.g., |
type
|
The type of the field. |
Type
| JSON representation |
|---|
{ "code" : enum ( |
| Fields | |
|---|---|
code
|
Required. The |
arrayElementType
|
If |
structType
|
If |
typeAnnotation
|
The |
protoTypeFqn
|
If |
Transaction
| JSON representation |
|---|
{
"id"
:
string
,
"readTimestamp"
:
string
,
"precommitToken"
:
{
object (
|
| Fields | |
|---|---|
id
|
Single-use read-only transactions do not have IDs, because single-use transactions do not support multiple requests. A base64-encoded string. |
readTimestamp
|
For snapshot read-only transactions, the read timestamp chosen for the transaction. Not returned by default: see A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: 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: |
precommitToken
|
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 the |
Timestamp
| JSON representation |
|---|
{ "seconds" : string , "nanos" : integer } |
| Fields | |
|---|---|
seconds
|
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
|
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
|
Opaque precommit token. A base64-encoded string. |
seqNum
|
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[]
|
Repeated field of dynamically typed values. |
Value
| JSON representation |
|---|
{ // Union field |
kind
. 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 repeated Value
.
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
|
|
Tool Annotations
Destructive Hint: ✅ | Idempotent Hint: ❌ | Read Only Hint: ❌ | Open World Hint: ❌

