Tool: execute_sql
Execute a SQL query on an instance.
Requirements
- The cluster must exist and be in a READY state. You can use the
list_clusterstool to list all clusters in a project. - The instance must exist and be in a READY state. You can use the
list_instancestool to list all instances in a cluster. - The user must exist and have the appropriate permissions to execute the SQL query. You can use the
list_userstool to list all users in a cluster.
Usage
- Call
create_clusterto create a cluster if it doesn't exist. - Call
create_instanceto create an instance if it doesn't exist. - Call
create_userto create a user with the appropriate permissions if it doesn't exist. - Call
execute_sqlto execute a SQL query on an instance. - This will return the result of the SQL query.
The following sample demonstrate how to use curl to invoke the execute_sql MCP tool.
| Curl Request |
|---|
curl --location 'https://alloydb.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
Message for executing a SQL statement in a database inside an AlloyDB instance. Uses IAM user authentication.
ExecuteSqlRequest
| JSON representation |
|---|
{ "instance": string, "database": string, "sqlStatement": string, } |
| Fields | |
|---|---|
instance |
Required. Identifier. The name of the instance resource with the format: * projects/{project}/locations/{region}/clusters/{cluster_id}/instances/{instance_id} where the cluster and instance ID segments should satisfy the regex expression |
database |
Required. Name of the database where the query will be executed. You can use the default "postgres" database if a different database is not created. Note - Value provided should be the same as expected from |
sqlStatement |
Required. SQL statement to execute on database. Any valid statement is permitted, including DDL, DML, DQL statements. This field is REQUIRED. |
Output Schema
Execute a SQL statement response.
ExecuteSqlResponse
| JSON representation |
|---|
{ "sqlResults": [ { object ( |
| Fields | |
|---|---|
sqlResults[] |
SqlResult represents the results for the execution of sql statements. |
metadata |
Any additional metadata information regarding the execution of the sql statement. |
SqlResult
| JSON representation |
|---|
{ "columns": [ { object ( |
| Fields | |
|---|---|
columns[] |
List of columns included in the result. This also includes the data type of the column. |
rows[] |
Rows returned by the SQL statement. |
SqlResultColumn
| JSON representation |
|---|
{ "name": string, "type": string } |
| Fields | |
|---|---|
name |
Name of the column. |
type |
Datatype of the column as reported by the postgres driver. Common type names are "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL", "INT", and "BIGINT". |
SqlResultRow
| JSON representation |
|---|
{
"values": [
{
object ( |
| Fields | |
|---|---|
values[] |
List of values in a row of sql result. |
SqlResultValue
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field
|
|
value |
The cell value represented in string format. Timestamps are converted to string using RFC3339Nano format. |
Union field
|
|
nullValue |
Set to true if cell value is null. |
ExecuteSqlMetadata
| JSON representation |
|---|
{
"message": string,
"partialResult": boolean,
"sqlStatementExecutionDuration": string,
"status": enum ( |
| Fields | |
|---|---|
message |
Message related to SQL execution. Marked as core content since it can potentially contain details related to the query or result set. This field can be used to convey messages such as "when the SQL result set exceeds the acceptable response size limits." |
partialResult |
Set to true if SQL returned a result set larger than the acceptable response size limits and the result was truncated. |
sqlStatementExecutionDuration |
The time duration taken to execute the sql statement. A duration in seconds with up to nine fractional digits, ending with ' |
status |
Status of SQL execution. |
Duration
| JSON representation |
|---|
{ "seconds": string, "nanos": integer } |
| Fields | |
|---|---|
seconds |
Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years |
nanos |
Signed fractions of a second at nanosecond resolution of the span of time. Durations less than one second are represented with a 0 |
Tool Annotations
Destructive Hint: ✅ | Idempotent Hint: ❌ | Read Only Hint: ❌ | Open World Hint: ✅