get_cell_source
Retrieve source code from a Jupyter notebook cell using its index to access and analyze specific code segments within notebook files.
Instructions
Get the source code of a specific cell by index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notebook_path | Yes | Absolute path to the Jupyter notebook file | |
| cell_index | Yes | Zero-based index of the cell |
Input Schema (JSON Schema)
{
"properties": {
"cell_index": {
"description": "Zero-based index of the cell",
"type": "integer"
},
"notebook_path": {
"description": "Absolute path to the Jupyter notebook file",
"type": "string"
}
},
"required": [
"notebook_path",
"cell_index"
],
"type": "object"
}
Implementation Reference
- src/jupyter-handler.js:122-137 (handler)The core handler function that reads the Jupyter notebook file, validates the cell index, extracts and joins the cell source (handling array format), and returns it as MCP text 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 } ] }; }
- src/index.js:54-70 (schema)JSON schema definition for the 'get_cell_source' tool in the ListTools response, specifying input parameters: notebook_path (string) and cell_index (integer).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)Tool dispatch/registration in the CallToolRequestSchema handler switch statement, which calls the jupyterHandler.getCellSource method with parsed arguments.case "get_cell_source": return await this.jupyterHandler.getCellSource(args.notebook_path, args.cell_index);