Skip to main content
Glama
azharlabs
by azharlabs

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
      );
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without behavioral details. It doesn't disclose whether this is a destructive mutation (likely yes, but unconfirmed), whether it requires specific permissions, what happens on error (e.g., invalid index), or if changes are saved automatically. For a write operation with zero annotation coverage, this is insufficient.

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 directly states the tool's function without unnecessary words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place.

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 this is a mutation tool with no annotations and no output schema, the description is incomplete. It lacks critical context: behavioral traits (e.g., destructiveness, error handling), usage guidelines relative to siblings, and expected outcomes. For a 3-parameter tool that modifies data, more guidance is needed to help the agent use it correctly.

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%, with clear parameter documentation in the input schema. The description adds no additional meaning beyond implying 'cell_index' is used to target a cell and 'new_source' replaces existing content. Since the schema already fully describes parameters, the baseline score of 3 is appropriate.

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 target resource ('source code of a specific cell by index'), making the purpose understandable. However, it doesn't distinguish this tool from sibling 'edit_cell' (which might edit metadata or other properties) or 'bulk_edit_cells' (which handles multiple cells), leaving some ambiguity about when to choose this specific tool.

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?

The description provides no guidance on when to use this tool versus alternatives like 'edit_cell' or 'bulk_edit_cells'. It doesn't mention prerequisites (e.g., whether the notebook must be open or saved) or exclusions (e.g., not for editing cell outputs). Without such context, the agent must infer usage from tool names alone.

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