Recipes

Agent-driven Jupyter notebook analysis and execution via MCP

From README links · today

Research & KnowledgeSoftware & DevOps

AI agent connects to a live Jupyter kernel to run and edit notebooks.

What they did

They wanted an agent that could actually work inside a real Jupyter notebook instead of guessing at code in a chat window. They installed jupyter-mcp-server from PyPI, started a Jupyter server with a token, and pointed their MCP-capable client at the server's MCP endpoint. From there the agent could list open notebooks, read cell contents, insert and edit cells, execute them against the live kernel, and read back stdout, errors, and rich outputs. The workflow they settled into was iterative: ask the agent to load a CSV, have it write a cell, run it, look at the traceback or the dataframe head, fix the cell, and re-run — all inside the same kernel so variables persisted between steps. They also used the server's ability to connect to remote Jupyter instances (JupyterHub or a hosted sandbox) so the heavy compute stayed off the laptop while the agent stayed in the loop. Finally they wrapped the whole thing in a short prompt template so a fresh session could pick up an existing notebook and continue the analysis without re-explaining context.

How it went

The loop worked well: the agent could run a cell, read the error, patch it, and re-run without human copy-paste, which cut the back-and-forth on exploratory data work substantially. Kernel state persisting across tool calls was the biggest win — no re-loading data each turn. Polish level was solid for a local single-user setup; the agent occasionally needed nudging to read outputs before writing the next cell rather than batching edits blind.

Worth knowing

You need a running Jupyter server with a token and the MCP endpoint reachable from the client; the README's hosted option avoids local process management but ties you to Datalayer's service. Token handling and network exposure of the Jupyter server are on you. Cell execution is real code execution against your kernel, so sandboxing and permissions matter. Multi-notebook and multi-user concurrency is not something to assume without testing.

Wiring

Install the server with pip (jupyter-mcp-server) or run the Docker image. Start Jupyter (lab or notebook) with a token and note the URL and token. Configure your MCP client with the server command and pass the Jupyter URL and token via environment variables or CLI flags as documented. The client connects over the MCP transport, the server talks to the Jupyter server's REST and websocket APIs, and tool calls map to notebook and kernel operations: list/read notebooks, insert/edit cells, execute cells, and fetch outputs. For remote setups, point the same config at a JupyterHub or hosted sandbox URL instead of localhost. The optional Claude Code plugin adds slash commands on top of the same connection.

Try it yourself

Set up jupyter-mcp-server against my local Jupyter instance and act as a notebook copilot. Steps: (1) confirm the MCP server is reachable and list my open notebooks; (2) open the notebook I name and summarize its cells and current kernel state; (3) for each task I give you, insert a new cell, execute it, read the output or traceback, and fix and re-run until it succeeds; (4) never delete existing cells without asking; (5) at the end, give me a short changelog of cells added or modified and any variables left in the kernel.

Source

Tools in this stack

Run this stack

Install the stack into this project. It writes AGENTS.md and the manifest, merges the MCP servers into .mcp.json, and — with --yes — runs the tool installs.

npx runchr install runchr/stack-jupyter-mcp-server-and-python-sdk
No CLI?curl -s https://api.runchr.com/api/recipes/runchr/stack-jupyter-mcp-server-and-python-sdk/manifest
System prompt
You are a notebook copilot working inside a live Jupyter kernel via jupyter-mcp-server. Read the output or traceback of every cell you execute before writing the next one, fix and re-run until it succeeds, and never delete existing cells without asking.

This system prompt was generated from this stack's copy and tools. A person has not reviewed it.

The manifest is also at api.runchr.com/api/recipes/runchr/stack-jupyter-mcp-server-and-python-sdk/manifest.