Skip to content

feat: add create_notebook - #446

Merged
barryroodt merged 26 commits into
mainfrom
chore/create-notebook-tool
Oct 21, 2026
Merged

barryroodt merged 26 commits into
mainfrom
chore/create-notebook-tool

Conversation

@SaxonF

@SaxonF SaxonF commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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 feat: add run_notebook with destructive SQL confirmation #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.

BEGIN_COMMIT_OVERRIDE
chore: add create_notebook
END_COMMIT_OVERRIDE

@SaxonF
SaxonF added this pull request to stack #447 September 24, 2026 04:54
@coveralls

coveralls commented Sep 24, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 39611717735

Coverage increased (+0.2%) to 97.511%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 139 of 139 lines across 3 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 5579
Covered Lines: 5472
Line Coverage: 98.08%
Relevant Branches: 1050
Covered Branches: 992
Branch Coverage: 94.48%
Branches in Coverage %: Yes
Coverage Strength: 146.65 hits per line

💛 - Coveralls

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 35957649144

Warning

No base build found for commit 5fe1cbe on feat/run-notebook-tool.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 97.342%

Details

  • Patch coverage: 149 of 149 lines across 6 files are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 4912
Covered Lines: 4807
Line Coverage: 97.86%
Relevant Branches: 845
Covered Branches: 797
Branch Coverage: 94.32%
Branches in Coverage %: Yes
Coverage Strength: 95.61 hits per line

💛 - Coveralls

SaxonF and others added 2 commits September 24, 2026 15:23
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]>
@SaxonF SaxonF changed the title feat: add create_notebook with confirmation feat: add create_notebook Sep 24, 2026
@SaxonF
SaxonF force-pushed the chore/create-notebook-tool branch from 237afb8 to e145f24 Compare September 24, 2026 23:39
@SaxonF
SaxonF force-pushed the chore/create-notebook-tool branch from e145f24 to 115915e Compare September 24, 2026 23:46
SaxonF and others added 6 commits September 25, 2026 09:50
- 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]>
@SaxonF
SaxonF force-pushed the chore/create-notebook-tool branch from 115915e to 3912918 Compare September 24, 2026 23:51
@SaxonF
SaxonF marked this pull request as ready for review September 25, 2026 01:19
@SaxonF
SaxonF requested a review from a team as a code owner September 25, 2026 01:20
SaxonF and others added 2 commits September 28, 2026 12:35
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]>
project_id,
options
);
return { id, name, updated_at };

@mattrossman mattrossman Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Image

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.

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.

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.',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

const queryLogsByDialect = {
clickhouse: buildQueryLogsCopy({
name: 'ClickHouse',
logsNoun: 'unified logs stream',
schemaHint:
"Logs are exposed through a `logs` table; filter by `source` (common values include 'edge_logs', 'postgres_logs', and 'function_edge_logs', but this list is not exhaustive — run `select distinct source from logs` to discover the sources available for this project) and read nested fields via `log_attributes['<key>']`.",
}),
bigquery: buildQueryLogsCopy({
name: 'BigQuery',
logsNoun: 'logs',
schemaHint:
"Each service has its own source table (common ones include 'edge_logs', 'postgres_logs', and 'function_edge_logs', but the set is not exhaustive — other per-service tables, e.g. Data API and pooler logs, also exist); read nested fields by cross joining `unnest(metadata) as m` and then `m.<field>` (unnest further for nested structs such as `m.request` or `m.parsed`).",
}),
} as const satisfies Record<
LogsDialect,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Example of it writing an invalid logs query:

Image Image

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.

Fixed

@mattrossman mattrossman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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=true hides create_notebook

I left some comments on returning the notebook url so agents can hand it off, and adding logs schema hint.

@mattrossman mattrossman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Base automatically changed from feat/run-notebook-tool to main October 21, 2026 13:48
barryroodt added a commit that referenced this pull request Oct 21, 2026
## 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
@barryroodt
barryroodt merged commit 82e4630 into main Oct 21, 2026
5 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Oct 21, 2026
barryroodt added a commit that referenced this pull request Oct 21, 2026
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]>
barryroodt pushed a commit that referenced this pull request Oct 29, 2026
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants