Skip to content

run_notebook: row_limit is silently ignored for CTEs, comments, and ; inside literals #595

Done

Description

@officialbidisha

run_notebook returns every row for database cells whose SQL applyRowLimit does not rewrite. That covers CTEs, SQL with comments, and SQL with ; inside a string or $$ body. Nothing in the result says the limit was skipped, and row_limit is a required field, so agents treat it as a hard cap.

Repro (row_limit 5 on each cell):

SQL Rows returned
select g from generate_series(1,50) g 5
select g, 'a;b' as s from generate_series(1,50) g 50
with s as (select g from generate_series(1,50) g) select * from s 50
select g from generate_series(1,50) g -- trailing 50
select g, $$a;b$$ as body from generate_series(1,20) g (row_limit 3) 20

Cause: applyRowLimit counts every ; with a regex over the raw text, including ones inside literals. It also deliberately skips CTEs and commented SQL, and nothing truncates rows after the fetch.

Two related problems:

  • After an oversized cell, later cells are skipped with reason "run result budget spent", even though about 998 KB of budget was unused. The skip itself is documented; only the reason text is wrong.
  • create_notebook with whitespace-only SQL (" ") fails with "Too small: expected string to have >=1 characters", because the schema trims before checking. That message is misleading for a 3-character input.

Proposed fix:

  • Lex the SQL with the existing lexSql so ; inside literals doesn't count as a statement break.
  • Cap the returned rows at row_limit after the fetch.
  • Use a distinct skip reason after an oversized cell.
  • Add explicit messages for blank SQL and blank notebook names.

None of this changes tools/list.

Environment: @supabase/mcp-server-supabase 0.19.0 (main at efe189f), local --http transport, Claude Code client.

A fix with tests is open in #593.

Activity

  1. added
    bug
    on Nov 22, 2026
  2. changed the title [-]`run_notebook` returns every row for database cells whose SQL `applyRowLimit` does not rewrite.[/-] [+]run_notebook: row_limit is silently ignored for CTEs, comments, and `;` inside literals[/+] on Nov 22, 2026
  3. added a commit that references this issue on Nov 26, 2026
    ad07f1b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions