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

Function handleSnapshotLoad

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

Source from the content-addressed store, hash-verified

263}
264
265async function handleSnapshotLoad(args: Record<string, unknown>) {
266 if (args.path === undefined) {
267 return snapshotError('path is required')
268 }
269 const parsedArgs = snapshotLoadArgsSchema.safeParse(args)
270 if (!parsedArgs.success) {
271 return snapshotError(`Invalid arguments for deepnote_snapshot_load: ${formatFirstIssue(parsedArgs.error)}`)
272 }
273 const { path: filePath, snapshotDir } = parsedArgs.data
274
275 try {
276 const absolutePath = path.resolve(filePath)
277
278 // Check if it's a snapshot file directly
279 if (filePath.endsWith('.snapshot.deepnote')) {
280 const snapshot = await loadSnapshotFile(absolutePath)
281
282 // Count outputs
283 let totalOutputs = 0
284 for (const notebook of snapshot.project.notebooks) {
285 for (const block of notebook.blocks) {
286 const execBlock = block as { outputs?: unknown[] }
287 if (execBlock.outputs && execBlock.outputs.length > 0) {
288 totalOutputs++
289 }
290 }
291 }
292
293 return {
294 content: [
295 {
296 type: 'text',
297 text: JSON.stringify(
298 {
299 path: absolutePath,
300 projectName: snapshot.project.name,
301 projectId: snapshot.project.id,
302 version: snapshot.version,
303 notebooks: snapshot.project.notebooks.length,
304 blocksWithOutputs: totalOutputs,
305 execution: snapshot.execution,
306 environment: snapshot.environment,
307 },
308 null,
309 2
310 ),
311 },
312 ],
313 }
314 }
315
316 // Otherwise, find and load latest snapshot for the source file
317 const content = await fs.readFile(absolutePath, 'utf-8')
318 const file = deserializeDeepnoteFile(content)
319 const projectId = file.project.id
320 const notebookId = resolveSnapshotNotebookId(file)
321 const snapshotOptions = { ...(snapshotDir ? { snapshotDir } : {}), ...(notebookId ? { notebookId } : {}) }
322 const snapshot = await loadLatestSnapshot(absolutePath, projectId, snapshotOptions)

Callers 1

handleSnapshotToolFunction · 0.85

Calls 6

loadSnapshotFileFunction · 0.90
deserializeDeepnoteFileFunction · 0.90
loadLatestSnapshotFunction · 0.90
snapshotErrorFunction · 0.85
formatFirstIssueFunction · 0.70

Tested by

no test coverage detected