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

Function handleRemoveBlock

packages/mcp/src/tools/writing.ts:696–771  ·  view source on GitHub ↗
(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

694}
695
696async function handleRemoveBlock(args: Record<string, unknown>) {
697 const parsedArgs = removeBlockArgsSchema.safeParse(args)
698 if (!parsedArgs.success) {
699 return writingError(`Invalid args in handleRemoveBlock: ${formatFirstIssue(parsedArgs.error)}`)
700 }
701 const filePath = parsedArgs.data.path
702 const blockId = parsedArgs.data.blockId
703 const dryRun = parsedArgs.data.dryRun === true
704
705 const file = await loadDeepnoteFile(filePath)
706
707 let removed = false
708 let removedFrom: string | undefined
709
710 for (const notebook of file.project.notebooks) {
711 const index = findBlockIndex(notebook.blocks, blockId)
712 if (index >= 0) {
713 if (dryRun !== true) {
714 notebook.blocks.splice(index, 1)
715 // Update sorting keys
716 notebook.blocks.forEach((block, i) => {
717 block.sortingKey = generateSortingKey(i)
718 })
719 }
720 removed = true
721 removedFrom = notebook.name
722 break
723 }
724 }
725
726 if (!removed) {
727 return {
728 content: [{ type: 'text', text: `Block not found: ${blockId}` }],
729 isError: true,
730 }
731 }
732
733 if (dryRun === true) {
734 return {
735 content: [
736 {
737 type: 'text',
738 text: JSON.stringify(
739 {
740 wouldRemove: {
741 blockId,
742 fromNotebook: removedFrom,
743 },
744 },
745 null,
746 2
747 ),
748 },
749 ],
750 }
751 }
752
753 await saveDeepnoteFile(filePath, file)

Callers 1

handleWritingToolFunction · 0.85

Calls 6

generateSortingKeyFunction · 0.90
writingErrorFunction · 0.85
findBlockIndexFunction · 0.85
saveDeepnoteFileFunction · 0.85
formatFirstIssueFunction · 0.70
loadDeepnoteFileFunction · 0.50

Tested by

no test coverage detected