get_cell_source
Retrieve source code from a specific Jupyter notebook cell using its index to inspect or analyze code content directly.
Instructions
Get the source code of a specific cell by index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notebook_path | Yes | Absolute path to the Jupyter notebook file | |
| cell_index | Yes | Zero-based index of the cell |
Implementation Reference
- src/jupyter-handler.js:122-137 (handler)The core handler function for 'get_cell_source' tool. Reads the Jupyter notebook file, validates the cell index, extracts the source code from the specified cell (handling array or string format), and returns it formatted as MCP content.async getCellSource(notebookPath, cellIndex) { const notebook = await this.readNotebook(notebookPath); this.validateCellIndex(notebook.cells, cellIndex); const cell = notebook.cells[cellIndex]; const source = Array.isArray(cell.source) ? cell.source.join('') : cell.source; return { content: [ { type: "text", text: source } ] }; }
- src/index.js:54-69 (schema)Input schema definition for the 'get_cell_source' tool, specifying notebook_path (string) and cell_index (integer) as required parameters.name: "get_cell_source", description: "Get the source code of a specific cell by index", inputSchema: { type: "object", properties: { notebook_path: { type: "string", description: "Absolute path to the Jupyter notebook file" }, cell_index: { type: "integer", description: "Zero-based index of the cell" } }, required: ["notebook_path", "cell_index"] }
- src/index.js:334-335 (registration)Registration in the CallToolRequestSchema handler: switch case that dispatches 'get_cell_source' calls to the jupyterHandler.getCellSource method.case "get_cell_source": return await this.jupyterHandler.getCellSource(args.notebook_path, args.cell_index);
- src/jupyter-handler.js:83-87 (helper)Helper method used by getCellSource to validate that the cell_index is within the bounds of the notebook's cells.validateCellIndex(cells, index) { if (index < 0 || index >= cells.length) { throw new Error(`Invalid cell index ${index}. Notebook has ${cells.length} cells (indices 0-${cells.length - 1})`); } }
- src/jupyter-handler.js:66-73 (helper)Helper method used by getCellSource to read and parse the Jupyter notebook JSON file from disk.async readNotebook(notebookPath) { try { const content = await fs.readFile(notebookPath, 'utf8'); return JSON.parse(content); } catch (error) { throw new Error(`Failed to read notebook: ${error.message}`); } }