-
-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Description
Bug Report: Cell ID matching fails in edit_cell operation
Problem Description
When attempting to edit Jupyter notebook cells using the edit_cell
function, 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
read_notebook_source_only
- Copy the exact cell source code from the output (including the first comment line)
- Attempt to edit that cell using
edit_cell
with 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, or at least provide clear guidance on what constitutes a valid cell ID.
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 using various ID approaches
Attempted Cell ID Formats
- ❌ Full source code: Complete cell content as returned by read operation
- ❌ First line only:
# August-only spatial visualization with UltraPlot (FIXED)
- ❌ Truncated comment: Various shortened versions
- ❌ Position-based: Attempted numeric indexing
Current Workaround
Direct JSON manipulation of the notebook file:
import json
with open('notebook.ipynb', 'r') as f:
nb = json.load(f)
nb['cells'][-1]['source'] = new_source.split('\n')
with open('notebook.ipynb', 'w') as f:
json.dump(nb, f, indent=2)
Questions/Issues
- What constitutes a valid cell ID? The documentation is unclear about the expected format
- Should cell IDs be UUIDs? Some Jupyter notebooks use UUID-based cell IDs
- Source code matching: If source-based matching is intended, the algorithm appears broken
- Error messages: Could be more helpful by listing available cell IDs
Impact
- Breaks the expected workflow: read → identify → edit
- Forces users to bypass the MCP server entirely
- Makes programmatic notebook editing very difficult
- Inconsistent behavior between read and edit operations
Environment
- MCP Server: jupyter-mcp-server
- Client: Claude Code CLI
- Notebook format: Standard Jupyter .ipynb files
- Python version: 3.x
Suggested Improvements
- Clear documentation on cell ID format and matching rules
- Better error messages showing available cell IDs when match fails
- Multiple matching strategies:
- Exact source matching
- Comment/header matching
- Position-based indexing (0, 1, 2, -1, etc.)
- UUID matching for notebooks that have them
- Fallback mechanisms when primary matching fails
Additional Context
This issue significantly impacts the usability of the MCP server for automated notebook manipulation workflows. The read-edit cycle should be seamless and intuitive for users.
Would appreciate guidance on the intended cell ID format or if this represents a bug in the matching logic.
Metadata
Metadata
Assignees
Labels
No labels