Run Query
run-queryExecute one supported SQL statement through RawTree’s Query API to run reads or authorized writes, including data changes, table configuration, and access-control management.
Instructions
Execute one SQL statement through RawTree's Query API. Supports reads and the writes below; this tool can change data, table configuration, and access controls. Use the existing connection with sufficient permission; supported writes do not require a browser login or a different execution surface.
Supported statements and permissions:
SELECT, WITH, EXPLAIN, DESCRIBE: read_only, read_write, or admin API key, or a signed-in session. Database-role keys support reads subject to their database grants; they cannot execute the write families below. write_only keys can only TRUNCATE through this endpoint.
INSERT INTO [(columns)] SELECT ... (including a WITH source): read_write/admin or a signed-in session. The target must already exist in the selected user database. VALUES, FORMAT, and url()/urlCluster() sources are unsupported; use insert-json or insert-from-url for ingestion.
INSERT INTO FUNCTION s3(...) SELECT ... (including a WITH source): read_write/admin or a signed-in session, with a selected user database. Exports query results to S3; only the unqualified s3 function is supported as a function destination. No VALUES, FORMAT, or url()/urlCluster() sources, including nested function arguments.
TRUNCATE TABLE [IF EXISTS] [database.] [SYNC]: write_only/read_write/admin or a signed-in session with write permission. One table in the selected user database; removes all rows but preserves table configuration. Always waits for replicas; no ON CLUSTER or partition clauses.
SELECT ... CACHE INTO [database.]view [EVERY|AFTER interval] [TTL interval [FROM LAST READ]]: admin API key or a signed-in session (table-create permission). Cache destinations must be in the selected user database; intervals use numeric literal/unit pairs. No url()/urlCluster() sources.
CREATE TABLE [IF NOT EXISTS] ENGINE = ReplicatedRawMergeTree [ORDER BY ] [TTL [DELETE [WHERE ]]] [SETTINGS name = value, ...]: admin API key or a signed-in session, in the selected user database. Optional ON CLUSTER 'default'; no column definitions, engine arguments, other engines, or AS SELECT. TTL supports row deletion only; TTL and settings reject subqueries.
ALTER TABLE MODIFY ORDER BY ; MODIFY TTL [DELETE [WHERE ]]; MODIFY SETTING name = value, ...; RESET SETTING name, ...; ADD/MATERIALIZE/CLEAR/DROP PROJECTION; ADD/MATERIALIZE/CLEAR/DROP INDEX (including text indexes): admin API key or a signed-in session. One operation per statement, on a table in the selected user database; no ON CLUSTER or IN PARTITION. TTL supports row deletion only; TTL and settings reject subqueries. Settings use engine-supported names. ADD accepts IF NOT EXISTS; MATERIALIZE/CLEAR/DROP accept IF EXISTS. ADD INDEX requires an expression and TYPE, optionally positive integer GRANULARITY; AFTER is unsupported. Use storage paths such as __raw_data.field in index/projection definitions, with casts as needed.
KILL MUTATION WHERE table = '' [AND mutation_id = '']: admin API key or a signed-in session. The backend applies the selected user database automatically. Only these equality filters are supported; use doubled quotes, not backslash escapes, in string values.
CREATE ROLE , DROP ROLE [IF EXISTS] , GRANT SELECT/INSERT [(columns)] ON . TO : admin API key or organization administrator session. Grants can combine SELECT and INSERT and use database.* or .; the target must be an existing role, not a user. No role inheritance, delegation options, or REVOKE.
CREATE [OR REPLACE] WORKLOAD/RESOURCE, CREATE WORKLOAD/RESOURCE IF NOT EXISTS, DROP WORKLOAD/RESOURCE [IF EXISTS]: admin API key or organization administrator session. Workloads support IN and literal SETTINGS; resources support MASTER/WORKER THREAD and READ/WRITE DISK or ANY DISK operations.
CREATE SETTINGS PROFILE [OR REPLACE | IF NOT EXISTS], DROP SETTINGS PROFILE [IF EXISTS]: admin API key or organization administrator session. Only workload = '' and use_concurrency_control = 0/1, optionally READONLY/CONST, assigned TO 1–32 distinct existing roles.
CREATE ROW POLICY [OR REPLACE | IF NOT EXISTS], DROP ROW POLICY [IF EXISTS]: admin API key or organization administrator session. One table in the selected user database; SELECT USING a scalar filter, optional AS PERMISSIVE/RESTRICTIVE, TO 1–32 distinct existing roles. No subqueries, user targets, or wildcard targets.
CREATE NAMED COLLECTION [IF NOT EXISTS] AS key = literal, ...: admin API key or organization administrator session. Unique keys with string/numeric/boolean values and optional OVERRIDABLE/NOT OVERRIDABLE; no ALTER or DROP.
CREATE HANDLER [IF NOT EXISTS] URL '/path' [METHODS (GET)] AS SELECT ..., ALTER HANDLER URL '/path' [METHODS (GET)] AS SELECT ..., DROP HANDLER [IF EXISTS] : admin API key or organization administrator session, with a selected cluster and database. Exact paths and read-only SELECT queries only; no URL REGEXP, other methods, or url()/urlCluster() sources. SQL executes as submitted; optional ON CLUSTER 'default' follows the name and is never added automatically. Handler parameters cannot use Platform database or execution setting names.
Role, workload/resource, profile, policy, and named-collection management accept optional ON CLUSTER 'default' and preserve the engine's replication semantics; row policies with ON CLUSTER require an explicit matching database.table. These management operations and handlers can affect the cluster beyond the selected database. All write families, including handler DDL, are unavailable in RawTree's internal organization. Mutations outside the listed forms, including UPDATE, standalone DELETE, DROP TABLE, and other ALTER operations, are unsupported; use delete-table for table deletion.
Returns JSON meta, data, rows, statistics, and optional hints. DDL normally returns an empty result; handler DDL returns empty meta/data and rows: 0, with statistics. INSERT SELECT reports statistics.written_rows; KILL MUTATION returns matched mutations. MATERIALIZE/CLEAR run in the background: inspect system.mutations for progress and system.projections or system.data_skipping_indices for definitions. Repeating writes may duplicate data or change state; inspect results before retrying. For exploratory reads, use LIMIT and deterministic ORDER BY.
Detailed syntax and replication limits: https://rawtree.com/docs/reference/api, https://rawtree.com/docs/reference/api/query#sql-defined-http-endpoints, and https://rawtree.com/docs/reference/authentication#existing-database-roles.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sql": "<sql>"
},
"name": "run-query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | One supported SQL statement to execute: a read query or an authorized INSERT SELECT, CREATE TABLE, ALTER TABLE, KILL MUTATION, or management statement listed in the tool description. Writes can change persistent state. Use LIMIT for exploratory reads. | |
| cluster | No | Name or ID of the cluster to use for this operation. | |
| database | No | Optional RawTree database override. RawTree uses the default database when omitted. | |
| organization | No | Name or ID of the organization containing the target cluster. |