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

Function handleAddNotebook

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

Source from the content-addressed store, hash-verified

885}
886
887async function handleAddNotebook(args: Record<string, unknown>) {
888 const parsedArgs = addNotebookArgsSchema.safeParse(args)
889 if (!parsedArgs.success) {
890 return writingError(`Invalid args in handleAddNotebook: ${formatFirstIssue(parsedArgs.error)}`)
891 }
892 const filePath = parsedArgs.data.path
893 const name = parsedArgs.data.name
894 const blocks = parsedArgs.data.blocks ?? []
895 const dryRun = parsedArgs.data.dryRun === true
896
897 const file = await loadDeepnoteFile(filePath)
898
899 const notebookId = randomUUID()
900 const newNotebook = {
901 id: notebookId,
902 name,
903 blocks: blocks.map((block, index) => createBlock(block, index)),
904 }
905
906 if (dryRun === true) {
907 return {
908 content: [
909 {
910 type: 'text',
911 text: JSON.stringify(
912 {
913 wouldAdd: {
914 notebookId,
915 name,
916 blockCount: newNotebook.blocks.length,
917 },
918 },
919 null,
920 2
921 ),
922 },
923 ],
924 }
925 }
926
927 file.project.notebooks.push(newNotebook)
928 await saveDeepnoteFile(filePath, file)
929
930 return {
931 content: [
932 {
933 type: 'text',
934 text: JSON.stringify(
935 {
936 success: true,
937 notebookId,
938 name,
939 blockCount: newNotebook.blocks.length,
940 totalNotebooks: file.project.notebooks.length,
941 },
942 null,
943 2
944 ),

Callers 1

handleWritingToolFunction · 0.85

Calls 5

writingErrorFunction · 0.85
saveDeepnoteFileFunction · 0.85
formatFirstIssueFunction · 0.70
createBlockFunction · 0.70
loadDeepnoteFileFunction · 0.50

Tested by

no test coverage detected