Jupyter Notebook MCP Server

A VS Code / Cursor extension that exposes Jupyter notebook manipulation via MCP (Model Context Protocol): read/edit/run cells and capture outputs. Works with Claude Code, Cursor Agent, Windsurf, and any MCP-compatible AI assistant.
Install: VS Code Marketplace · GitHub
[!NOTE]
This project is an independent fork of olavocarvalho/vscode-runtime-notebook-mcp, licensed under MIT.
Fork additions include broker/worker multi-window routing, notebook_get_summary, cell_id-based operations, and stress/verify improvements.
[!IMPORTANT]
This project is still pre-alpha so it's very rough on the edge. Working in multiple windows is unstable.
Why connect to VS Code Runtime API?
There are currently two main architectures to give AI agents access to Jupyter notebooks. This project was heavily inspired by both - kudos to these teams for pioneering the space:
These servers read/write .ipynb files directly using libraries like nbformat.
Pros: No server dependencies, works out-of-the-box
Cons:
- Cannot execute code - agents can only edit cells, user must run them manually
- UI sync issues - VS Code may show stale content until you revert/reopen
- The
.ipynb JSON format is verbose (~3x more tokens than raw code)
- Race conditions if you edit while agent writes
Architecture 2: Jupyter Server API (e.g., jupyter-mcp-server)
These servers connect to Jupyter's REST API and can execute code through the kernel.
Pros: Can execute code, best choice for standalone remote JupyterLab/JupyterHub deployments
Cons:
- Requires running JupyterLab separately (
jupyter lab --port 8888)
- Auth setup: tokens, URLs, environment variables
- You end up running two UIs: one for notebook and another for AI
- If you open the notebook in VS Code you create another source of truth (Jupyter server state vs your editor)
Architecture 3: VS Code / Cursor Runtime API (this extension)
We're introducing a third architecture - hooking directly into Cursor/VS Code's Notebook API, the same API the editor uses internally.
Pros:
- Zero config - just install, server starts automatically
- Faster reads (direct memory access, no serialization)
- Executes code in your existing kernel (the one VS Code already manages)
- Changes appear instantly in the editor with full undo/redo support
- Single source of truth: what you see is what the agent sees
- Works with remote kernels - if VS Code connects to a remote Jupyter server, so does the agent
Cons:
- Only works inside VS Code / Cursor (won't help if you use JupyterLab web UI)
When to use what
| Use case |
Recommended |
| VS Code / Cursor + AI coding |
This extension |
| Remote VS Code / Cursor (tunnels, containers, SSH) |
This extension |
| Standalone JupyterLab/JupyterHub server |
Datalayer |
| Just edit cells, no execution needed |
File-based |
Features
- Execute code in the active kernel and retrieve outputs
- Full cell manipulation - insert, edit, delete, move cells
- Read cell contents and outputs including images (base64)
- Search and navigate - find text, get notebook outline
- Bulk operations - add multiple cells, clear all outputs
Navigation & Reading
| Tool |
Description |
notebook_list_open |
List all open notebooks with URIs and cell counts |
notebook_list_cells |
List cells with type, language, preview, execution state |
notebook_get_summary |
Get compact per-cell summary with stable cellId, execution, and output MIME |
notebook_get_cell_content |
Get full source code of a cell |
notebook_get_cell_output |
Get cell outputs (text, errors, images as base64) |
notebook_get_outline |
Get notebook structure (headings, functions, classes) |
notebook_search |
Search all cells for a keyword with context |
notebook_get_kernel_info |
Get kernel name, language, and state |
notebook_get_kernel_context |
Get kernel runtime context (variables/imports/history) |
notebook_server_health |
Read MCP runtime health (mode/ports/sessions) via MCP tool |
notebook_server_workers |
Read broker worker registry via MCP tool |
notebook_server_active_notebooks |
Read active/open notebook inventory in current window |
Cell Manipulation
| Tool |
Description |
notebook_insert_cell |
Insert a code or markdown cell at any position |
notebook_edit_cell |
Replace the content of an existing cell (supports cell_id) |
notebook_delete_cell |
Delete a cell by index or cell_id |
notebook_move_cell |
Move a cell to a different position |
notebook_bulk_add_cells |
Add multiple cells in a single operation |
Execution & Outputs
To execute ad-hoc code, use notebook_insert_cell with execute: true. To execute an existing cell, use notebook_run_cell.
| Tool |
Description |
notebook_run_cell |
Execute an existing code cell by index or cell_id and return outputs |
notebook_clear_outputs |
Clear outputs of a specific cell by index or cell_id |
notebook_clear_all_outputs |
Clear outputs from all cells |
Tool Parameters
All tools support response_format parameter ("markdown" or "json").
notebook_insert_cell
{
"content": "print('hello')",
"type": "code",
"index": 0,
"language": "python",
"execute": false
}
notebook_edit_cell
{
"cell_id": "abc123cellid",
"content": "# New content"
}
notebook_search
{
"query": "import pandas",
"case_sensitive": false,
"context_lines": 1
}
notebook_move_cell
{
"from_index": 5,
"to_index": 0
}
notebook_bulk_add_cells
{
"cells": [
{"content": "# Header", "type": "markdown"},
{"content": "x = 1", "type": "code", "language": "python"}
],
"index": 0
}
notebook_run_cell
{
"cell_id": "abc123cellid"
}
Setup
- Install the extension in VS Code or Cursor
- Recommended (low-permission) MCP client config via stdio proxy:
{
"mcpServers": {
"notebook": {
"command": "node",
"args": [
"/ABS/PATH/vscode-runtime-notebook-mcp/scripts/mcp-stdio-proxy.mjs"
],
"env": {
"MCP_BASE_URL": "http://127.0.0.1:49777/mcp"
}
}
}
}
- HTTP config (alternative):
{
"mcpServers": {
"notebook": {
"url": "http://127.0.0.1:49777/mcp"
}
}
}
[!ATTENTION]
The server starts automatically when VS Code / Cursor opens. Look for the 🪐 :<port> indicator in the status bar.
Multi-window mode now uses a fixed endpoint model:
- One window becomes the broker on
notebook-mcp.port (default 49777).
- Other windows start local workers on
49778+ and auto-register to the broker.
- MCP clients can keep a single config URL (
http://127.0.0.1:49777/mcp).
stdio mode is recommended for sandboxed agents to reduce repeated localhost/network permission prompts.
Configuration
| Setting |
Default |
Description |
notebook-mcp.port |
49777 |
Port number for the MCP server |
notebook-mcp.runCellTimeoutMs |
60000 |
Timeout in ms for notebook_run_cell and execute=true insert operations |
notebook-mcp.kernelIntrospectionTimeoutMs |
10000 |
Timeout in ms for notebook_get_kernel_context introspection |
notebook-mcp.maxJsonBodyMb |
5 |
Maximum accepted JSON request body size (MB) for MCP HTTP endpoints |
Verification Scripts
For repeatable validation in development:
npm run gen_notebooks # Generate deterministic test notebooks
npm run bootstrap # Check health + MCP initialize/tools/list
npm run self_check # MCP-only health/workers/active-notebooks check (no curl/lsof/ps)
npm run smoke # initialize -> tools/list -> list_open (+ requires kernel in verify)
npm run api_stability # Exercise notebook tools, requiring 3 notebooks / 3 kernels in verify
npm run stress # 3-notebook triad stress (reader/editor/executor lanes in parallel)
npm run stress:nightly # Strict nightly triad profile on 3 distinct runtime kernels (>=1 run-capable lane)
npm run stress:nightly:x2 # Run strict nightly profile twice (quick pre-release confidence)
npm run verify:strict:5 # Strict 5-notebook full gate (requires 5 open notebooks with 5 kernels)
npm run stress:soak:5 # Heavier 5-notebook soak profile
npm run verify # bootstrap -> smoke(kernel required) -> api_stability(strict) -> stress(strict)
Permission-Minimal Workflow (P0)
- Prefer
stdio MCP config (scripts/mcp-stdio-proxy.mjs) over direct HTTP from sandboxed agents.
- Use
npm run self_check for health/workers/notebook inventory instead of ad-hoc curl/ps/lsof.
- Keep automation on stable npm scripts (
verify, verify:strict:5, stress:nightly:x2) to reuse command-prefix approvals.
- Keep test scripts writing inside workspace paths only.
Tested with a 471-cell notebook (~2.8MB, 1MB outputs):
| Operation |
Time |
| List/read cells |
<1ms |
| Search all cells |
<1ms |
| Generate outline |
~1ms |
| Insert/edit cell |
~7ms |
[!NOTE]
Read operations are sub-millisecond because they access in-memory data structures directly. Write operations (~7ms) go through VS Code's edit pipeline for undo/redo support.
Requirements
Architecture
┌─────────────────────────────────────────────────────────────────────────┐
│ VS Code / Cursor │
│ │
│ ┌───────────────────────────────────────────────────────────────────┐ │
│ │ Jupyter Extension │ │
│ │ │ │
│ │ Notebook Document ◄───► Kernel (Python) ───► Outputs │ │
│ │ ▲ │ │
│ └────────────────────────────────────┼──────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────────┼──────────────────────────────┐ │
│ │ Notebook MCP Server Extension │ │
│ │ │ │ │
│ │ ┌────────────────────────────────┴───────────────────────────┐ │ │
│ │ │ HTTP Broker (:49777) + Worker Instances (:49778+) │ │ │
│ │ │ │ │ │
│ │ │ execute_code insert_cell list_cells get_output ... │ │ │
│ │ └────────────────────────────────────────────────────────────┘ │ │
│ └───────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
│
│ HTTP (MCP Protocol)
▼
┌───────────────────────────────┐
│ AI Agent │
│ (Claude Code, Cursor, etc) │
└───────────────────────────────┘
How It Works
- Extension embeds an HTTP MCP layer with broker + worker roles (default broker port
49777)
- AI agent (Claude Code, Cursor Agent, etc.) sends tool calls via MCP protocol
- Broker routes requests to the window that owns the target notebook URI
- Worker uses VS Code / Cursor APIs to manipulate notebook state in its own window
- Changes appear instantly in the editor
- Outputs are captured and returned to the agent
This enables true interactive notebook sessions with AI agents in VS Code and Cursor.