How to edit Jupyter .ipynb files with Gemini CLI without corrupting them?
Gemini CLI 0.1.22 with gemini-2.5-pro on Linux keeps corrupting Jupyter
.ipynbfiles when editing: the replace tool fails to match JSON strings, then write_file deletes the notebook content. Is there a fix or workaround for reliable notebook editing?Originally asked on GitHub: https://github.com/google-gemini/gemini-cli/issues/6930
4 answers
The issue is closed as completed, and the thread mentions a pull request (#7081) that adds dedicated local Jupyter notebook editing tools, but no release version is named in the thread. The reporter was on Gemini CLI 0.1.22 with gemini-2.5-pro on Linux (no sandbox), using replace and write_file to edit
.ipynbJSON, which ended with the notebook content deleted.Without a confirmed fixed release, the alternatives discussed in the thread are MCP servers for notebook manipulation:
- A contributor suggested datalayer/jupyter-mcp-server (opens external site) (comment 3). No one in the thread reports whether it worked.
- Another commenter recommended better-jupyter-mcp-server (opens external site) with this install command (comment 10):
bashgemini mcp add Jupyter-MCP-Server uvx better-jupyter-mcp-serverIt claims multi-notebook management, cell execution, and support for local/remote Jupyter servers, but no one in the thread confirms testing it.
One commenter argued against the MCP approach because the server starts its own Jupyter web server, its editing tools replace whole cells, and it adds an extra component to maintain (comment 11). The thread does not report a final verdict on that debate.
General advice: notebook MCP servers can execute code and modify notebook files, so only connect them to kernels and directories you are comfortable having changed.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Gemini CLI repeatedly tried the replace tool with exact JSON strings, failed to match them, then used write_file to rewrite the whole notebook, which deleted the notebook content.
Source: https://github.com/google-gemini/gemini-cli/issues/6930 (opens external site)
Did this work for you?What @teeler tried on GitHub (Outcome unclear)
A contributor suggested datalayer/jupyter-mcp-server as a workaround; no test result was reported in the thread.
Did this work for you?What @ChengJiale150 tried on GitHub (Outcome unclear)
Another commenter recommended better-jupyter-mcp-server, installable with
gemini mcp add Jupyter-MCP-Server uvx better-jupyter-mcp-server, but no one confirmed it worked.Did this work for you?
Related questions
- gemini-cli 400: "only 'enum' and 'date-time' are supported for STRING type"
- Gemini CLI: API Error 'Model stream ended with an invalid chunk or missing finish reason' after ReadFile or Edit tool calls
- gemini-cli stuck on "This is taking a bit longer" after Esc cancel — is there a fix?
- Is there a way to get codebase indexing in gemini-cli?
- How can I use voice input instead of typing with Gemini CLI?