Skip to main content
Glama

edit_cell_source

Modify source code in Jupyter notebook cells by specifying the notebook path, cell index, and new code content to update cell programming instructions.

Instructions

Edit the source code of a specific cell by index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notebook_pathYesAbsolute path to the Jupyter notebook file
cell_indexYesZero-based index of the cell
new_sourceYesNew source code for the cell

Implementation Reference

  • The core handler function that reads the Jupyter notebook, validates the cell index, converts the new source string to the required array format (with proper line endings), updates the cell source, writes the notebook back to disk, and returns a success message.
    async editCellSource(notebookPath, cellIndex, newSource) { const notebook = await this.readNotebook(notebookPath); this.validateCellIndex(notebook.cells, cellIndex); // Convert string to array format - each line should end with \n except the last const lines = newSource.split('\n'); const sourceArray = lines.map((line, index) => { // Add \n to all lines except the last one, unless the original ended with \n if (index === lines.length - 1) { // Last line: only add \n if original text ended with \n (detected by empty last element) return line === '' ? '' : line; } else { // All other lines get \n return line + '\n'; } }); // Remove empty last element if original ended with \n if (sourceArray.length > 1 && sourceArray[sourceArray.length - 1] === '') { sourceArray.pop(); } notebook.cells[cellIndex].source = sourceArray; await this.writeNotebook(notebookPath, notebook); return { content: [ { type: "text", text: `Successfully updated cell ${cellIndex}` } ] }; }
  • The input schema definition for the 'edit_cell_source' tool, specifying the required parameters: notebook_path (string), cell_index (integer), new_source (string). This is part of the tools list returned by the ListTools handler.
    { name: "edit_cell_source", description: "Edit the source code of a specific cell by index", inputSchema: { type: "object", properties: { notebook_path: { type: "string", description: "Absolute path to the Jupyter notebook file" }, cell_index: { type: "integer", description: "Zero-based index of the cell" }, new_source: { type: "string", description: "New source code for the cell" } }, required: ["notebook_path", "cell_index", "new_source"] } },
  • src/index.js:337-343 (registration)
    The dispatch handler in the CallToolRequestSchema that matches the tool name and delegates execution to this.jupyterHandler.editCellSource with the parsed arguments.
    case "edit_cell_source": return await this.jupyterHandler.editCellSource( args.notebook_path, args.cell_index, args.new_source );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/azharlabs/mcp-jupyter-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server