Repository navigation
feat: add create_notebook - #446
Conversation
Coverage Report for CI Build 39611717735Coverage increased (+0.2%) to 97.511%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
Coverage Report for CI Build 35957649144Warning No base build found for commit Coverage: 97.342%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → 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]>
237afb8 to
e145f24
Compare
e145f24 to
115915e
Compare
- Reject negative or fractional row limits, blank names and SQL, and unknown chart or time range keys; trim saved names and SQL. - Build the tool input schema in notebook-tools with project_id first, keeping the platform options schema free of model-facing descriptions. - Show the creation confirmation as a readable per-cell list instead of raw JSON, and explain why creation confirms at all. - Configure notebook confirmations through one option with enabledTools, matching the database tools. - Note in the description that run_notebook can only run log cells whose range is 24 hours or less. - Cover the full confirmation message, non-elicitation responses, declines after changes, and which field each invalid input fails on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
115915e to
3912918
Compare
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| project_id, | ||
| options | ||
| ); | ||
| return { id, name, updated_at }; |
There was a problem hiding this comment.
In testing, my agent was able to create the notebook but it didn't close the loop on where a user can see proof of the action. When I asked for the URL, it gave me an incorrect /reports/notebooks URL that 404-ed.
It would be helpful if it knew the URL of the notebook and proactively offered it to the user after notebook creation.
We'll probably want the URL returned in the output here, because in project-scoped mode the project ref is auto injected and not visible in context, so the only way it assembled the correct URL above was by reading my MCP config.
There was a problem hiding this comment.
create_notebook returns a url now. It's built server-side so it works in project-scoped mode, using the same helper as the run_notebook elicitation link. The links also follow the configured API URL, so staging points at the staging dashboard etc.
| export const notebookToolDefs = { | ||
| create_notebook: { | ||
| description: | ||
| 'Creates a saved notebook shared with everyone who has access to the Supabase project. Use for investigations or dashboards the user wants to revisit. Saves markdown, database SQL, and log SQL cells without executing queries. Cell ids are assigned by the server. Use get_notebook and run_notebook to run the saved notebook; run_notebook can only run log cells whose time range is 24 hours or less.', |
There was a problem hiding this comment.
I'm not sure agents have enough context from this about how to write log queries. We give more instruction about how to query logs on query_logs but (a) they might not have both tools available depending on their features config and (b) they might not realize these tools use the same logs schema.
Maybe we could reuse query_logs per-dialect schemaHint in the description?
mcp/packages/mcp-server-supabase/src/tools/debugging-tools.ts
Lines 96 to 110 in a39a599
mattrossman
left a comment
There was a problem hiding this comment.
Tested working w/ Claude Code and staging API:
- Creating a notebook returns immediately w/o a prompt
- Markdown, chart config, and relative log time range render correctly in Studio
- A notebook created via MCP runs via
run_notebook read_only=truehidescreate_notebook
I left some comments on returning the notebook url so agents can hand it off, and adding logs schema hint.
# Conflicts: # CONTRIBUTING.md # packages/mcp-server-supabase/test/server-harness.ts
…re/create-notebook-tool # Conflicts: # CONTRIBUTING.md # packages/mcp-server-supabase/src/server.test.ts
mattrossman
left a comment
There was a problem hiding this comment.
Verified in Claude locally that the new tool doesn't appear in read-only mode, I'm able to get the URL after creating a notebook, and the tool runs w/o elicitation now. Thanks!
I had one run where it still wrote invalid logs SQL but I think that was because I only had notebooks tools, once I added debugging it was able to figure out the write structure.
…re/create-notebook-tool # Conflicts: # packages/mcp-server-supabase/src/server.test.ts
## What kind of change does this PR introduce? Feature: adds `run_notebook` so agents can execute a saved notebook in one call instead of calling `execute_sql` for 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? - Runs database and log cells in order, returning each cell's rows or error; markdown is skipped and individual cell failures do not stop later cells. - Requires `notebooks` plus `database` or `debugging`. Each cell still requires its own feature, so enabling logs does not grant database execution. - Checks `expected_updated_at` against the saved notebook and enforces database read-only mode. - Caps 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 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_sql` is unchanged. - Non-destructive and read-only runs do not prompt. With confirmation enabled, destructive database SQL requires form elicitation before any cell runs. Clients without form support are rejected; decline/cancel executes nothing. The prompt links to the notebook in Studio with query counts instead of listing SQL. Signed approval is bound to the notebook, cells, and execution mode. Explicitly disabling run confirmation preserves the opt-out. ## How to Review 1. **Registration and execution** - `packages/mcp-server-supabase/src/server.ts`, `packages/mcp-server-supabase/src/tools/notebook-tools.ts`, `packages/mcp-server-supabase/src/platform/types.ts` - Follow feature gating, stale-content checks, confirmation, sequential execution, and the per-run result budget (`max_result_bytes`). 2. **Cell handling and approval state** - `packages/mcp-server-supabase/src/tools/notebook-cells.ts`, `packages/mcp-server-supabase/src/logs.ts`, `packages/mcp-server-supabase/src/tools/confirmation.ts` - Check the shared primary-database predicate, SQL row limits, log windows/results, and signed approval binding. `query_logs` and notebook execution share window validation through `logs.ts`. 3. **Tests** - `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.ts` - Server tests cover execution, feature isolation, and approval continuations; helper tests cover response shapes; HTTP tests cover skip configuration. **Review questions** - [ ] Is the tool contract minimal? - [ ] Do cells respect feature and read-only restrictions? - [ ] Can any cell execute before required approval? - [ ] Do tests cover observable behavior without unnecessary duplication? ## 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 .`, 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 rendering and live-project execution have not been retested. ### Manual test 1. In **Supabase Studio**, create and save a notebook in a test project. Add markdown and separate database cells containing `select 1 as first_result;`, `select 1 / 0;`, and `select 2 as final_result;`. Optionally add a working log query cell with a time range of at most 24 hours. 2. Run `pnpm install` and `pnpm dev:http` from this checkout. 3. Connect your MCP client as `supabase-local` to `http://127.0.0.1:3111/mcp?project_ref=<ref>&features=notebooks,database,debugging&read_only=true`, using `Authorization: Bearer <Supabase PAT>`. Leave `skip_elicitations` unset. 4. Ask: **“Using only supabase-local, retrieve the notebook '<name>' and run it with run_notebook, passing its updated_at as expected_updated_at. Report each cell's result in order.”** This read-only run should not request server elicitation. Verify that the first and last database cells succeed, the middle cell reports an error, and markdown is skipped. Repeat with a client without form elicitation support; the same read-only run should work. 5. Retrieve the notebook, edit and save it in Studio, then call `run_notebook` with the old `expected_updated_at`. Verify it rejects the stale timestamp before running any cells. 6. To test destructive-query confirmation without touching persistent tables, add a cell containing `drop table if exists pg_temp.mcp_notebook_confirmation_probe;`. Reconnect with `read_only=false` and a client that supports form elicitation. Retrieve the notebook again and run it. The prompt should show short query counts and a link to `https://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. 7. Repeat step 6 with a client without form support: the entire run should fail before executing any cell. With `features=notebooks,debugging`, database cells should instead report that database queries are unavailable while log cells can still run. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Barry Roodt <[email protected]>
…-tool # Conflicts: # CONTRIBUTING.md # packages/mcp-server-supabase/src/server.notebooks.test.ts # packages/mcp-server-supabase/src/server.test.ts # packages/mcp-server-supabase/src/tools/notebook-tools.ts # packages/mcp-server-supabase/src/transports/local-http-entry.test.ts
Stacked on #446. Adds the observation facts introduced in 0.14.0 to `run_notebook` elicitation events. They're emitted under a new `notebook` feature, since its prompt also fires for mutating SQL that isn't destructive. Notebooks with nothing to confirm get a new `not_mutating` bypass reason. An accepted or bypassed run emits one started/returned pair for the whole notebook. The cell queries don't add facts of their own, and a cell error the run catches still counts as returned because the run keeps going. --------- Co-authored-by: Saxon Fletcher <[email protected]> Co-authored-by: Claude Opus 5.5 <[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
create_notebookto 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
packages/mcp-server-supabase/src/tools/notebook-tools.ts,packages/mcp-server-supabase/src/platform/types.tspackages/mcp-server-supabase/src/platform/api-platform.tspackages/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.tsReview questions
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 ., andgit diff --checkpassed.logs.allendpoint changed. Re-running the CI generation/diff check is clean, and both stack layers pass typechecking.Manual test
pnpm installandpnpm dev:httpfrom this checkout. Connect your MCP client assupabase-localtohttp://127.0.0.1:3111/mcp?project_ref=<test-project-ref>&features=notebooks,database,debugging&read_only=false, usingAuthorization: Bearer <Supabase PAT>. Leaveskip_elicitationsunset.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.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.result: 1. Destructive-run confirmation is covered in feat: add run_notebook with destructive SQL confirmation #445's manual test.read_only=true. Verify thatcreate_notebookis absent from the tool list and a direct call is rejected without saving a notebook.BEGIN_COMMIT_OVERRIDE
chore: add create_notebook
END_COMMIT_OVERRIDE