Skip to content

feat: bound run_notebook cost - #511

Merged
barryroodt merged 12 commits into
mainfrom
feat/bound-run-notebook-cost
Nov 5, 2026
Merged

barryroodt merged 12 commits into
mainfrom
feat/bound-run-notebook-cost

Conversation

@barryroodt

@barryroodt barryroodt commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This puts limits on how much one run_notebook call can do (AI-1353). A notebook with more than 50 query cells is now refused before any prompt or query runs, and the agent is told to split it. 50 is a starting value. Studio has no cell limit today.

The run's existing ~1 MB result budget now stops execution. Once it's spent, later query cells come back as skipped and don't run. A cell whose result is too big for what's left spends the rest of the budget, so the cells after it are skipped too (other errors don't spend budget). Log cells get the remaining budget as max_result_bytes, same as database cells, through a new optional field on QueryLogsOptions. Hosted honours it (supabase/platform#41193). The local server keeps calling the public logs API without it and relies on the existing post-run size check.

@supabase/mcp-server-supabase/platform now exports ResultTooLargeError. A host that stops reading at max_result_bytes throws an error with that name, and run_notebook treats it like its own size check. supabase/platform#41193 throws it from both bounded reads, so this applies on hosted once the pin includes this PR.

A database cell runs without confirmation only when every statement is a plain read (select, values, table, show, explain, or a with that doesn't insert/update/delete/merge), and those cells run read-only. Everything else, including call, do, transaction control and set, goes through confirmation and runs in the server's normal mode once accepted. A select that calls a writing function still runs without a prompt and may fail at the database. This came out of the review of supabase/platform#38799.

If the client cancels the request, no further cells run. The cell already in flight finishes. A run-level deadline is a follow-up in AI-1415.

@coveralls

coveralls commented Nov 3, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 42036110285

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.2%) to 98.02%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 5 uncovered changes across 2 files (304 of 309 lines covered, 98.38%).
  • 3 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
packages/mcp-server-supabase/src/tools/notebook-tools.ts 112 109 97.32%
packages/mcp-server-supabase/src/tools/destructive-sql.ts 107 105 98.13%
Total (4 files) 309 304 98.38%

Coverage Regressions

3 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
packages/mcp-server-supabase/src/management-api/index.ts 2 96.0%
packages/mcp-server-supabase/src/tools/destructive-sql.ts 1 98.31%

Coverage Stats

Coverage Status
Relevant Lines: 6095
Covered Lines: 6000
Line Coverage: 98.44%
Relevant Branches: 1279
Covered Branches: 1228
Branch Coverage: 96.01%
Branches in Coverage %: Yes
Coverage Strength: 254.8 hits per line

💛 - Coveralls

@barryroodt
barryroodt marked this pull request as ready for review November 4, 2026 08:38
@barryroodt
barryroodt requested a review from a team as a code owner November 4, 2026 08:38
Stop after cancellation and charge named size-limit errors to the remaining run budget.
@Rodriguespn Rodriguespn added the publish-preview Runs `publish-preview` workflow to publish preview packages via https://pkg.pr.new/ label Nov 5, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/@supabase/mcp-server-postgrest@ed2ac1d
pnpm add https://pkg.pr.new/@supabase/mcp-server-supabase@ed2ac1d
pnpm add https://pkg.pr.new/@supabase/mcp-utils@ed2ac1d

commit: ed2ac1d

@Rodriguespn Rodriguespn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for addressing my comments. Left some more here. After that, I think we're aligned with our expectations for Notebooks through MCP.

Note: We'll have to update https://github.com/supabase/platform/pull/41193 to reflect these changes later. Also, left another comment on #514 to change the error message when the notebook has more than 50 cells

@Rodriguespn Rodriguespn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, thanks for turning these around. I checked it against what we agreed on the
call
.

The part of the third bullet point that isn't done here is counting the work the service does (a timed-out cell is still charged 0) and stopping pg-meta/Postgres once the 1 MB read limit is hit. I'm fine leaving both to a follow-up.
AI-1415 only covers wall time today (run deadline plus a per-cell statement timeout), so could we add these two to it, or open a separate ticket?

Also, a rebase and conflict resolution should fix the CI.

Nit, optional: "Later cells were skipped." is still added when the oversized cell is the last one.

…ok-cost

# Conflicts:
#	packages/mcp-server-supabase/src/tools/destructive-sql.ts
@barryroodt

Copy link
Copy Markdown
Contributor Author

Thanks Pedro! I've widened AI-1415 to cover both: counting the work errored cells cause, and stopping Postgres once the 1 MB read limit is hit. CI is green after merging main, and the last-cell wording nit is fixed in a follow-up commit.

@barryroodt
barryroodt merged commit e90d110 into main Nov 5, 2026
6 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Nov 5, 2026
barryroodt added a commit that referenced this pull request Nov 5, 2026
Stacked on #511.

Adds an optional `cells` list (cell ids) to `run_notebook`, so an agent
can re-run just the cell it fixed instead of the whole notebook. Leaving
it out runs the whole notebook as before.

Selected cells run in notebook order. There's no dependency resolution,
so the agent should include any setup cell it needs. Duplicate ids are
de-duped. Unknown or non-query ids are skipped, and each one comes back
in the results as `{ cell_id, status: 'skipped', reason }` so the agent
can spot a typo or stale id. An empty list, or a selection with no
matching query cell, fails as a `ToolCallerError` before any prompt or
query runs.

The cell cap, result budget, confirmation prompt and `notebook_run`
counts all apply to the selected cells, and skipped ids don't count
toward any of them. An approval is tied to the selection it was given
for, so approving one set of cells doesn't approve a different one.
Selecting more than 50 query cells is refused with a message that tells
the agent to call `run_notebook` again with the next 50 or fewer ids.

Closes AI-1402
barryroodt pushed a commit that referenced this pull request Nov 5, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>mcp-server-supabase: 0.16.0</summary>

##
[0.16.0](mcp-server-supabase-v0.15.0...mcp-server-supabase-v0.16.0)
(2026-11-05)


### Features

* bound run_notebook cost
([#511](#511))
([e90d110](e90d110))
* **mcp-server-supabase:** run selected notebook cells
([#514](#514))
([8d04248](8d04248))
* **notebooks:** add delete_notebook tool with elicitation confirmation
([#510](#510))
([f36f74a](f36f74a))
* **notebooks:** enable create_notebook and run_notebook tools
([#509](#509))
([addc4e5](addc4e5))


### Bug Fixes

* **feedback:** accept null project_id and surface the feedback length
limit ([#521](#521))
([994f56c](994f56c))
* hint agents to re-copy malformed project refs
([#522](#522))
([0c650bf](0c650bf))
* **notebooks:** return caller errors for client-caused notebook
refusals ([#512](#512))
([5f0d393](5f0d393))
* **pg-meta:** report partition FKs once and add partition_of to
list_tables ([#508](#508))
([2c7fa82](2c7fa82))
* **pg-meta:** return complete check expressions for NOT VALID and NO
INHERIT constraints ([#517](#517))
([c54bb40](c54bb40))
* **sql:** skip destructive confirmation for planner-only EXPLAIN
([#519](#519))
([95745e5](95745e5))
* tolerate non-URL edge function paths in api platform
([#438](#438))
([00d07a4](00d07a4))
</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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

publish-preview Runs `publish-preview` workflow to publish preview packages via https://pkg.pr.new/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants