Skip to main content
Glama

convert_cell_type

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

Instructions

Convert a cell from one type to another

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "cell_index": { "description": "Zero-based index of the cell", "type": "integer" }, "new_type": { "description": "New cell type", "enum": [ "code", "markdown", "raw" ], "type": "string" }, "notebook_path": { "description": "Absolute path to the Jupyter notebook file", "type": "string" } }, "required": [ "notebook_path", "cell_index", "new_type" ], "type": "object" }

Implementation Reference

  • The core handler function that reads the notebook, validates inputs, changes the cell type, adjusts code-specific properties if necessary, writes back the notebook, and returns success/error message.
    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 parameters for the convert_cell_type tool: notebook_path (string), cell_index (integer), new_type (string enum).
    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, including name, description, and input 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 registration in the CallToolRequest handler that routes convert_cell_type calls to the JupyterHandler.convertCellType method.
    case "convert_cell_type": return await this.jupyterHandler.convertCellType( args.notebook_path, args.cell_index, args.new_type );

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