claude-code
claude-code copied to clipboard
Jupyter notebook cell ID matching fails when using edit_cell with full source code
Bug Report: Jupyter notebook cell ID matching fails with edit_cell
Problem Description
When attempting to edit Jupyter notebook cells using the mcp__jupyter__edit_cell tool, the cell ID matching consistently fails even when using the exact cell source code as returned by read_notebook_source_only.
Steps to Reproduce
- Read a notebook using
mcp__jupyter__read_notebook_source_only - Copy the exact cell source code from the output (including the first comment line)
- Attempt to edit that cell using
mcp__jupyter__edit_cellwith the copied source ascell_id - The operation fails with "No cell found with ID [exact_source_code]"
Expected Behavior
The cell should be found and edited successfully when using the exact source code as returned by the read operation.
Actual Behavior
No cell found with ID # August-only spatial visualization with UltraPlot (FIXED)
import ultraplot as uplt
[... rest of source code ...]
Example Case
- Notebook:
netcdf_reader.ipynb - Cell to edit: Last cell with comment
# August-only spatial visualization with UltraPlot (FIXED) - Read output shows: Cell exists with that exact source code
- Edit attempt: Fails to find the cell
Attempted Workarounds
- ✅ Used just the comment line:
# August-only spatial visualization with UltraPlot (FIXED)- Still failed - ✅ Used truncated comment: Same failure
- ✅ Used manual Python JSON manipulation: This worked as a workaround
Successful Workaround
import json
with open('notebook.ipynb', 'r') as f:
nb = json.load(f)
# Direct manipulation of nb['cells'][-1]['source']
Impact
- Makes programmatic notebook editing very difficult
- Forces users to resort to manual JSON manipulation
- Breaks the expected workflow of read → edit cycle
- Inconsistent behavior between read and edit operations
Environment
- Tool:
mcp__jupyter__edit_cell - Context: Claude Code CLI
- Notebook format: Standard Jupyter .ipynb
Suggested Fix
The cell ID matching algorithm should be more robust and handle:
- Exact source code matching (current behavior seems broken)
- Partial matching for comments/headers
- Position-based indexing as fallback
- Better error messages indicating what cell IDs are available
This issue significantly impacts the usability of Jupyter notebook editing capabilities.