MCP HubMCP Hub
ihrpr

mcp-server-jupyter

by: ihrpr

MCP server for Jupyter Notebooks and JupyterLab

15created 20/01/2025
Visit
Jupyter
Notebook

📌Overview

Purpose: To provide an MCP server that enables programmatic management and interaction with Jupyter notebooks.

Overview: The mcp-server-jupyter facilitates the manipulation and execution of Jupyter notebooks through a set of defined tools. This framework streamlines workflows for developers and data scientists, enabling efficient notebook handling directly from a server.

Key Features:

  • Read Notebooks with Outputs: Allows users to retrieve entire notebook content, including cell outputs, which is vital for full notebook analysis.

  • Read Notebook Source Only: Provides a way to read the notebook's content without outputs to mitigate size issues, ensuring flexibility in handling large notebooks.

  • Cell Manipulation: Users can add new cells, edit existing ones, and execute specific cells to obtain outputs. This feature is crucial for iterative development and testing within notebooks.

  • Integration with Claude Desktop: Seamlessly integrates with Claude Desktop, allowing users to configure and run notebooks efficiently within their development environment.


MCP Server for Jupyter

An MCP server for managing and interacting with Jupyter notebooks programmatically.

Components

Tools

The server provides six tools for notebook manipulation:

  1. Read Notebook with Outputs

    • Reads a notebook's content including cell outputs.
    • Required: notebook_path (string)
  2. Read Notebook Source Only

    • Reads notebook content without outputs.
    • Required: notebook_path (string)
    • Use when size limitations prevent reading the full notebook with outputs.
  3. Read Output of Cell

    • Reads output of a specific cell.
    • Required:
      • notebook_path (string)
      • cell_id (string)
  4. Add Cell

    • Adds a new cell to the notebook.
    • Required:
      • notebook_path (string)
      • source (string)
    • Optional:
      • cell_type (string): "code" or "markdown"
      • position (integer): insertion index (-1 to append)
  5. Edit Cell

    • Modifies existing cell content.
    • Required:
      • notebook_path (string)
      • cell_id (string)
      • source (string)
  6. Execute Cell

    • Executes a specific cell and returns its output.
    • Required:
      • notebook_path (string)
      • cell_id (string)

Usage with Claude Desktop

Step 1: Start JupyterLab or Jupyter Notebook

Use uv to run Jupyter notebooks for easier management of virtual environments and package installations. Follow the UV Jupyter documentation for more details.

uv venv --seed
source .venv/bin/activate
uv pip install jupyterlab
.venv/bin/jupyter lab

NOTE: Use this environment as the UV_PROJECT_ENVIRONMENT in the MCP server.

echo $(pwd)/.venv

Step 2: Configure Claude Desktop

Add the following configuration to your Claude Desktop config file:

Using PyPi package:

{
  "mcpServers": {
    "Jupyter-notebook-manager": {
      "command": "uv",
      "args": ["run", "--with", "mcp-server-jupyter", "mcp-server-jupyter"],
      "env": {
        "UV_PROJECT_ENVIRONMENT": "/path/to/venv_for_jupyter/.venv"
      }
    }
  }
}

Using Git repo fork:

{
  "mcpServers": {
    "Jupyter-notebook-manager": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/Users/inna/mcp-server-jupyter/src/mcp_server_jupyter",
        "mcp-server-jupyter"
      ],
      "env": {
        "UV_PROJECT_ENVIRONMENT": "/path/to/venv_for_jupyter/.venv"
      }
    }
  }
}

Step 3: Open Notebook & Claude Chat

Open or create a notebook in JupyterLab/Jupyter Notebook.

Get the full path to your notebook:

  • In JupyterLab: Right-click on the notebook in the file browser → "Copy Path"
  • In Jupyter Notebook: Copy the path from the URL and modify it to full system path.

In Claude Desktop chat:

  • Always use the full path to the notebook when calling tools.
  • Example: /Users/username/projects/my_notebook.ipynb

Important Notes:

  • After modifications through Claude (add_cell, edit_cell), reload the notebook page in JupyterLab/Jupyter Notebook (automatic reload is not supported).
  • Keep the JupyterLab/Jupyter Notebook instance running while working with Claude.

License

This project is licensed under the MIT License. See the LICENSE file for details.