MCPcopy Create free account
hub / github.com/deepnote/deepnote / handleCat

Function handleCat

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

Source from the content-addressed store, hash-verified

350}
351
352async function handleCat(args: Record<string, unknown>) {
353 const parsedArgs = catArgsSchema.safeParse(args)
354 if (!parsedArgs.success) {
355 return {
356 content: [
357 {
358 type: 'text',
359 text: 'Invalid args for deepnote_cat: path is required and optional fields must match expected types',
360 },
361 ],
362 isError: true,
363 }
364 }
365 const filePath = parsedArgs.data.path
366 const notebookFilter = parsedArgs.data.notebook
367 const blockIdFilter = parsedArgs.data.blockId
368 const blockTypeFilter = parsedArgs.data.blockType
369 const includeMetadata = parsedArgs.data.includeMetadata
370
371 let file: DeepnoteFile
372 try {
373 file = await loadDeepnoteFile(filePath)
374 } catch (error) {
375 const message = error instanceof Error ? error.message : String(error)
376 return {
377 content: [{ type: 'text', text: `Failed to read file "${filePath}": ${message}` }],
378 isError: true,
379 }
380 }
381 const output: string[] = []
382
383 for (const notebook of file.project.notebooks) {
384 if (notebookFilter && notebook.name !== notebookFilter && notebook.id !== notebookFilter) {
385 continue
386 }
387
388 output.push(`## Notebook: ${notebook.name}`)
389 output.push('')
390
391 for (const block of notebook.blocks) {
392 if (blockIdFilter && block.id !== blockIdFilter && !block.id.startsWith(blockIdFilter)) {
393 continue
394 }
395 if (blockTypeFilter && block.type !== blockTypeFilter) {
396 continue
397 }
398
399 output.push(`### Block: ${block.type} (${block.id.slice(0, 8)})`)
400
401 if (block.content) {
402 output.push('```')
403 output.push(block.content)
404 output.push('```')
405 }
406
407 if (includeMetadata && block.metadata) {
408 output.push('**Metadata:**')
409 output.push('```json')

Callers 1

handleReadingToolFunction · 0.85

Calls 1

loadDeepnoteFileFunction · 0.50

Tested by

no test coverage detected