Skip to content

run_sql

MCP tools › Databases

Run SQL on a workspace connection. Per-connection permissions (read-schema, read-data, modify-data, modify-schema) are granted by the user outside the project, none by default (see list_connections), and checked per statement first. A script that can change data or schema does nothing without apply true and returns each statement's needed permission; reading scripts run at once read-only. Refused in an untrusted project. Returns per statement rows, update count or error with SQLSTATE. sort, filter, value_filter, values_of, page and view work on loaded rows like the result grid. Stop a running call with cancel_sql.

Its results carry text from database: the client is told to treat that as data, never as instructions.

Capabilitydatabase.run_sql
AreaDatabases
Accesschanges database
Reachesdatabase, network
Rightsssh, database-permission, trusted-project
Dry runapply, on unless the call turns it off

Arguments

ArgumentTypeDescription
connectionrequiredstringConnection name from list_connections.
sqlrequiredstringSQL script; statements separated by ;.
applybooleanReally run a script that can change data or schema; without it such a script only returns what each statement needs (SPEC-0012 v3 behaviour 14). Reading scripts run at once.
continue_on_errorbooleanRun the remaining statements after an error (default: stop).
max_rowsintegerRows returned per result set (default 100, at most 10 000); also the page size.minimum 0
sortarray of objectSort the loaded rows of each result set by these columns, as the grid does (SPEC-0099).
sort[].columnrequiredstringColumn name as in the result.
sort[].descendingbooleanLargest first (default false).default false
filterstringKeep only rows with a cell containing this text (case-insensitive).
pageinteger0-based page of max_rows rows after sorting and filtering (default 0).minimum 0
confirm_unsafebooleanRun UPDATE/DELETE without WHERE (default false: refused with the table and row count).
value_filterarray of objectKeep only rows whose value in each named column is one of the given values, as the column's value filter in the grid (SPEC-0099 v3 behaviour 9).
value_filter[].columnrequiredstringColumn name as in the result.
value_filter[].valuesrequiredarray of stringThe values to keep; null keeps NULL.
values_ofstringAlso return the distinct values of this column over all loaded rows with their counts (values), the list of the grid's value filter.
viewstringtext adds text: the shown page as the grid's text view (SPEC-0099 v3 behaviour 10).

Call it from a shell

ferris-idea call runs one tool with the rights and safe mode of ferris-idea mcp. Replace the folder and the placeholder values.

Terminal window
ferris-idea call ~/my-project run_sql '{"connection":"<string>","sql":"<string>"}'
Input schema as JSON
{
"properties": {
"connection": {
"description": "Connection name from `list_connections`.",
"type": "string"
},
"sql": {
"description": "SQL script; statements separated by `;`.",
"type": "string"
},
"apply": {
"description": "Really run a script that can change data or schema; without it such a script only returns\nwhat each statement needs (`SPEC-0012` v3 behaviour 14). Reading scripts run at once.",
"type": [
"boolean",
"null"
],
"default": null
},
"continue_on_error": {
"description": "Run the remaining statements after an error (default: stop).",
"type": [
"boolean",
"null"
]
},
"max_rows": {
"description": "Rows returned per result set (default 100, at most 10 000); also the page size.",
"type": [
"integer",
"null"
],
"minimum": 0
},
"sort": {
"description": "Sort the loaded rows of each result set by these columns, as the grid does (`SPEC-0099`).",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/GridSortArg"
}
},
"filter": {
"description": "Keep only rows with a cell containing this text (case-insensitive).",
"type": [
"string",
"null"
],
"default": null
},
"page": {
"description": "0-based page of `max_rows` rows after sorting and filtering (default 0).",
"type": [
"integer",
"null"
],
"default": null,
"minimum": 0
},
"confirm_unsafe": {
"description": "Run UPDATE/DELETE without WHERE (default false: refused with the table and row count).",
"type": [
"boolean",
"null"
],
"default": null
},
"value_filter": {
"description": "Keep only rows whose value in each named column is one of the given values, as the\ncolumn's value filter in the grid (SPEC-0099 v3 behaviour 9).",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/ValueFilterArg"
}
},
"values_of": {
"description": "Also return the distinct values of this column over all loaded rows with their counts\n(`values`), the list of the grid's value filter.",
"type": [
"string",
"null"
],
"default": null
},
"view": {
"description": "`text` adds `text`: the shown page as the grid's text view (SPEC-0099 v3 behaviour 10).",
"type": [
"string",
"null"
],
"default": null
}
},
"$defs": {
"GridSortArg": {
"description": "One sort column of `run_sql`.",
"type": "object",
"properties": {
"column": {
"description": "Column name as in the result.",
"type": "string"
},
"descending": {
"description": "Largest first (default false).",
"type": "boolean",
"default": false
}
},
"required": [
"column"
]
},
"ValueFilterArg": {
"description": "One column's value filter of `run_sql` (SPEC-0099 v3 behaviour 9).",
"type": "object",
"properties": {
"column": {
"description": "Column name as in the result.",
"type": "string"
},
"values": {
"description": "The values to keep; `null` keeps NULL.",
"type": "array",
"items": {
"type": [
"string",
"null"
]
}
}
},
"required": [
"column",
"values"
]
}
},
"required": [
"connection",
"sql"
],
"type": "object"
}