Building a Data Stack Live with AI AgentsLivestream August 18

Skip to main content

MD_CREATE_DIVE

Creates a new Dive and returns its summary along with the initial version. The initial version (version 1) is captured from content, description, api_version, and required_resources.

Unlike the save_dive MCP tool, MD_CREATE_DIVE does not validate the component code or analyze which databases it queries — the content is stored as-is. Follow the component contract from get_dive_guide to produce content that renders in the Dive viewer.

Syntax

SELECT * FROM MD_CREATE_DIVE(
title := 'my_dive',
content := '<jsx_source>',
description := 'What this Dive shows',
required_resources := [{'url': 'md:my_db', 'alias': 'my_db'}]
);

Function arguments accept literals and getvariable() calls. Subqueries and lateral column references are rejected, so store dynamic values with SET VARIABLE first.

Parameters

ParameterTypeRequiredDescription
titleVARCHARYesHuman-readable Dive title.
contentVARCHARYesJSX/React source for the Dive: a single component with a default export, using useSQLQuery for live queries.
descriptionVARCHARNoA brief description of the Dive.
required_resourcesLIST(STRUCT(url VARCHAR, alias VARCHAR))NoDatabases and shares the Dive queries, so the Dive viewer can attach them. url is a database (md:<database_name>) or share (md:_share/<name>/<uuid>) URL; alias is the name the Dive's SQL uses to reference it.
api_versionUINTEGERNoDive API version of the content. Defaults to 1.

Return columns

ColumnTypeDescription
idUUIDUnique identifier of the created Dive.
titleVARCHARThe Dive title.
descriptionVARCHARThe Dive description, or NULL.
owner_idUUIDIdentifier of the owning user.
current_versionINTEGERAlways 1 for a newly created Dive.
created_atTIMESTAMP WITH TIME ZONECreation timestamp.
updated_atTIMESTAMP WITH TIME ZONELast update timestamp.
owner_nameVARCHARUsername of the owner.
version_idUUIDIdentifier of the initial version.
version_storage_urlVARCHARInternal storage location of the version's content.
version_descriptionVARCHARDescription attached to the version, or NULL.
version_created_atTIMESTAMP WITH TIME ZONEWhen the version was created.
version_api_versionUINTEGERDive API version of the content.
version_required_resourcesLIST(STRUCT(name VARCHAR, alias VARCHAR, url VARCHAR, id UUID, resource_type VARCHAR))The resolved resources: each input url is resolved to its name, id, and resource_type (database or share).

Examples

Minimal Dive:

SELECT id, title, current_version
FROM MD_CREATE_DIVE(
title := 'Hello Dive',
content := 'export default function Dive() {
return <div>Hello from SQL</div>;
}'
);

A Dive querying a database, with the resource declared so viewers can attach it:

SELECT id
FROM MD_CREATE_DIVE(
title := 'Daily orders',
description := 'Order counts by day over the last 30 days',
content := $$
import { useSQLQuery } from "@motherduck/react-sql-query";

export default function Dive() {
const { data, isLoading } = useSQLQuery(`
SELECT order_date, COUNT(*) AS orders
FROM analytics.main.orders
WHERE order_date > now() - INTERVAL 30 DAY
GROUP BY ALL ORDER BY 1
`);
if (isLoading) return <div>Loading…</div>;
return <pre>{JSON.stringify(data, null, 2)}</pre>;
}
$$,
required_resources := [{'url': 'md:analytics', 'alias': 'analytics'}]
);