Repository navigation
feat: make the SQL confirmation classifier swappable, with a regex fallback - #454
barryroodt wants to merge 11 commits into
Conversation
Coverage Report for CI Build 37011856462Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.1%) to 97.164%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
…llback Adds the SqlConfirmationClassifier interface at ./sql-confirmation with regexClassifier (the default, unchanged regex logic) and withFallback, which falls back on an 'unavailable' failure or a SqlClassifierUnavailableError. Hosts set elicitation.confirmation.classifier for execute_sql and apply_migration. Only undefined skips confirmation; out-of-contract results, rejections and unavailable/timeout/crashed failures stop the call, and oversized SQL asks for confirmation with its own wording.
A primary result that is an object but not exactly { failure: <known kind> }
(unknown kind, extra keys, inherited failure, arrays) now rejects instead of
reaching the fallback. The tool validator shares the same check.
When a resend carries valid state this server issued for the same tool, project, name and query hash, a decline, a cancel or no answer never runs the SQL, even if the classifier now returns undefined (for example withFallback after the primary sheds). Decline and cancel keep their result; no answer re-prompts with a neutral reconfirm line. An accepted bound resend still runs once, as on main.
F1: keep only the unanswered resend row and assert two classifications. F2: keep the injected-classifier decline/cancel test as primary and cut the spied loop back to its no-answer precedence row. F3: drop the mockClear and not-called classifier assertions. F4: fold the abort-signal test into the abort-during-classification test. F5: drop the isDestructiveSql spy and classifier call count.
F6: fail any second classification of an accepted bound resend instead of counting calls, and cut to the destructive and oversized rows. F7: give the fallback a distinct failure so the test proves the fallback's result is returned, and rename it to match.
F8: keep the regexClassifier test as the primary proof for the exported ./sql-confirmation entry point, cut to one destructive and one non-destructive row. F9: name and comment the fallback test as the documented withFallback(parser, regexClassifier) recipe from the server.ts docs.
aeae0b6 to
4683923
Compare
|
Closing this in favour of a stack on The interface here is the starting point of #582, which changes it in three small ways (a new error class, |
…on final (#581) First PR in the stack replacing #454. Base: `main` (1/5). ## Why this changes When `execute_sql` or `apply_migration` asks for confirmation, the client sends a second tool call with the server-issued state and the user’s answer. Today, only **Accept** skips a second SQL classification. If the user clicks **Decline** or **Cancel**, the server checks the SQL again before it honors that answer. The current regex always gives the same answer for the same SQL. The next PR makes the classifier replaceable, so a parser could flag a query on the first call and a fallback could clear it on the second. Today, that would run SQL the user just declined. #455 added observability and a test that captures this behavior. ## What changes The server checks that the signed state is valid and unexpired, then matches it to the current tool, project ID and exact SQL text. For `apply_migration`, the migration name must also match. | Answer for a matching prompt | What the server does | | --- | --- | | Decline or Cancel | Returns the user’s answer immediately. It skips classification and stops before executing the SQL. | | No answer | Asks again, even if the classifier now clears the SQL. In that case, the prompt says “This SQL was flagged for confirmation earlier and still needs your approval.” | | Accept | Runs the SQL, as it does today. | A decline ends that call. The client can still send **Accept** for the same prompt before the state expires. If the client changes the SQL, the earlier answer doesn’t apply to the new query. The server classifies it as before. ## Where to review Start with `checkDestructiveSqlConfirmation`, which decides when to classify the SQL. The updated tests show what happens when the classifier changes its answer or throws after the first prompt. [SQL confirmation handling](https://github.com/supabase/mcp/blob/92be4920a465b507d2efc5196cff252eb9323126/packages/mcp-server-supabase/src/tools/database-operation-tools.ts#L67-L152) · [PR diff and tests](https://github.com/supabase/mcp/pull/581/files) Refs AI-1338
This makes the SQL confirmation classifier swappable, and falls back to the regex classifier when the plugged-in one can't load. I want to try Jev as a classifier later, and before that we need a clean way to plug one in (#426's AST parser included). Jev itself is out of scope here, this PR only adds the interface and the fallback.
With no host option set, behaviour matches
mainapart from two things: a request that's aborted while its SQL is being classified no longer runs the SQL, and a decline or cancel resend now returns before the classifier runs.Once the server has asked for confirmation on a query, a resend that carries a decline, a cancel or no answer never runs the SQL, even if the classifier now returns nothing, which matters because with a fallback the AST can flag a query and then the regex finds nothing on the resend.
How #426 (and later Jev) plugs in
withFallbackhands the SQL toregexClassifierwhen the primary resolves{ failure: 'unavailable' }or throwsSqlClassifierUnavailableError. #426's AST classifier doesn't do either yet. Today it throws a raw error when libpg-query can't load, so this setup would fail closed instead of falling back. When #426 rebases, that load failure needs to throwSqlClassifierUnavailableError(or resolve{ failure: 'unavailable' }).