Repository navigation
fix(mcp-server-supabase): match Studio's notebook row_limit and clarify skip and blank-input messages - #593
Conversation
… and blank-input messages applyRowLimit now ignores semicolons inside literals via lexSql, and run_notebook caps returned rows at row_limit for SQL it does not rewrite (CTEs, comments). Cells skipped after an oversized result get their own reason instead of 'run result budget spent'. Blank notebook SQL and names get explicit validation messages. tools/list is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
barryroodt
left a comment
There was a problem hiding this comment.
Thanks for the detailed write-up and the live check! The lexer change, the new skip reason and the validation messages all look good.
One change please: the post-fetch rows.slice makes row_limit a hard cap, so select … limit 100 with row_limit: 5 now returns 5 rows. Studio treats row_limit as an auto-limit: an explicit LIMIT wins, and it never trims rows after the fetch (applyAutoLimit). The same notebook should return the same rows in both places.
Could you drop the slice, and cover the CTE case the way Studio does instead? It treats with … select as a select unless a write keyword (insert, update, delete, merge, into) appears outside literals. That also keeps the limit in SQL, so a big CTE doesn't hit the result budget.
…ike Studio Drop the post-fetch row slice, so an explicit LIMIT wins and rows are never trimmed after the fetch. Treat a query as a select unless insert, update, delete, merge or into appears outside literals, matching Studio's applyAutoLimit, so read-only CTEs are limited in SQL.
Thanks! Done in 1d6d70e.
One difference from Studio remains, and this PR doesn't change it: applyRowLimit skips the limit whenever the word limit or fetch appears anywhere, such as in a subquery or a string. Studio only checks for a trailing LIMIT or fetch first|next. So with u as (select … limit 1) select * from u gets the limit in Studio but not here. Happy to align that in this PR or a follow-up, whichever you prefer. FYKI: barryroodt |
barryroodt
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround, this is exactly what I was after! Reusing the lexer spans for the write keywords is a nice touch.
On the remaining limit/fetch difference: let's leave it as is for this PR. Erring toward not adding a limit is the safer side, and the result budget still bounds what comes back.
…ook-row-limit Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I merged Tests / test: all unit and integration tests pass, including every notebook test. The only failures are the 5 e2e tests ( Check Management API Types: the live v2 spec has changed since #607 (it now includes the Locally, the unit suite passes on this branch merged with current @barryroodt could you take another look and re-approve when you have a moment? The workflows for the new push are also waiting for maintainer approval. Thanks! |
🤖 I have created a release *beep* *boop* --- <details><summary>mcp-utils: 0.11.1</summary> ## [0.11.1](mcp-utils-v0.11.0...mcp-utils-v0.11.1) (2026-11-26) ### Bug Fixes * **mcp-ui:** shared project card for create-project and create-branch ([#578](#578)) ([efe189f](efe189f)) </details> <details><summary>mcp-server-supabase: 0.20.0</summary> ## [0.20.0](mcp-server-supabase-v0.19.0...mcp-server-supabase-v0.20.0) (2026-11-26) ### Features * **debugging:** add project issues DEBUG-311 ([#546](#546)) ([01f8021](01f8021)) * **mcp-server-supabase:** add optional schemas parameter to generate_typescript_types ([#592](#592)) ([7532f53](7532f53)) ### Bug Fixes * **debugging:** link docs once per issue in get_issues ([#610](#610)) ([74801d8](74801d8)) * **mcp-server-supabase:** detect import maps uploaded with a ./ prefix ([#591](#591)) ([6b8f4dc](6b8f4dc)) * **mcp-server-supabase:** keep a declined or cancelled SQL confirmation final ([#581](#581)) ([03afe8e](03afe8e)) * **mcp-server-supabase:** match Studio's notebook row_limit and clarify skip and blank-input messages ([#593](#593)) ([ad07f1b](ad07f1b)) * **mcp-server-supabase:** skip cost confirmation for $0 projects on clients without forms ([#608](#608)) ([50cfc37](50cfc37)) * **mcp-server-supabase:** stop reusing a removed import map on edge function redeploy ([#588](#588)) ([56093a6](56093a6)) * **mcp-ui:** shared project card for create-project and create-branch ([#578](#578)) ([efe189f](efe189f)) * **mcp:** confirm UPDATEs without WHERE that follow a comment and set a dollar-quoted value ([#612](#612)) ([468907a](468907a)) * **mcp:** confirm UPDATEs without WHERE that use inheritance syntax ([#565](#565)) ([687b3ee](687b3ee)) * **mcp:** confirm UPDATEs without WHERE when a column name ends in where ([#557](#557)) ([57fa34b](57fa34b)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
applyRowLimit now ignores semicolons inside literals via lexSql, and treats a read-only CTE (
with … select) as a select, the same way Studio's applyAutoLimit does. Cells skipped after an oversized result get their own reason instead of 'run result budget spent'. Blank notebook SQL and names get explicit validation messages. tools/list is unchanged.What kind of change does this PR introduce?
Bug fix. There are no changes to
tools/list: tool names, descriptions, and input/output schemas are byte-identical.What is the current behavior?
Fixes #595
row_limitis silently ignored for common SELECT shapes.applyRowLimitcounts every;with a regex over the raw text, including ones inside string or$$literals, and it skips every CTE, including read-only ones that Studio limits. Each cell below has row_limit 5 (the$$cell has row_limit 3):select g from generate_series(1,50) gselect g, 'a;b' as s from generate_series(1,50) gwith s as (select g from generate_series(1,50) g) select * from sselect g, $$a;b$$ as body from generate_series(1,20) gAfter an oversized cell, later cells are reported as
"run result budget spent", even though about 998 KB of the budget was never used. The cell ran fine on its own.create_notebookwith whitespace-only SQL (" ") fails withToo small: expected string to have >=1 characters, because the schema trims before checking length. That message is misleading for a 3-character input.What is the new behavior?
applyRowLimitlexes the SQL with the existinglexSql, so only;in code spans separates statements. A single SELECT with;inside a string, E-string, quoted identifier or dollar-quoted body now getslimit N. Unterminated SQL is returned unchanged.withcounts as a select unless a write keyword (insert,update,delete,merge,into) appears in its code, outside literals and quoted identifiers. This mirrorsapplyAutoLimitinapps/studio/data/sql/utils.ts. The limit stays in SQL, so a large read-only CTE no longer fills the run's result budget.row_limitstays an auto-limit: as in Studio, an explicit LIMIT wins, and rows are never trimmed after the fetch.select … limit 100with row_limit 5 returns 100 rows, and SQL that is left as written (for example, with comments) returns all its rows. All other conservative rules are unchanged.runQueryCellreturns an explicitoversizedflag."an earlier cell's result was too large for this run"."run result budget spent"is kept for real exhaustion by returned rows.create_notebooknow returnsSQL must not be empty or only whitespace.andNotebook name must not be empty or only whitespace.The published JSON schema is identical, because these are only custom messages on the existing.trim().min(1).How to Review
Review area
packages/mcp-server-supabase/src/tools/notebook-cells.tsapplyRowLimit, non-code spans are replaced with a space. That code-only text is used for the statement count and for the CTE write-keyword check.isSelectLikereplaces the old^selecttest.^selectis unchanged, and^withpasses only withoutinsert|update|delete|merge|intoin code.limit/fetchword andlimit > 0checks are untouched.Next review area
packages/mcp-server-supabase/src/tools/notebook-tools.tsrunQueryCellreturns rows exactly as the database returned them. There is no post-fetch trimming.budgetSkipReasonswitches only after anoversizedresult. Look at theBudgetSkipReasonunion inCellResult.Next review area
packages/mcp-server-supabase/src/platform/types.tsnewNotebookSqlSchemaandcreateNotebookOptionsSchema.name, only the custom.min(1, { message })text was added.Tests
src/tools/notebook-cells.test.ts:'a;b',$$a;b$$;,$fn$ x; y $fn$,"a;b", an E-string with an escaped quote and;, and read-only CTEs, includingWITH RECURSIVE.$$body, and longer words such asupdated_atanddeleted, do not block the limit.select … into,for update, or use a data-modifying CTE (with d as (delete … returning *) select …). CTEs with a limit or comments, an unterminatedselect 'a;b, andselect 'a'; select 2are also unchanged.src/server.notebooks.test.ts:limit 3;and returns 3 rows.select … limit 6with row_limit 3 is sent as written and returns 6 rows. A---commented cell is sent as written and returns all its rows.ResultTooLargeError) expect the new skip reason. The genuine-exhaustion tests still expect"run result budget spent".path, and nothing is saved.Review questions
tools/listis unchanged. The new skip-reason string appears only inside the run result payload, which is a wrapped string in the output schema.;inside a literal, and a read-only CTE. Rows are returned as the database returned them.Verification
From the repo root, on this branch:
The new server test fails when the old post-fetch
rows.sliceis restored: the explicit-limit and commented cells come back trimmed to 3 rows.Live check: with the
--httpserver built from this branch, I ran a notebook against a real project (row_limit 5 on each query cell).The change was written with AI assistance (Claude Code). I reviewed the diff and re-ran the commands above.
Additional context
Remaining difference from Studio, unchanged by this PR: Studio only skips the auto-limit when the query ends in a LIMIT or contains
fetch first|next.applyRowLimitskips on anylimitorfetchword, including one inside a subquery or a string. Those shapes still return more rows here than in Studio. Commented SQL is left as written in both places, so it can still exceed the run budget.Out of scope: argument validation errors (including the new messages) still arrive inside the shared raw
ZodErrorwrapper from@supabase/mcp-utils. Changing that affects every tool and is better as its own PR.Generated with Claude Code