MCPcopy Index your code
hub / github.com/deepnote/deepnote / createBlock

Function createBlock

packages/mcp/src/tools/writing.ts:406–436  ·  view source on GitHub ↗
(
  spec: { type: string; content?: string; metadata?: Record<string, unknown> },
  index: number
)

Source from the content-addressed store, hash-verified

404]
405
406function createBlock(
407 spec: { type: string; content?: string; metadata?: Record<string, unknown> },
408 index: number
409): DeepnoteBlock {
410 const base = {
411 id: randomUUID(),
412 blockGroup: randomUUID(),
413 sortingKey: generateSortingKey(index),
414 type: spec.type,
415 content: spec.content !== undefined ? spec.content : '',
416 metadata: spec.metadata !== undefined ? spec.metadata : {},
417 }
418
419 // Add execution fields for executable blocks
420 const candidate = executableBlockTypeSet.has(spec.type)
421 ? {
422 ...base,
423 executionCount: null,
424 outputs: [],
425 }
426 : base
427
428 const parsed = deepnoteBlockSchema.safeParse(candidate)
429 if (!parsed.success) {
430 throw new Error(
431 `Invalid block spec for type "${spec.type}": ${parsed.error.issues[0]?.message ?? 'schema validation failed'}`
432 )
433 }
434
435 return parsed.data
436}
437
438async function handleCreate(args: Record<string, unknown>) {
439 const parsedArgs = createArgsSchema.safeParse(args)

Callers 3

handleCreateFunction · 0.70
handleAddBlockFunction · 0.70
handleAddNotebookFunction · 0.70

Calls 1

generateSortingKeyFunction · 0.90

Tested by

no test coverage detected