delete_cell
Remove a specific cell from a Jupyter notebook file by its index to clean up or reorganize notebook content.
Instructions
Delete a cell by index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notebook_path | Yes | Absolute path to the Jupyter notebook file | |
| cell_index | Yes | Zero-based index of the cell to delete |
Input Schema (JSON Schema)
{
"properties": {
"cell_index": {
"description": "Zero-based index of the cell to delete",
"type": "integer"
},
"notebook_path": {
"description": "Absolute path to the Jupyter notebook file",
"type": "string"
}
},
"required": [
"notebook_path",
"cell_index"
],
"type": "object"
}
Implementation Reference
- src/jupyter-handler.js:226-245 (handler)The core handler function that implements the delete_cell tool logic: reads the notebook JSON, validates the cell index, splices out the cell, writes the updated notebook back to disk, and returns a success response.async deleteCell(notebookPath, cellIndex) { const notebook = await this.readNotebook(notebookPath); this.validateCellIndex(notebook.cells, cellIndex); if (notebook.cells.length === 1) { throw new Error("Cannot delete the last remaining cell in the notebook"); } notebook.cells.splice(cellIndex, 1); await this.writeNotebook(notebookPath, notebook); return { content: [ { type: "text", text: `Successfully deleted cell ${cellIndex}` } ] }; }
- src/index.js:122-139 (schema)The input schema definition for the delete_cell tool, including required parameters notebook_path (string) and cell_index (integer).{ name: "delete_cell", description: "Delete a 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 to delete" } }, required: ["notebook_path", "cell_index"] } },
- src/index.js:352-354 (registration)Registration in the CallToolRequest handler switch statement that maps the 'delete_cell' tool name to the jupyterHandler.deleteCell method.case "delete_cell": return await this.jupyterHandler.deleteCell(args.notebook_path, args.cell_index);