JupyterMCP 实现了 Jupyter Notebook 与 Claude AI 通过 Model Context Protocol (MCP) 的集成。借助该集成,Claude 能够与 Jupyter 笔记本直接交互并进行控制,实现 AI 辅助的代码执行、数据分析、可视化等功能。
uv run jupyter notebook
jupyter_mcp_server.py 笔记本。from jupyter_mcp_server import start_server
start_server()
uv 包管理器](/README.md#安装 uv)brew install uv
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
git clone https://github.com/jjsantos01/jupyter-notebook-mcp.git
jupyter-mcp 内核,以便 Jupyter 安装程序识别:uv run python -m ipykernel install --name jupyter-mcp
uv pip install seaborn
Claude > 设置 > 开发者 > 编辑配置 > claude_desktop_config.json 以包含以下内容:{
"mcpServers": {
"jupyter": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/REPO/FOLDER/src",
"run",
"jupyter_mcp_server.py"
]
}
}
}
用实际的路径替换 /ABSOLUTE/PATH/TO/,例如:
"C:\\Users\\MyUser\\GitHub\\jupyter-notebook-mcp\\src\\"/Users/MyUser/GitHub/jupyter-notebook-mcp/src/如果你之前已经打开了 Claude,请关闭并重新打开。
在连接后,Claude 将具有访问以下工具的能力:
# 检查服务器连通性
ping
# 在指定位置插入单元格并执行它
insert_and_execute_cell
# 保存当前 Jupyter 笔记本
save_notebook
# 获取所有单元格的信息
get_cells_info
# 获取当前笔记本的信息
get_notebook_info
# 按照索引运行特定的单元格
run_cell
# 运行笔记本中的所有单元格
run_all_cells
# 获取特定单元格的输出内容
get_cell_text_output
# 获取特定单元格的图像输出
get_image_output
# 编辑现有单元格的内容
edit_cell_content
# 设置单元格的幻灯片类型
set_slideshow_type
系统由三个主要组件组成:
jupyter_ws_server.py):在 Jupyter 中设置一个 WebSocket 服务器,实现笔记本与外部客户端之间的桥梁通信。client.js):运行在笔记本中以处理操作(插入单元格、执行代码等)。jupyter_mcp_server.py):实现 Model Context Protocol 并连接到 WebSocket 服务器。