Skip to main content
Glama
azharlabs
by azharlabs

convert_cell_type

Change a Jupyter notebook cell's type between code, markdown, or raw formats to modify content behavior and presentation.

Instructions

Convert a cell from one type to another

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notebook_pathYesAbsolute path to the Jupyter notebook file
cell_indexYesZero-based index of the cell
new_typeYesNew cell type

Implementation Reference

  • Main handler function that performs the cell type conversion by modifying the notebook JSON, handling type-specific properties like execution_count and outputs, and persisting the changes.
    async convertCellType(notebookPath, cellIndex, newType) {
      const notebook = await this.readNotebook(notebookPath);
      this.validateCellIndex(notebook.cells, cellIndex);
      this.validateCellType(newType);
      
      const cell = notebook.cells[cellIndex];
      const oldType = cell.cell_type;
      
      if (oldType === newType) {
        return {
          content: [
            {
              type: "text",
              text: `Cell ${cellIndex} is already of type '${newType}'`
            }
          ]
        };
      }
      
      // Convert cell type
      cell.cell_type = newType;
      
      // Handle type-specific properties
      if (newType === 'code') {
        cell.execution_count = null;
        cell.outputs = [];
      } else {
        // Remove code-specific properties for non-code cells
        delete cell.execution_count;
        delete cell.outputs;
      }
      
      await this.writeNotebook(notebookPath, notebook);
      
      return {
        content: [
          {
            type: "text",
            text: `Successfully converted cell ${cellIndex} from '${oldType}' to '${newType}'`
          }
        ]
      };
    }
  • Input schema defining the parameters for the convert_cell_type tool.
    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_type: {
          type: "string",
          enum: ["code", "markdown", "raw"],
          description: "New cell type"
        }
      },
      required: ["notebook_path", "cell_index", "new_type"]
    }
  • src/index.js:163-185 (registration)
    Tool registration in the ListTools response, providing name, description, and schema.
    {
      name: "convert_cell_type",
      description: "Convert a cell from one type to another",
      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_type: {
            type: "string",
            enum: ["code", "markdown", "raw"],
            description: "New cell type"
          }
        },
        required: ["notebook_path", "cell_index", "new_type"]
      }
    },
  • src/index.js:362-367 (registration)
    Dispatch/routing in CallToolRequest handler to invoke the convertCellType method.
    case "convert_cell_type":
      return await this.jupyterHandler.convertCellType(
        args.notebook_path,
        args.cell_index,
        args.new_type
      );
  • Helper method to validate the new cell type against supported types.
    validateCellType(cellType) {
      if (!this.supportedCellTypes.includes(cellType)) {
        throw new Error(`Invalid cell type '${cellType}'. Supported types: ${this.supportedCellTypes.join(', ')}`);
      }
    }
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention whether this is a destructive operation (e.g., overwriting cell content), permission requirements, error handling, or side effects like file modifications.

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 with zero waste. It is front-loaded and appropriately sized for the tool's complexity, earning its place by stating the core purpose clearly.

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 no annotations and no output schema, the description is incomplete. It lacks details on return values, error conditions, and behavioral context needed for a mutation tool in a notebook environment with multiple sibling tools.

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 parameters. The description adds no additional meaning beyond implying 'cell' and 'type' concepts, which are already covered in the schema. Baseline 3 is appropriate as the 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 ('convert') and resource ('a cell'), specifying the transformation from one type to another. It distinguishes from siblings like 'edit_cell' or 'edit_cell_source' by focusing on type conversion rather than content editing, though it doesn't explicitly name alternatives.

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 is provided on when to use this tool versus alternatives like 'edit_cell' or 'bulk_edit_cells'. The description implies usage for type changes but lacks context on prerequisites, exclusions, or specific scenarios.

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