Repository navigation
feat: add run_notebook with destructive SQL confirmation - #445
Conversation
Coverage Report for CI Build 39609416938Coverage increased (+0.2%) to 97.344%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Logs notebooks are a primary observability use case, so run_notebook is now offered when either the database or debugging feature can run cells. Database cells return a per-cell error without the database feature, as log cells already do without debugging. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| // Use the same SQL heuristic as execute_sql, but only for cells | ||
| // this server can execute. Check before running even the first cell. | ||
| const destructiveCells = queryCells.filter( | ||
| (cell) => | ||
| !readOnly && | ||
| database && | ||
| isPrimaryDatabaseCell(cell, project_id) && | ||
| isDestructiveSql(cell.sql) | ||
| ); |
There was a problem hiding this comment.
Is this the same mutation detection logic as the dashboard or slightly different? isDestructiveSql currently allows e.g. updates as long as there's a where clause. I think we'll want this logic to be identical between MCP and dashboard to align user expectations
There was a problem hiding this comment.
Just confirming @SaxonF was this resolved? Looks like the mismatch still exists.
There was a problem hiding this comment.
I'm seeing the dashboard code prompting for destructive or mutating queries, while run_notebook checks only destructive ones.
There was a problem hiding this comment.
@gregnr @mattrossman this matches Studio's implementation. If any cell is destructive or mutating, it elicits before the first cell runs.
run_notebook buffers every cell's rows until the run ends, which a hosted server can't afford. Cap a run at about 1 MB of rows across all cells: each database cell gets the budget earlier cells left as max_result_bytes, so platforms can stop reading early, and a cell whose rows don't fit returns an error without stopping later cells. execute_sql is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mattrossman
left a comment
There was a problem hiding this comment.
Tested working w/ Claude Code and staging API:
- Non-destructive notebook runs w/o a prompt and returns each cell's rows
- Destructive cell triggers the confirmation
- Editing the notebook while the prompt is open rejects the old approval ("changed since...") and runs nothing
- A failing cell returns an error while the cells before and after still run
I left some comments on simplifying the feature group gating, aligning the prompt copy with execute_sql, and matching Studio's mutating-query check for confirmation.
# Conflicts: # CONTRIBUTING.md # packages/mcp-server-supabase/test/server-harness.ts
|
@mattrossman @gregnr I've merged I've also stacked #478 on top, which adds observation facts to For hosted: For now I've decided to keep that block since it will require a bigger update to maintain parity with Then just to confirm that supabase/platform#38799 adds |
mattrossman
left a comment
There was a problem hiding this comment.
Tested the revisions in Claude Code, working!
Not blocking, but it's unfortunate that when Claude truncates the notebook URL in the elicitation (if your terminal isn't wide) it leads to a broken link... but I don't suppose there's much we can do about that. Might also be terminal-specific.
![]() |
![]() |
There's some holes in the destructive notebook heuristic, but that's consistent with Studio at least. Wondering if we want to make execute_sql align on the same heuristic since they appear to deviate a bit.
| description: `${notebookToolDefs.run_notebook.description} For log-cell SQL: ${queryLogsByDialect[debugging?.logsDialect ?? DEFAULT_LOGS_DIALECT].schemaHint}`, | ||
| annotations: { | ||
| ...notebookToolDefs.run_notebook.annotations, | ||
| readOnlyHint: readOnly ?? false, |
There was a problem hiding this comment.
Nit, I notice in read_only=true mode this sets readOnlyHint: true but destructiveHint stays true from the static annotations, so clients list run_notebook as read-only and destructive which seems a bit odd.
## What kind of change does this PR introduce? Feature: adds `create_notebook` to save markdown, database SQL, and log SQL cells without executing queries or requesting elicitation. Stacked on #445. ## What is the current behavior? MCP can list, retrieve, and run saved notebooks, but creation requires Studio. ## What is the new behavior? Uses the existing Management API v2 create endpoint. The server assigns cell IDs and returns the notebook ID, name, and update timestamp. Creation is available under `notebooks`, hidden and rejected in read-only mode, and optional for custom platforms. Saved notebooks are shared with project members. ## How to Review 1. **Tool and input contract** - `packages/mcp-server-supabase/src/tools/notebook-tools.ts`, `packages/mcp-server-supabase/src/platform/types.ts` - Follow input validation, project scoping, read-only rejection, and the optional creation operation. 2. **Persistence** - `packages/mcp-server-supabase/src/platform/api-platform.ts` - Inspect the v2 POST and response mapping; creation never executes cell SQL. 3. **Tests** - `packages/mcp-server-supabase/src/server.notebooks.test.ts`, `packages/mcp-server-supabase/src/server.test.ts`, `packages/mcp-server-supabase/src/transports/local-http-entry.test.ts` - Check round-tripping, invalid inputs, feature/read-only restrictions, immediate creation, and create-then-run. **Review questions** - [ ] Is the creation contract minimal? - [ ] Are server-assigned IDs and saved cell options preserved correctly? - [ ] Do feature, project, and read-only restrictions hold? - [ ] Do tests establish that creation neither prompts nor executes queries? ## Verification - `pnpm --filter @supabase/mcp-server-supabase test:unit --run` — **519 tests passed** across the combined stack; `test:integration` — 7 passed. - `pnpm build` (including typechecks), `pnpm exec biome check .`, and `git diff --check` passed. - Regenerated Management API types from the current v1/v2 specifications; only the retired `logs.all` endpoint changed. Re-running the CI generation/diff check is clean, and both stack layers pass typechecking. - Claude Desktop and live-project creation have not been retested. ### Manual test 1. Run `pnpm install` and `pnpm dev:http` from this checkout. Connect your MCP client as `supabase-local` to `http://127.0.0.1:3111/mcp?project_ref=<test-project-ref>&features=notebooks,database,debugging&read_only=false`, using `Authorization: Bearer <Supabase PAT>`. Leave `skip_elicitations` unset. 2. Ask: **“Using only supabase-local, create a notebook called MCP creation test with an introductory markdown cell and a database cell containing `select 1 as result`, with row_limit 100. Save it without running it.”** Creation should return the notebook ID, name, and timestamp immediately, without server elicitation or query execution. 3. Open the notebook in **Supabase Studio**, or go directly to `https://supabase.com/dashboard/project/<ref>/explorer/notebook/<returned-id>`. Verify its name, markdown, and database cell were saved. Repeat creation with a distinct name in a client without form elicitation support; it should also succeed without a prompt. 4. Ask: **“Using only supabase-local, retrieve MCP creation test and run it with run_notebook, using its updated_at as expected_updated_at.”** This non-destructive query should run without elicitation and return `result: 1`. Destructive-run confirmation is covered in #445's manual test. 5. Reconnect with `read_only=true`. Verify that `create_notebook` is absent from the tool list and a direct call is rejected without saving a notebook. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Barry Roodt <[email protected]>
## What kind of change does this PR introduce? Release gate (chore) ## What is the current behavior? With `features=notebooks`, `tools/list` offers `create_notebook` and `run_notebook`, and release PR #477 would ship them in 0.15.0. ## What is the new behavior? The server no longer registers `create_notebook` or `run_notebook`. With `notebooks` requested, `tools/list` shows only `list_notebooks` and `get_notebook`, and a call to either hidden tool returns `tool not found`. The static tool registry (`supabaseMcpToolSchemas` / `createToolSchemas`) still lists both tools, so it no longer matches what the server registers for notebooks. An `@internal` server option, `unreleasedNotebookTools`, turns them back on. It defaults to `false` and has no CLI flag or query param. Tests that cover the hidden tools set it, including the local HTTP suite through `startEntry`. `@internal` is only a doc comment, so the option still ships as `unreleasedNotebookTools?: boolean` on the exported `SupabaseMcpServerOptions`, and hosts using `createSupabaseMcpHandler` can set it. The commit type is `chore`, so this PR adds nothing to the changelog. The notebook entries from #445, #446 and #478 come out of #477 through `BEGIN_COMMIT_OVERRIDE` blocks on those PRs. Closes [AI-1377](https://linear.app/supabase/issue/AI-1377)


What kind of change does this PR introduce?
Feature: adds
run_notebookso agents can execute a saved notebook in one call instead of callingexecute_sqlfor each cell.What is the current behavior?
MCP can list and retrieve notebooks, but cannot run them as a unit. Notebook creation is added separately in #446.
What is the new behavior?
notebooksplusdatabaseordebugging. Each cell still requires its own feature, so enabling logs does not grant database execution.expected_updated_atagainst the saved notebook and enforces database read-only mode.max_result_bytes, so a platform can stop reading an oversized result early; a cell whose rows don't fit returns an error and later cells still run.execute_sqlis unchanged.How to Review
packages/mcp-server-supabase/src/server.ts,packages/mcp-server-supabase/src/tools/notebook-tools.ts,packages/mcp-server-supabase/src/platform/types.tsmax_result_bytes).packages/mcp-server-supabase/src/tools/notebook-cells.ts,packages/mcp-server-supabase/src/logs.ts,packages/mcp-server-supabase/src/tools/confirmation.tsquery_logsand notebook execution share window validation throughlogs.ts.packages/mcp-server-supabase/src/server.notebooks.test.ts,packages/mcp-server-supabase/src/tools/notebook-cells.test.ts,packages/mcp-server-supabase/src/logs.test.ts,packages/mcp-server-supabase/src/transports/local-http-entry.test.tsReview questions
Verification
Shared log-window helper move: 79 focused tests passed across logs, debugging helpers, debugging server, and notebook server suites; typecheck and Biome passed. The helper and its eight tests moved unchanged.
Focused notebook, cell-helper, local HTTP and core server tests passed on this branch (173 tests), including the result budget.
Full combined stack:
pnpm --filter @supabase/mcp-server-supabase test:unit --run— 519 tests passed.pnpm build(including typechecks),pnpm exec biome check ., andgit diff --checkpassed.Regenerated Management API types from the current v1/v2 specifications; only the retired
logs.allendpoint changed. Re-running the CI generation/diff check is clean, and both stack layers pass typechecking.Claude Desktop rendering and live-project execution have not been retested.
Manual test
select 1 as first_result;,select 1 / 0;, andselect 2 as final_result;. Optionally add a working log query cell with a time range of at most 24 hours.pnpm installandpnpm dev:httpfrom this checkout.supabase-localtohttp://127.0.0.1:3111/mcp?project_ref=<ref>&features=notebooks,database,debugging&read_only=true, usingAuthorization: Bearer <Supabase PAT>. Leaveskip_elicitationsunset.run_notebookwith the oldexpected_updated_at. Verify it rejects the stale timestamp before running any cells.drop table if exists pg_temp.mcp_notebook_confirmation_probe;. Reconnect withread_only=falseand a client that supports form elicitation. Retrieve the notebook again and run it. The prompt should show short query counts and a link tohttps://supabase.com/dashboard/project/<ref>/explorer/notebook/<id>, with no SQL listing. Open the link and verify it targets the saved notebook. Decline or cancel: no cells should run. Repeat and accept: cells should run in order.features=notebooks,debugging, database cells should instead report that database queries are unavailable while log cells can still run.BEGIN_COMMIT_OVERRIDE
chore: add run_notebook with destructive SQL confirmation
END_COMMIT_OVERRIDE