Skip to main content
Glama
azharlabs
by azharlabs

list_cells

Retrieve all cells from a Jupyter notebook with their indices and types to inspect notebook structure and content organization.

Instructions

List all cells in a Jupyter notebook with their indices and types

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notebook_pathYesAbsolute path to the Jupyter notebook file

Implementation Reference

  • The handler function that reads a Jupyter notebook file, extracts information about each cell (index, type, and preview of source), and returns a formatted text list of all cells.
    async listCells(notebookPath) {
      const notebook = await this.readNotebook(notebookPath);
      const cellsInfo = notebook.cells.map((cell, index) => {
        const source = Array.isArray(cell.source) ? cell.source.join('') : cell.source;
        const preview = source.length > 100 ? source.substring(0, 100) + '...' : source;
        
        return {
          index,
          type: cell.cell_type,
          preview: preview.replace(/\\n/g, ' ')
        };
      });
    
      return {
        content: [
          {
            type: "text",
            text: `Notebook: ${notebookPath}\nTotal cells: ${cellsInfo.length}\n\n${
              cellsInfo.map(cell => 
                `[${cell.index}] ${cell.type}: ${cell.preview}`
              ).join('\n')
            }`
          }
        ]
      };
    }
  • The input schema definition for the 'list_cells' tool, specifying the required 'notebook_path' parameter.
    {
      name: "list_cells",
      description: "List all cells in a Jupyter notebook with their indices and types",
      inputSchema: {
        type: "object",
        properties: {
          notebook_path: {
            type: "string",
            description: "Absolute path to the Jupyter notebook file"
          }
        },
        required: ["notebook_path"]
      }
    },
  • src/index.js:331-333 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes 'list_cells' calls to the JupyterHandler's listCells method.
    case "list_cells":
      return await this.jupyterHandler.listCells(args.notebook_path);

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