claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Jupyter notebook cell ID matching fails when using edit_cell with full source code

Open tofunori opened this issue 6 months ago • 0 comments

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

  1. Read a notebook using mcp__jupyter__read_notebook_source_only
  2. Copy the exact cell source code from the output (including the first comment line)
  3. Attempt to edit that cell using mcp__jupyter__edit_cell with the copied source as cell_id
  4. 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

  1. Used just the comment line: # August-only spatial visualization with UltraPlot (FIXED) - Still failed
  2. Used truncated comment: Same failure
  3. 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:

  1. Exact source code matching (current behavior seems broken)
  2. Partial matching for comments/headers
  3. Position-based indexing as fallback
  4. Better error messages indicating what cell IDs are available

This issue significantly impacts the usability of Jupyter notebook editing capabilities.

tofunori avatar Jun 28 '25 12:06 tofunori