Jupyter MCP Server Skill
Control Jupyter Notebooks through Model Context Protocol (MCP) using the datalayer/jupyter-mcp-server.
When to Use
Use this skill when:
- Agents (Codex, Claude Code, etc.) need to work with Jupyter notebooks
- You want to read/edit/execute notebook cells programmatically
- You need real-time notebook manipulation without manual conversion
- Working with data science workflows requiring notebook interaction
- Converting notebooks to LaTeX/PDF (NEW)
- Creating academic papers and presentations from notebooks (NEW)
NOT for:
- Simple notebook → script conversion (use jupytext/nbconvert directly)
- One-off notebook execution (use
jupyter nbconvert --execute) - Manual notebook editing (use Jupyter UI)
Prerequisites
- Running Jupyter Server (JupyterLab 4.4.1+ recommended)
- uv installed (
~/.local/bin/uvor~/.local/bin/uvx) - Jupyter token for authentication
Architecture
Agent (Cursor/Codex/Claude Code)
↓
MCP Client (spawned via sessions_spawn with runtime="acp")
↓
jupyter-mcp-server (via uvx)
↓
Jupyter Server API
↓
Notebook (.ipynb)
Setup Jupyter Server
Quick Start (Local)
# Install JupyterLab with real-time collaboration
pip install jupyterlab==4.4.1 jupyter-collaboration==4.0.2 jupyter-mcp-tools>=0.1.4 ipykernel pycrdt
# Start server
jupyter lab --port 8888 --IdentityProvider.token MY_TOKEN --ip 0.0.0.0
Verify Setup
Open a notebook and type content in a cell. You should see:
- Tab shows "×" (unsaved)
- After ~2 seconds, "×" changes to "●" (auto-saved)
This confirms real-time collaboration is working.
MCP Server Configuration
The server is run via uvx jupyter-mcp-server@latest with environment variables:
Required Environment Variables
JUPYTER_URL=http://localhost:8888 # Jupyter server URL
JUPYTER_TOKEN=MY_TOKEN # Authentication token
Optional Environment Variables
DOCUMENT_ID=notebooks/analysis.ipynb # Default notebook to open
ALLOW_IMG_OUTPUT=true # Enable image/plot outputs (default: true)
DOCUMENT_URL=http://localhost:8888 # Separate document server (if different)
RUNTIME_URL=http://localhost:8888 # Separate runtime server (if different)
DOCUMENT_TOKEN=token1 # Separate document token (if different)
RUNTIME_TOKEN=token2 # Separate runtime token (if different)
Available Tools
File & Kernel Management
list_files— List files/directories in Jupyter filesystemlist_kernels— List available and running kernelsconnect_to_jupyter— Connect to Jupyter server dynamically
Notebook Lifecycle
use_notebook— Connect to notebook, create new, or switch between notebookslist_notebooks— List all notebooks and their statusrestart_notebook— Restart kernel for a notebookunuse_notebook— Disconnect from notebook and release resourcesread_notebook— Read all cells (brief or detailed format)
Cell Operations (Basic)
read_cell— Read full content (metadata, source, outputs) of one cellinsert_cell— Insert new code/markdown cell at positiondelete_cell— Delete cell at indexmove_cell— Move cell from one position to anotheroverwrite_cell_source— Replace cell source entirelyedit_cell_source— Surgical find-and-replace editsexecute_cell— Execute cell with timeout, returns multimodal outputinsert_execute_code_cell— Insert + execute in one stepexecute_code— Execute code directly in kernel (supports magic commands)
Advanced Features (Extended)
Cell History & Tracking
diff_cell— Compare cell versions and show edit historyrollback_cell— Restore cell to previous version
Smart Search & Analysis
find_cells— Search cells by pattern, type, errors, or outputsget_cell_dependencies— Analyze variable dependencies between cellsget_affected_cells— Find cells affected by changes
Batch Operations
execute_cells— Execute multiple cells in sequencebatch_edit_cells— Edit multiple cells at once
Output Filtering
get_cell_output— Get specific output types (images, HTML, etc.)get_dataframe_output— Extract pandas DataFrames from outputs
Annotations & Flags
annotate_cell— Add notes/TODOs to cellsget_cell_annotations— Get cell annotationsflag_cell— Mark cells for reviewlist_flagged_cells— List all flagged cells
Execution Analytics
get_cell_execution_time— Get cell execution durationget_slowest_cells— Find performance bottlenecksget_cell_memory_usage— Get memory usage per cell
Smart Insertion
insert_cell_after_imports— Insert after import statementsinsert_cell_before_plots— Insert before visualizationsinsert_cleanup_cell— Add cleanup code for temp variables
Cell Templates
insert_dataframe_inspect_cell— Add DataFrame inspection codeinsert_plot_cell— Add plotting code (line/bar/scatter)insert_error_handling_cell— Wrap cell in try/except
Kernel Inspection
list_kernel_variables— List all kernel variablesget_variable_info— Get variable type, size, shapeget_variable_value— Get variable valuecheck_cell_variables— Check for undefined variables
Validation & Testing
validate_notebook— Check for errors, undefined vars, execution issuescheck_reproducibility— Test if notebook runs cleanly from top to bottomcompare_cell_outputs— Compare outputs between runssave_cell_output_baseline— Save output for regression testingcompare_with_baseline— Compare current output with baseline
Magic Commands
timeit_cell— Execute cell with %%timeitprofile_cell— Execute cell with %%prun profilerdebug_cell— Execute cell in debug mode
Refactoring
extract_to_function— Extract cell code into reusable functionmerge_cells— Merge multiple cells into onesplit_cell— Split cell at specific line
Section Management
list_sections— List all markdown section headersget_section_cells— Get cells belonging to a sectionexecute_section— Execute all cells in a sectioninsert_section_header— Insert markdown section header
LaTeX & PDF Export (NEW) 📄
notebook_to_latex— Convert notebook to LaTeX sourcenotebook_to_pdf— Direct notebook to PDF exportcompile_latex— Compile .tex file to PDFlatex_validate— Validate LaTeX syntaxlatex_edit— Edit LaTeX source fileslatex_create— Create new LaTeX document from templatelatex_insert_figure— Insert figures into LaTeXlatex_insert_table— Insert tables into LaTeXpdf_merge— Merge multiple PDFspdf_extract_pages— Extract pages from PDFpdf_metadata— Get/set PDF metadataapply_design_template— NEW: Apply professional design templates (beamer-semantic, ieee-paper, technical-report)get_design_templates— NEW: List available design templates
JupyterLab Integration (when enabled)
notebook_run-all-cells— Execute all cells sequentiallynotebook_get-selected-cell— Get currently selected cell info
Prompts
jupyter-cite— Cite specific cells from notebook (like @ in IDEs)
Tool Documentation
- Basic Tools: See tools.md for complete API reference
- Advanced Features: See advanced-features.md for extended tools (40+ additional tools)
- LaTeX & PDF Export: See latex-pdf-extension.md for LaTeX/PDF tools (13 tools)
- LaTeX Design Guide: See latex-design-guide.md for professional typography & styling (NEW)
Usage Pattern
1. Start Jupyter Server
jupyter lab --port 8888 --IdentityProvider.token MY_TOKEN
2. Spawn ACP Agent with MCP
Use sessions_spawn with runtime="acp" and configure MCP in the agent's config.
Example for Cursor/Codex:
# In agent config (e.g., ~/.codex/config.json or cursor settings)
{
"mcpServers": {
"jupyter": {
"command": "uvx",
"args": ["jupyter-mcp-server@latest"],
"env": {
"JUPYTER_URL": "http://localhost:8888",
"JUPYTER_TOKEN": "MY_TOKEN",
"ALLOW_IMG_OUTPUT": "true"
}
}
}
}
3. Agent Instructions
Provide clear context to the agent:
You have access to a Jupyter notebook server via MCP.
Current notebook: notebooks/analysis.ipynb
Tasks:
1. Read all cells to understand current state
2. Fix the bug in cell 5 (NameError on variable 'df')
3. Execute cells 5-8 to verify the fix
4. Add a new cell at the end with a summary plot
Use these tools:
- read_notebook() to see all cells
- edit_cell_source() for surgical edits
- execute_cell() to run and check outputs
- insert_execute_code_cell() to add new code
Best Practices
For Agents
- Read before writing — Always
read_notebook()orread_cell()first - Surgical edits — Use
edit_cell_source()for small fixes, notoverwrite_cell_source() - Execute to verify — Run
execute_cell()after changes to catch errors - Context awareness — Read surrounding cells to understand data flow
- Multimodal outputs — Check for images/plots in cell outputs
- Use advanced features — Leverage
find_cells(),validate_notebook(),check_cell_variables()for smart workflows - Track dependencies — Use
get_cell_dependencies()before refactoring - Profile performance — Use
get_slowest_cells()andtimeit_cell()to optimize - Validate before commit — Run
check_reproducibility()to ensure clean execution - Annotate complex logic — Use
annotate_cell()for future reference
For Prompts
- Break down tasks — Split complex workflows into steps
- Provide context — Mention installed packages, dataset fields, current directory
- Set expectations — Clarify what "done" looks like
- Iterate — Let agent read → edit → execute → verify in loops
- Use sections — Reference notebook sections for large notebooks
- Request validation — Ask agent to run
validate_notebook()at the end
For Error Handling
- Always set
timeoutonexecute_cell()(default 30s) - Check
successfield in execution results - Parse
error.ename,error.evalue,error.tracebackfor debugging - Use
check_cell_variables()to catch undefined variable errors early - Flag problematic cells with
flag_cell()for review
Security Notes
- Arbitrary code execution — Agents can run any Python code in your kernel
- User consent required — Review agent actions before execution
- Token protection — Never expose
JUPYTER_TOKENin logs/commits - Filesystem access — MCP server inherits Jupyter's filesystem permissions
Troubleshooting
Connection Issues
# Test Jupyter API manually
curl -H "Authorization: token MY_TOKEN" http://localhost:8888/api
# Check if jupyter-mcp-server can connect
uvx jupyter-mcp-server@latest --help
Auto-save Not Working
- Verify
jupyter-collaborationis installed:pip show jupyter-collaboration - Check JupyterLab version:
jupyter lab --version(should be 4.4.1+) - Restart JupyterLab server
Image Outputs Not Showing
- Set
ALLOW_IMG_OUTPUT=true - Ensure agent/client supports multimodal (e.g., Gemini 2.5 Pro, Claude with vision)
- Check MCP client can parse base64 image data
References
Example: Spawn Codex with Jupyter MCP
# In OpenClaw session
sessions_spawn(
runtime="acp",
task="Fix the data cleaning bug in notebooks/analysis.ipynb cell 5",
mode="run",
# Agent will use MCP config from its own settings
# Make sure Codex/Cursor has jupyter MCP server configured
)
Example: Manual Test (without agent)
# Start Jupyter
jupyter lab --port 8888 --IdentityProvider.token test123
# In another terminal, test MCP server
export JUPYTER_URL=http://localhost:8888
export JUPYTER_TOKEN=test123
export ALLOW_IMG_OUTPUT=true
uvx jupyter-mcp-server@latest
# Server will start and wait for MCP client connections
Status: Production-ready (73+ tools available)
Maintainer: Datalayer
Extensions: LaTeX/PDF Export (v1.2.0) + Professional Design Templates
Last Updated: 2026-06-15