Skip to main content
Glama

get_cell_source

Retrieve source code from a specific Jupyter notebook cell using its index to inspect or analyze code content directly.

Instructions

Get 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

Implementation Reference

  • The core handler function for 'get_cell_source' tool. Reads the Jupyter notebook file, validates the cell index, extracts the source code from the specified cell (handling array or string format), and returns it formatted as MCP content.
    async getCellSource(notebookPath, cellIndex) { const notebook = await this.readNotebook(notebookPath); this.validateCellIndex(notebook.cells, cellIndex); const cell = notebook.cells[cellIndex]; const source = Array.isArray(cell.source) ? cell.source.join('') : cell.source; return { content: [ { type: "text", text: source } ] }; }
  • Input schema definition for the 'get_cell_source' tool, specifying notebook_path (string) and cell_index (integer) as required parameters.
    name: "get_cell_source", description: "Get 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" } }, required: ["notebook_path", "cell_index"] }
  • src/index.js:334-335 (registration)
    Registration in the CallToolRequestSchema handler: switch case that dispatches 'get_cell_source' calls to the jupyterHandler.getCellSource method.
    case "get_cell_source": return await this.jupyterHandler.getCellSource(args.notebook_path, args.cell_index);
  • Helper method used by getCellSource to validate that the cell_index is within the bounds of the notebook's cells.
    validateCellIndex(cells, index) { if (index < 0 || index >= cells.length) { throw new Error(`Invalid cell index ${index}. Notebook has ${cells.length} cells (indices 0-${cells.length - 1})`); } }
  • Helper method used by getCellSource to read and parse the Jupyter notebook JSON file from disk.
    async readNotebook(notebookPath) { try { const content = await fs.readFile(notebookPath, 'utf8'); return JSON.parse(content); } catch (error) { throw new Error(`Failed to read notebook: ${error.message}`); } }

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