runSql
runSql[ExoBench server version: 1.4.29]
⚠️ EPHEMERAL DATABASE — READ THIS FIRST ⚠️
Each call provisions a fresh database from schema and DESTROYS it on return.
Tables, data, indexes, and settings from previous calls are GONE. correlationId
is for tracking only — it does NOT preserve DB state. Pass the FULL schema
(CREATE TABLE + INSERT) in EVERY call. If the user expects persistence, tell
them ExoBench has none.
ExoBench: Execute raw SQL queries against an ephemeral database initialized with the provided schema. Returns query results in a simple JSON format with column headers and row data as a 2D array.
The database type is specified via the databaseType parameter:
POSTGRES: Temporary isolated schema with dedicated user, uses PostgreSQL syntax and features (Postgres 17, the default)
POSTGRES_18: Same as POSTGRES but runs against a Postgres 18 pool; use it to compare a query's plan and timing on 18 vs POSTGRES (17), e.g. B-tree skip scan, uuidv7(), virtual generated columns
SQLSERVER: Temporary isolated schema, uses T-SQL syntax and features
MYSQL: Temporary isolated database, uses MySQL syntax and features
SQLITE: In-memory, lightweight, uses standard SQLite syntax
WHEN TO USE: When you need to run your own hand-written SQL queries to test database behavior or compare the output with ExoQuery results from validateAndRunKotlinExoQuery. This lets you verify that ExoQuery-generated SQL produces the same results as your expected SQL.
INPUT REQUIREMENTS:
query: A valid SQL query (SELECT, INSERT, UPDATE, DELETE, etc.)
schema: SQL schema with CREATE TABLE and INSERT statements to initialize the test database
databaseType: POSTGRES, POSTGRES_18, SQLSERVER, MYSQL, or SQLITE (defaults to POSTGRES if not specified)
OUTPUT FORMAT:
On success, returns JSON with the SQL query, the seed the run used, and a 2D array of results: {"sql":"SELECT * FROM users ORDER BY id","seed":2215213096,"seedSource":"default","output":[["id","name","age"],["1","Alice","30"],["2","Bob","25"],["3","Charlie","35"]]}
Output format details:
First array element contains column headers
Subsequent array elements contain row data
All values are returned as strings
seed/seedSource: the seed every random function ran under (default = derived from correlationId); pass it back as
seedto reproduce
On error, returns JSON with error message and the attempted query (if available): {"error":"Query execution failed: no such table: USERS","sql":"SELECT * FROM USERS"}
Or if schema initialization fails: {"error":"Database initialization failed due to: near "CREAT": syntax error\nWhen executing the following statement:\n--------\nCREATE TABLE users ...\n--------","sql":"CREATE TABLE users ..."}
EXAMPLE INPUT:
Query: SELECT * FROM users ORDER BY id
Schema: CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, age INTEGER );
INSERT INTO users (id, name, age) VALUES (1, 'Alice', 30); INSERT INTO users (id, name, age) VALUES (2, 'Bob', 25); INSERT INTO users (id, name, age) VALUES (3, 'Charlie', 35);
(The success and error outputs for this input are the ones shown under OUTPUT FORMAT.)
More query examples, full error-output examples, and how seeding works per engine: getMcpDocs('run-sql').
SCHEMA RULES:
Use the syntax of the selected databaseType
Table names are case-sensitive (use lowercase for simplicity or quote names)
Include INSERT statements to populate test data for meaningful results
Schema SQL is split on semicolons (;), so each statement after a ';' is executed separately
Avoid semicolons in comments as they will cause statement parsing issues
COMPARISON WITH EXOQUERY: This tool is designed to work alongside validateAndRunKotlinExoQuery for comparison purposes:
Use validateAndRunKotlinExoQuery to run ExoQuery Kotlin code and see the generated SQL + results
Use runSql with your own hand-written SQL to verify you get the same output
Compare the outputs to ensure ExoQuery generates the SQL you expect
Test edge cases with plain SQL before writing equivalent ExoQuery code
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": {
"query": "<query>",
"schema": "<schema>"
},
"name": "runSql"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| seed | No | Integer seed for the SQL's random functions (Postgres setseed, SQL Server RAND(seed)). Omitted: the DEFAULT_SEED is derived from correlationId, so one session reuses the same data. Returned as seed/seedSource. | |
| query | Yes | A valid SQL query to execute against the database. Can be any valid SQL statement (syntax depends on databaseType parameter — Postgres, SQL Server, MySQL, or SQLite): - SELECT queries (with WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, etc.) - INSERT statements - UPDATE statements - DELETE statements - DDL statements like CREATE/ALTER/DROP (applied after schema initialization) The query will be executed against a database initialized with the provided schema parameter. ${SCHEMA} = the run's schema name (SQL Server scalar UDF: ${SCHEMA}.fn(x)). Example: SELECT * FROM users WHERE age > 25 ORDER BY name | |
| schema | Yes | SQL schema to initialize the ephemeral test database. Must include: 1. CREATE TABLE statements for all tables used in the query 2. INSERT statements with test data Use syntax appropriate for the selected databaseType (Postgres, SQL Server, MySQL, or SQLite). Table names are case-sensitive. The schema is split on semicolons, so each statement is executed separately. Example: CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, age INTEGER ); INSERT INTO users (id, name, age) VALUES (1, 'Alice', 30); INSERT INTO users (id, name, age) VALUES (2, 'Bob', 25); INSERT INTO users (id, name, age) VALUES (3, 'Charlie', 35); | |
| databaseType | No | Database type to use for query execution. Must be POSTGRES, POSTGRES_18, SQLSERVER, MYSQL, or SQLITE. Defaults to POSTGRES if not specified. - POSTGRES: Temporary isolated schema with dedicated user, uses PostgreSQL syntax and features (Postgres 17, the default) - POSTGRES_18: Same as POSTGRES but runs against a Postgres 18 pool; use it to compare a query's plan and timing on 18 vs POSTGRES (17), e.g. B-tree skip scan, uuidv7(), virtual generated columns - SQLSERVER: Temporary isolated schema, uses T-SQL syntax and features - MYSQL: Temporary isolated database, uses MySQL syntax and features - SQLITE: In-memory, lightweight, uses standard SQLite syntax Choose based on: - Your target deployment database - Specific SQL dialect features you need to test (e.g. T-SQL TOP vs LIMIT, IDENTITY vs SERIAL) | |
| correlationId | No | [TRACKING ONLY — does NOT preserve DB state, schema, or settings between calls.] Echo the correlationId from the previous ExoBench response so the ExoBench team can correlate your workflow for analytics. Omitted = a new one is created. Each tool call still provisions a fresh ephemeral DB from its own schema parameter. | |
| customDelimiter | No | LAST RESORT ONLY — Do NOT use this parameter unless all other approaches have failed. ExoBench has a highly robust, dialect-aware SQL script splitter that correctly handles: - Single-quoted string literals (including '' escape sequences) - Double-quoted identifiers (PostgreSQL, SQL Server) - Bracket-quoted identifiers (SQL Server: [col;name]) - Backtick-quoted identifiers (MySQL: `col;name`) - Dollar-quoted function bodies (PostgreSQL: $$ ... $$ and $tag$ ... $tag$) - Line comments (-- comment; still in comment) - Block comments (/* nested /* block */ comments */ supported for all dialects except MySQL) - MySQL hash comments (# comment; to end of line) - MySQL's -- comment rule (requires whitespace after the dashes) In the vast majority of cases, you do NOT need this parameter. The splitter handles all standard SQL constructs including stored procedures, triggers, and functions that contain semicolons within their bodies. If you encounter a GENUINE splitting failure (the schema executes incorrectly because a semicolon inside a construct was misinterpreted as a delimiter), you may set customDelimiter to a unique string that does NOT appear inside any of your SQL statements. The system will then split ONLY on that string — with NO intelligence about quoting or comments. You are fully responsible for ensuring the delimiter is truly unique in your script. Example: If your schema has a pathological construct that confuses the splitter, you could separate statements with '---SPLIT---' and set customDelimiter to '---SPLIT---'. DO NOT use this to work around issues that the splitter already handles. If you think the splitter is failing on a standard construct, it is almost certainly a bug — report it instead of using this escape hatch. | |
| exobenchServerVersion | No | ExoBench server version — copy the X.X.X from the [ExoBench server version: X.X.X] tag at the top of this tool's description. |