Skip to main content
Glama
azharlabs
by azharlabs

add_cell

Insert a new code, markdown, or raw cell into a Jupyter notebook at a specified position with optional initial content.

Instructions

Add a new cell to the notebook

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notebook_pathYesAbsolute path to the Jupyter notebook file
sourceNoInitial source code/content for the cell
cell_typeNoType of cell to createcode
positionNoPosition to insert the cell (defaults to end if not specified)

Implementation Reference

  • Handler function for the 'add_cell' tool. Computes insertion position (defaults to end) and delegates to the insertCell helper function.
    async addCell(notebookPath, source = '', cellType = 'code', position = null) {
      const notebook = await this.readNotebook(notebookPath);
      
      // If position not specified, add at the end
      const insertPosition = position !== null ? position : notebook.cells.length;
      
      return await this.insertCell(notebookPath, insertPosition, cellType, source);
    }
  • Core helper function that performs the cell insertion: validates inputs, formats source code into Jupyter notebook array format, creates the new cell object, inserts it into the notebook cells array at the specified position, saves the notebook, and returns a success response.
    async insertCell(notebookPath, position, cellType = 'code', source = '') {
      const notebook = await this.readNotebook(notebookPath);
      this.validateCellType(cellType);
      
      if (position < 0 || position > notebook.cells.length) {
        throw new Error(`Invalid position ${position}. Must be between 0 and ${notebook.cells.length}`);
      }
      
      // Convert string to array format - each line should end with \n except the last
      let sourceArray;
      if (!source) {
        sourceArray = [''];
      } else {
        const lines = source.split('\n');
        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();
        }
      }
      
      const newCell = {
        cell_type: cellType,
        metadata: {},
        source: sourceArray
      };
      
      if (cellType === 'code') {
        newCell.execution_count = null;
        newCell.outputs = [];
      }
      
      notebook.cells.splice(position, 0, newCell);
      await this.writeNotebook(notebookPath, notebook);
      
      return {
        content: [
          {
            type: "text",
            text: `Successfully inserted ${cellType} cell at position ${position}`
          }
        ]
      };
    }
  • Input schema definition for the 'add_cell' tool, specifying parameters, types, defaults, and required fields.
    inputSchema: {
      type: "object",
      properties: {
        notebook_path: {
          type: "string",
          description: "Absolute path to the Jupyter notebook file"
        },
        source: {
          type: "string",
          default: "",
          description: "Initial source code/content for the cell"
        },
        cell_type: {
          type: "string",
          enum: ["code", "markdown", "raw"],
          default: "code",
          description: "Type of cell to create"
        },
        position: {
          type: "integer",
          description: "Position to insert the cell (defaults to end if not specified)"
        }
      },
      required: ["notebook_path"]
    }
  • src/index.js:381-387 (registration)
    Registration in the request handler switch statement: maps 'add_cell' tool invocations to the jupyterHandler.addCell method with parameter extraction.
    case "add_cell":
      return await this.jupyterHandler.addCell(
        args.notebook_path,
        args.source,
        args.cell_type,
        args.position
      );
  • src/index.js:256-284 (registration)
    Tool registration in the tools array: defines name 'add_cell', description, and input schema for the MCP server.
    {
      name: "add_cell",
      description: "Add a new cell to the notebook",
      inputSchema: {
        type: "object",
        properties: {
          notebook_path: {
            type: "string",
            description: "Absolute path to the Jupyter notebook file"
          },
          source: {
            type: "string",
            default: "",
            description: "Initial source code/content for the cell"
          },
          cell_type: {
            type: "string",
            enum: ["code", "markdown", "raw"],
            default: "code",
            description: "Type of cell to create"
          },
          position: {
            type: "integer",
            description: "Position to insert the cell (defaults to end if not specified)"
          }
        },
        required: ["notebook_path"]
      }
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the basic action. It doesn't mention whether this operation modifies the notebook file on disk, requires specific permissions, has side effects like saving changes, or what happens on failure (e.g., if the notebook path is invalid). This leaves significant gaps for a mutation tool.

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, direct sentence that efficiently conveys the core purpose without any unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 that this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., success status, cell ID), error conditions, or behavioral nuances like file locking or concurrency issues, which are important for context.

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?

The schema description coverage is 100%, providing detailed documentation for all parameters, including defaults and enums. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline score of 3 without compensating value.

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 ('Add') and resource ('a new cell to the notebook'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'insert_cell', which appears to serve a similar function, missing an opportunity for differentiation.

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 'insert_cell' or 'bulk_edit_cells'. It lacks context about prerequisites, such as whether the notebook must exist or be open, and offers no explicit when-to-use or when-not-to-use instructions.

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