Skip to main content
Glama
azharlabs
by azharlabs

bulk_edit_cells

Edit, delete, or convert multiple cells in Jupyter notebooks simultaneously to manage content efficiently.

Instructions

Perform bulk operations on multiple cells

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notebook_pathYesAbsolute path to the Jupyter notebook file
operationsYes

Implementation Reference

  • The main handler function that executes bulk cell operations (edit, delete, convert) on a Jupyter notebook. It reads the notebook, applies operations in sorted order to handle index shifts, writes back changes, and reports success/errors.
    async bulkEditCells(notebookPath, operations) {
      const notebook = await this.readNotebook(notebookPath);
      let successCount = 0;
      const errors = [];
      
      // Sort operations by index in descending order for deletions
      const sortedOps = operations.sort((a, b) => {
        if (a.type === 'delete' && b.type !== 'delete') return -1;
        if (a.type !== 'delete' && b.type === 'delete') return 1;
        return b.cell_index - a.cell_index;
      });
      
      for (const op of sortedOps) {
        try {
          switch (op.type) {
            case 'edit':
              if (op.cell_index < 0 || op.cell_index >= notebook.cells.length) {
                throw new Error(`Invalid cell index ${op.cell_index}`);
              }
              // Convert string to array format - each line should end with \n except the last
              const lines = op.new_source.split('\n');
              const sourceArray = lines.map((line, index) => {
                if (index === lines.length - 1) {
                  return line === '' ? '' : line;
                } else {
                  return line + '\n';
                }
              });
              
              // Remove empty last element if original ended with \n
              if (sourceArray.length > 1 && sourceArray[sourceArray.length - 1] === '') {
                sourceArray.pop();
              }
              notebook.cells[op.cell_index].source = sourceArray;
              break;
              
            case 'delete':
              if (op.cell_index < 0 || op.cell_index >= notebook.cells.length) {
                throw new Error(`Invalid cell index ${op.cell_index}`);
              }
              notebook.cells.splice(op.cell_index, 1);
              break;
              
            case 'convert':
              if (op.cell_index < 0 || op.cell_index >= notebook.cells.length) {
                throw new Error(`Invalid cell index ${op.cell_index}`);
              }
              this.validateCellType(op.new_type);
              const cell = notebook.cells[op.cell_index];
              cell.cell_type = op.new_type;
              if (op.new_type === 'code') {
                cell.execution_count = null;
                cell.outputs = [];
              } else {
                delete cell.execution_count;
                delete cell.outputs;
              }
              break;
              
            default:
              throw new Error(`Unknown operation type: ${op.type}`);
          }
          successCount++;
        } catch (error) {
          errors.push(`Operation ${op.type} on cell ${op.cell_index}: ${error.message}`);
        }
      }
      
      await this.writeNotebook(notebookPath, notebook);
      
      const resultText = [
        `Bulk operation completed: ${successCount}/${operations.length} operations successful`
      ];
      
      if (errors.length > 0) {
        resultText.push(`\nErrors:\n${errors.join('\n')}`);
      }
      
      return {
        content: [
          {
            type: "text",
            text: resultText.join('\n')
          }
        ]
      };
    }
  • Input schema for the bulk_edit_cells tool, defining parameters: notebook_path (string) and operations (array of objects with type 'edit'/'delete'/'convert', cell_index (required), optional new_source and new_type).
      name: "bulk_edit_cells",
      description: "Perform bulk operations on multiple cells",
      inputSchema: {
        type: "object",
        properties: {
          notebook_path: {
            type: "string",
            description: "Absolute path to the Jupyter notebook file"
          },
          operations: {
            type: "array",
            items: {
              type: "object",
              properties: {
                type: {
                  type: "string",
                  enum: ["edit", "delete", "convert"]
                },
                cell_index: {
                  type: "integer"
                },
                new_source: {
                  type: "string"
                },
                new_type: {
                  type: "string",
                  enum: ["code", "markdown", "raw"]
                }
              },
              required: ["type", "cell_index"]
            }
          }
        },
        required: ["notebook_path", "operations"]
      }
    },
  • src/index.js:369-373 (registration)
    Registration in the CallToolRequest handler switch statement, dispatching calls to bulk_edit_cells to the JupyterHandler.bulkEditCells method.
    case "bulk_edit_cells":
      return await this.jupyterHandler.bulkEditCells(
        args.notebook_path,
        args.operations
      );
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 mentions 'bulk operations' but doesn't disclose critical behavioral traits: whether this modifies files in-place, requires write permissions, handles errors partially or atomically, or has rate limits. For a mutation tool with no annotations, this leaves significant gaps in understanding its behavior.

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

Conciseness4/5

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

The description is a single, efficient sentence with no wasted words. However, it's too brief given the tool's complexity—it could benefit from more detail to justify its conciseness, as it under-specifies rather than being optimally concise.

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 (bulk mutations on Jupyter notebooks), lack of annotations, no output schema, and incomplete parameter documentation, the description is inadequate. It doesn't cover mutation effects, error handling, or output expectations, leaving the agent with insufficient context to use the tool safely and effectively.

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 50% (notebook_path has a description, operations does not). The description adds no parameter-specific semantics beyond implying 'bulk operations' relate to the operations array. It doesn't explain the structure or meaning of operation types (edit, delete, convert) or their fields, leaving gaps that the schema partially covers with enums but not descriptions.

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

Purpose3/5

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

The description 'Perform bulk operations on multiple cells' states the general action but is vague about what constitutes 'bulk operations' and doesn't specify the resource context (Jupyter notebook cells). It doesn't distinguish from siblings like edit_cell, delete_cell, or convert_cell_type, which handle single-cell operations.

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. The description doesn't mention that this is for batch processing multiple cells at once, as opposed to using individual sibling tools like edit_cell or delete_cell for single operations. No prerequisites or exclusions are stated.

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