Skip to content

feat(mcp-server-supabase): route execute_sql and apply_migration through one SQL classify step - #583

Open
barryroodt wants to merge 2 commits into
feat/sql-classifier-interfacefrom
feat/sql-classify-step
Open

barryroodt wants to merge 2 commits into
feat/sql-classifier-interfacefrom
feat/sql-classify-step

Conversation

@barryroodt

@barryroodt barryroodt commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Third PR in the stack replacing #454. Base: #582 (3/5).

Why this changes

#582 defined how a SQL classifier tells a tool whether to ask for confirmation. This PR connects that classifier to execute_sql and apply_migration. Hosts can set elicitation.confirmation.classifier once for both tools. The existing regex stays the default.

In #454, each tool group could omit the classifier, which made it easy to miss run_notebook when it was added. The server now creates one shared classification step and requires it when building the database tools. #584 connects notebooks to the same step.

When the tools ask for confirmation

Classifier result What the tool does
undefined Runs the SQL on a first call. If the client returns an earlier matching prompt without an answer, it asks again.
A confirmation reason or oversized Asks for approval and tells the user why.
unavailable, timeout, crashed, an invalid result or an exception Stops before running the SQL. The client and host get a SqlClassifierCallError with a fixed message. The original error stays out of logs and traces.

When the user answers a matching prompt, #581’s behavior still applies. Accept runs the SQL. Decline or Cancel ends the call. All of these answers skip classification.

Cancelling the request while classification is running takes a different path. Once the classifier settles, the tool propagates the cancellation and records tool_error. Hosts that count tool errors will count these cancellations too. A custom classifier must handle its own timeout because the server can keep waiting indefinitely.

Rollout

Wait for #585 before releasing this change or enabling a custom classifier on a host. #584 brings run_notebook onto the shared classifier, and #585 lets hosts see when classification failed.

Refs AI-1338

Tests for `elicitation.confirmation.classifier` on execute_sql and
apply_migration, at the public option with real tool calls. They fail on
this commit by design: the option is not wired yet.

- One row per classifier outcome, per tool, on the first call and on an
  unanswered resend: the four reasons ask; `unavailable`, `timeout`,
  `crashed`, results outside the contract, a result whose inspection throws
  and every throw stop the call.
- Every stopped call carries the error name SqlClassifierCallError. Nothing
  from the classifier's own error or result reaches the client, and the
  error the host's onToolCall gets has no cause.
- A result whose failure kind changes while it is read (a getter that
  answers differently after n reads, n = 0 to 12, bare and through
  withFallback) never puts its text in the client result or the host error.
- Each confirmation reason's first prompt line holds its own keyword and
  none of the others'.
- The state-error path (state for another tool, other SQL or another
  project): cleared SQL runs, and a classifier failure replaces the state
  error.
- The classifier is not called on an accepted, declined or cancelled resend,
  when confirmation is not enabled for the tool, for a client that cannot
  elicit, or on a read-only server.
- A request aborted while the classifier is pending does not run the SQL,
  whether the classifier then resolves or rejects.
- The tests that spied on isDestructiveSql now pass a classifier through the
  option, with SQL the regex clears.
- The packed consumer type check passes a classifier as the server option.

Carried from 4683923 (PR 454) and merged with the accept-only tests.
…y step

execute_sql and apply_migration now ask one classify step whether SQL needs
confirmation. The server builds the step once from the new
`elicitation.confirmation.classifier` option (default: the regex classifier)
and getDatabaseTools requires it, so a tool group cannot be wired without it.

The step checks the classifier's result at runtime. Only `undefined` skips
confirmation; a reason or `oversized` asks, each with its own first prompt
line. `unavailable`, `timeout`, `crashed`, a result outside the contract, a
result that throws when read, or any rejection fails the call with a
SqlClassifierCallError, and the SQL does not run. The error carries nothing
of the classifier's own error and has no cause. A failure kind is read once
and checked against the fixed kinds before it is used, so a result that
changes while it is read cannot put its text in the message. A cancelled
request rethrows its abort.

The rules from the accept-only change hold: a decline or cancel returns before
any classification, and an accepted resend runs without one.

The one test that builds the tool group by hand passes the step here, since
this commit makes it a required argument.

Carried from 4683923 (PR 454): the reason maps, the runtime validation and the
prompt lines.
@barryroodt
barryroodt force-pushed the feat/sql-classify-step branch from 27619f2 to 0162527 Compare November 23, 2026 08:44
@barryroodt
barryroodt force-pushed the feat/sql-classifier-interface branch from eded40b to 9167400 Compare November 23, 2026 08:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant