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
| 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 |
Input Schema (JSON Schema)
{
"properties": {
"from_index": {
"description": "Current index of the cell",
"type": "integer"
},
"notebook_path": {
"description": "Absolute path to the Jupyter notebook file",
"type": "string"
},
"to_index": {
"description": "Target index for the cell",
"type": "integer"
}
},
"required": [
"notebook_path",
"from_index",
"to_index"
],
"type": "object"
}
Implementation Reference
- src/jupyter-handler.js:247-267 (handler)The core handler function that reads the Jupyter notebook, validates indices, moves the cell by splicing the cells array, writes the notebook back, 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)The tool schema definition for 'move_cell', including name, description, and input schema specifying notebook_path, from_index, and to_index parameters.{ 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)The registration/dispatch logic in the CallToolRequestSchema handler that calls the jupyterHandler.moveCell method with the provided arguments.case "move_cell": return await this.jupyterHandler.moveCell( args.notebook_path, args.from_index, args.to_index );