execute_notebook_code
Execute code cells or install packages in a Jupyter notebook. Requires prior notebook setup to specify the server URL.
Instructions
Execute code in a Jupyter notebook on the user-provided server.
This consolidates all code execution operations into a single tool following MCP best practices.
IMPORTANT: Server URL Configuration
This tool requires that you first call setup_notebook with the correct server URL:
Required setup: setup_notebook("my_notebook", server_url="http://localhost:9999")
Then you can use this tool: execute_notebook_code("my_notebook", "execute_cell", position_index=0)
Without setup_notebook, this will try to connect to http://localhost:8888 by default.
Args: notebook_path: Path to the notebook file (.ipynb extension will be added if missing), relative to the Jupyter server root. execution_type: Type of execution operation. Options: - 'execute_cell': Execute an existing code cell - 'install_packages': Install packages using uv pip in the notebook environment position_index: (For execute_cell) Positional index of cell to execute package_names: (For install_packages) Space-separated list of package names to install
Returns
Union[dict, str]:
- execute_cell: dict with execution_count, outputs, status
- install_packages: str with installation result messageRaises
ValueError: If invalid execution_type or missing required parameters
McpError: If there's an error connecting to the Jupyter server
IndexError: If position_index is out of range
RuntimeError: If kernel execution failsInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notebook_path | Yes | ||
| execution_type | Yes | ||
| position_index | No | ||
| package_names | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |