Skip to main content
Glama
azharlabs
by azharlabs

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}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Get') but doesn't describe traits like whether it's read-only (implied but not explicit), error handling (e.g., if cell_index is out of bounds), performance, or return format. For a tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves beyond the basic operation.

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 that directly states the tool's function without unnecessary words. It is front-loaded with the core action ('Get the source code'), making it easy to parse. There is no wasted verbiage, and every part of the sentence contributes to understanding the purpose.

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 the complexity (a read operation with specific indexing) and lack of annotations and output schema, the description is incomplete. It doesn't explain what 'source code' includes (e.g., code only or with metadata), how errors are handled, or the return format. For a tool that retrieves data, more context is needed to use it effectively without trial and error.

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%, with clear descriptions for both parameters (notebook_path and cell_index). The description adds no additional meaning beyond the schema, such as examples or constraints (e.g., valid index ranges). Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 verb 'Get' and the resource 'source code of a specific cell by index', making the purpose understandable. It distinguishes from siblings like 'edit_cell_source' (which modifies) and 'list_cells' (which lists metadata), though it doesn't explicitly name alternatives. The description is specific but could be more precise about what 'source code' entails (e.g., code content vs. metadata).

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. It doesn't mention prerequisites (e.g., the notebook must exist), compare to 'list_cells' for browsing or 'read_notebook_with_outputs' for full content, or specify use cases like debugging or analysis. Without such context, the agent must infer usage from the tool name alone.

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