Skip to main content
Glama
azharlabs
by azharlabs

edit_cell

Modify Jupyter notebook cell source code by specifying cell ID or index to update content while preserving metadata.

Instructions

Edit the source code of a specific cell by ID or index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notebook_pathYesAbsolute path to the Jupyter notebook file
cell_idYesCell ID or zero-based index of the cell to edit
new_sourceYesNew source code for the cell

Implementation Reference

  • The main handler function for the 'edit_cell' tool. Resolves cell by ID or index and delegates to editCellSource to update the notebook.
    async editCell(notebookPath, cellId, newSource) {
      const notebook = await this.readNotebook(notebookPath);
      
      // Find cell by ID or treat as index
      let cellIndex = -1;
      
      if (typeof cellId === 'string') {
        // Search by cell ID
        cellIndex = notebook.cells.findIndex(c => c.id === cellId);
        if (cellIndex === -1) {
          throw new Error(`Cell with ID '${cellId}' not found`);
        }
      } else {
        // Treat as index
        cellIndex = cellId;
      }
      
      return await this.editCellSource(notebookPath, cellIndex, newSource);
    }
  • Input schema definition for the 'edit_cell' tool, used in the listTools response.
    {
      name: "edit_cell",
      description: "Edit the source code of a specific cell by ID or index",
      inputSchema: {
        type: "object",
        properties: {
          notebook_path: {
            type: "string",
            description: "Absolute path to the Jupyter notebook file"
          },
          cell_id: {
            type: ["string", "integer"],
            description: "Cell ID or zero-based index of the cell to edit"
          },
          new_source: {
            type: "string",
            description: "New source code for the cell"
          }
        },
        required: ["notebook_path", "cell_id", "new_source"]
      }
    },
  • src/index.js:389-394 (registration)
    Dispatch registration in the CallToolRequestSchema handler that routes 'edit_cell' calls to JupyterHandler.editCell.
    case "edit_cell":
      return await this.jupyterHandler.editCell(
        args.notebook_path,
        args.cell_id,
        args.new_source
      );
  • Core helper function that performs the actual editing of cell source by index, converting string to Jupyter source array format and writing the notebook.
    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}`
          }
        ]
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the tool edits source code but doesn't disclose behavioral traits such as whether it overwrites existing content, requires write permissions, handles errors (e.g., invalid cell ID), or affects notebook state. This is a significant gap for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Edit the source code') and specifies the target ('specific cell by ID or index'). There is zero waste, and every word earns its place, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with 3 required parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like side effects, error handling, or return values, leaving gaps that could hinder an AI agent's correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds no additional meaning beyond what the schema provides, such as explaining 'cell_id' as 'ID or index' (already in schema) or clarifying parameter interactions. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Edit') and resource ('source code of a specific cell'), specifying it targets cells by 'ID or index'. It distinguishes from siblings like 'edit_cell_source' (which might be similar) by explicitly mentioning source code editing, though the distinction could be more explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives is provided. For example, it doesn't clarify when to choose 'edit_cell' over 'edit_cell_source' or 'bulk_edit_cells', or mention prerequisites like needing an existing notebook. The description implies usage but lacks explicit context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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