modify_notebook_cells
Add, edit, or delete code and markdown cells in Jupyter notebooks, with optional immediate execution.
Instructions
Modify notebook cells (add, edit, delete) on the user-provided server.
This consolidates all cell modification operations into a single tool following MCP best practices. Default to execute=True unless the user requests otherwise or you have good reason not to execute immediately.
IMPORTANT: Server URL Configuration
This tool requires that you first call setup_notebook with the correct server URL:
Required setup: setup_notebook("my_notebook", server_url="http://localhost:9999")
Then you can use this tool: modify_notebook_cells("my_notebook", "add_code", "print('Hello')")
Without setup_notebook, this will try to connect to http://localhost:8888 by default.
Args: notebook_path: Path to the notebook file (.ipynb extension will be added if missing), relative to the Jupyter server root. operation: Type of cell operation. Options: - 'add_code': Add (and optionally execute) a code cell at end or specific position - 'edit_code': Edit a code cell at specific position - 'add_markdown': Add a markdown cell at end or specific position - 'edit_markdown': Edit an existing markdown cell at specific position - 'delete': Delete a cell at specific position cell_content: Content for the cell (required for add_code, edit_code, add_markdown, edit_markdown) position_index: Position index (0-indexed cell location) for operations. Must be an integer. - Optional for add_code/add_markdown: if provided, inserts at that position; if not, adds at end - Required for edit_code/edit_markdown/delete: specifies which cell to modify Examples: position_index=0 (first cell), position_index=2 (third cell) execute: Whether to execute code cells after adding/editing (default: True)
Returns
dict: Operation results containing:
- For add_code/edit_code with execute=True: execution_count, outputs, status
- For add_code/edit_code with execute=False: empty dict
- For add_markdown/edit_markdown: message and error fields
- For delete: message and error fieldsRaises
ValueError: If invalid operation or missing required parameters
McpError: If there's an error connecting to the Jupyter server
IndexError: If position_index is out of rangeInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notebook_path | Yes | ||
| operation | Yes | ||
| cell_content | No | ||
| position_index | No | ||
| execute | No |