move_cell
Reposition cells within Jupyter notebooks by specifying source and destination indices to reorganize content structure.
Instructions
Move a cell from one position to another
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notebook_path | Yes | Absolute path to the Jupyter notebook file | |
| from_index | Yes | Current index of the cell | |
| to_index | Yes | Target index for the cell |
Implementation Reference
- src/jupyter-handler.js:247-267 (handler)The main handler function for the 'move_cell' tool. It reads the Jupyter notebook JSON, validates indices, moves the cell by splicing the cells array, writes the updated notebook back to disk, and returns a success message.async moveCell(notebookPath, fromIndex, toIndex) { const notebook = await this.readNotebook(notebookPath); this.validateCellIndex(notebook.cells, fromIndex); if (toIndex < 0 || toIndex >= notebook.cells.length) { throw new Error(`Invalid target index ${toIndex}. Must be between 0 and ${notebook.cells.length - 1}`); } const [movedCell] = notebook.cells.splice(fromIndex, 1); notebook.cells.splice(toIndex, 0, movedCell); await this.writeNotebook(notebookPath, notebook); return { content: [ { type: "text", text: `Successfully moved cell from index ${fromIndex} to ${toIndex}` } ] }; }
- src/index.js:141-162 (schema)JSON Schema defining the input parameters for the 'move_cell' tool: notebook_path (string), from_index (integer), to_index (integer). Returned by the ListTools handler.{ name: "move_cell", description: "Move a cell from one position to another", inputSchema: { type: "object", properties: { notebook_path: { type: "string", description: "Absolute path to the Jupyter notebook file" }, from_index: { type: "integer", description: "Current index of the cell" }, to_index: { type: "integer", description: "Target index for the cell" } }, required: ["notebook_path", "from_index", "to_index"] } },
- src/index.js:355-360 (registration)Tool call dispatching/registration in the CallToolRequestSchema handler's switch statement, which routes 'move_cell' calls to JupyterHandler.prototype.moveCell.case "move_cell": return await this.jupyterHandler.moveCell( args.notebook_path, args.from_index, args.to_index );