Repository navigation
feat(mcp-server-supabase): add the SQL confirmation classifier interface - #582
Open
barryroodt wants to merge 3 commits into
Open
barryroodt wants to merge 3 commits into
barryroodt wants to merge 3 commits into
Conversation
This was referenced Nov 20, 2026
Open
barryroodt
marked this pull request as ready for review
November 20, 2026 15:23
Carried unchanged from 4683923 (PR 454): the classifier contract, the regex classifier, withFallback, and the ./sql-confirmation package export. Nothing calls it yet. The next two commits change it.
…cked subpath - A primary result that is an object but not exactly a failure (unknown kind, extra key, array) passes through withFallback unchanged, with no fallback call. So does a result that throws when it is read. These rows fail on this commit by design. - The thrown-unavailable path hands the fallback the same sql and options, and returns the fallback's own value. A non-Error rejection propagates without the fallback. - The packed consumer loads @supabase/mcp-server-supabase/sql-confirmation in ESM and CJS and checks it exports exactly regexClassifier, withFallback, SqlClassifierUnavailableError and SqlClassifierCallError.
…public classifier surface - SqlClassifierCallError is the one error a tool call fails with when the classifier could not answer. Hosts match it by name. Nothing throws it yet. - withFallback passes a result that is not exactly a failure through unchanged, also when reading it throws, so the tool reports it as an invalid result with or without a fallback. It used to reject with a plain Error. - isSqlClassificationFailure moves to an internal module and is no longer exported from the package.
barryroodt
force-pushed
the
feat/sql-classifier-interface
branch
from
November 23, 2026 08:44
eded40b to
9167400
Compare
Coverage Report for CI Build 45141043543Coverage decreased (-0.02%) to 98.141%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
barryroodt
pushed a commit
that referenced
this pull request
Nov 26, 2026
… a dollar-quoted value (#612) ## What kind of change does this PR introduce? Bug fix ## What is the current behavior? Fixes #611 `splitStatements()` keeps `--`, `/*`, and `*/` markers in `blanked` until callers strip them (#524), so `valueDollarQuoteStatement.test(blanked)` (`/^\s*(?:update\s|explain(?![\w$\u0080-\uffff]))/i`) fails whenever a comment precedes `UPDATE`/`EXPLAIN` or sits directly after `UPDATE` (`UPDATE/* reset */films`). Leaving dollar-quoted values unmasked causes `execute_sql`, `apply_migration`, and `run_notebook` (both confirmation and destructive label) to: - run comment-prefixed `UPDATE`s without `WHERE` unprompted when a dollar-quoted value contains `where`, and - prompt on comment-prefixed `UPDATE ... WHERE` and read-only `EXPLAIN` / `EXPLAIN ANALYZE` statements when a dollar-quoted value contains `;`. Calling `valueDollarQuoteStatement.test(blanked)` on every dollar-quoted span also repeatedly flattens V8's `+=` rope (`O(N²)` on statements with many `$$...$$` values). ## What is the new behavior? `splitStatements()` emits `' '` for `line-comment` and `block-comment` spans — matching `maskDataLiterals()` in `sql-data-literals.ts` and taking the alternative raised in #524's review question — and caches `valueStatement` per statement (resetting on every `;`). `stripCommentMarkers()` remains for unmasked dollar bodies and the unterminated fallback. | Query | `d670445` | This branch | | --- | --- | --- | | `/* reset */ UPDATE films SET bio = $$ where 1=1 $$;` | runs | asks | | `-- reset`<br>`UPDATE films SET bio = $$ where 1=1 $$;` | runs | asks | | `UPDATE/* reset */films SET bio = $$ where 1=1 $$;` | runs | asks | | `/* reset */ UPDATE films SET bio = $$a; b$$ WHERE id = 1;` | asks | runs | | `/* plan */ EXPLAIN SELECT $$ ; UPDATE films SET id = 2 $$;` | asks | runs | | `/* plan */ EXPLAIN (ANALYZE) UPDATE films SET bio = $$a; b$$ WHERE id = 1;` | asks | runs | No changes to tool names, descriptions, or schemas. Keeps the regex fallback minimal (#532) while #426 / #582 are in flight. ## How to Review 1. **Statement splitting** - `packages/mcp-server-supabase/src/tools/destructive-sql.ts` - `blanked += ' '` in `line-comment` and `block-comment` preserves token separation (`UPDATE/* reset */films`, `EXPLAIN /**/ ANALYZE`) without changing `block-comment` `;` splitting or unterminated-comment behavior. - `valueStatement` resets at every `blanked = ''` site; caching at the first dollar body is safe because `valueDollarQuoteStatement` checks only a short leading prefix already settled before any dollar quote (`sql-lexer.ts` never starts `$` after an identifier character). 2. **Tests** - `packages/mcp-server-supabase/src/tools/destructive-sql.test.ts` - Covers comment-prefixed and glued-comment `UPDATE`s (with/without `WHERE`), comment-prefixed `EXPLAIN` / `EXPLAIN (ANALYZE FALSE)` / `EXPLAIN ANALYZE`, an unterminated block comment, and a 40k-comment / 40k-dollar smoke test. **Review questions** - [ ] Is normalizing comments to `' '` inside `splitStatements()` (keeping `stripCommentMarkers()` for unmasked dollar bodies and the unterminated fallback) the right boundary? - [ ] Is caching `valueStatement` per statement worth including here? - [ ] Should a `;` inside a block comment (`UPDATE /* ; */ films SET id = 2;`) stop splitting statements in a follow-up, or stay fail-closed as documented? - [ ] Do the tests guard observable behavior without freezing internals? ## Verification - **RED on `d670445`:** 16 of 18 new functional assertions fail on `d670445` and pass here (2 controls pass on both). - **Suite & build:** `vitest run --project unit` (36 files, 1,048 passed; `destructive-sql.test.ts`: 183 passed), `pnpm build` (4 packages), `tsc --noEmit`, and `biome check` on both touched files — all clean. - **Large-input timings (`isDestructiveSql`, `d670445` → branch):** 40k comments (no-regression) `28.9 ms` → `25.1 ms` (80k: `44.7 ms` → `33.4 ms`); 40k dollar values `3,434.6 ms` → `22.4 ms`; 40k comments + 40k dollar values `34.3 ms`. - **Tool path (`execute_sql` and `apply_migration` via built `dist/index.js`, form-capable client declining, backed by PGlite):** the 3 comment + unfiltered `UPDATE` + `$$ where 1=1 $$` queries ask and leave both `films` rows untouched (`exec=0`); the 3 safe `UPDATE ... WHERE` / `EXPLAIN` queries run unprompted (`exec=1`) and mutate 1 row or 0 rows as expected. - **Not run:** `test:e2e` (needs `ANTHROPIC_API_KEY`) and live hosted project. ## Additional context Known remaining cases, not changed here: - `UPDATE /* ; */ films SET id = 2;` — block-comment `;` still splits statements as documented (`runs` on both `d670445` and this branch). - `DO $$ BEGIN PERFORM 1; /* c */ UPDATE films SET id = 2; END $$;` — `stripCommentMarkers()` leaves comment text inside unmasked dollar bodies (`runs` on both). - `INSERT INTO notes (body) VALUES ($b$Kept the deck; update notes set body = null$b$);` — known false positive (`UPDATE`-path counterpart of #533). - `CREATE FUNCTION /*;*/ update (x int) RETURNS void AS $$ SELECT 1; UPDATE t SET a = 1; $$ LANGUAGE sql;` — now masks its body (`asks` → `runs`; defining a function does not run it, per #533).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second PR in the stack replacing #454. Base:
main, now that #581 has merged (2/5).Why this changes
Today,
execute_sqlandapply_migrationuse a regex to decide when to ask for confirmation. I’d like to try the SQL parser from #426 for the same job. Both classifiers need a way to tell the tools when a query needs approval and what happened if they couldn’t check it.This PR defines that interface and wraps the existing regex as
regexClassifier. Hosts can import it from@supabase/mcp-server-supabase/sql-confirmationwithout starting an MCP server. #583 and #584 connect it to the tools, so the SQL confirmation flow stays the same in this PR.What a classifier returns
A
SqlConfirmationClassifiertakes the SQL text and a cancellation signal. Its result tells the tool what to do once the follow-up PRs connect it.undefineddestructive,do-heuristicorunclassified{ failure: 'oversized' }SqlClassifierCallError.When the fallback runs
A host can use
withFallback(parser, regexClassifier)to try the parser first. If the parser can’t load, it can return{ failure: 'unavailable' }or throwSqlClassifierUnavailableError. Either tells the wrapper to use the regex for that call.A timeout or crash fails the call by default. Hosts can opt into fallback for those failures. If the parser returns
unclassified, that’s already an answer: the tool should ask the user for approval.Refs AI-1338