JupyterMCP - Jupyter Notebook Model Context Protocol Integration

JupyterMCP - Jupyter Notebook Model Context Protocol Integration

site icon
2025.04.02 26
Jupyter NotebookJupyter集成AI辅助编程数据分析工具开发效率
JupyterMCP是一个将Jupyter Notebook与Claude AI通过Model Context Protocol (MCP)集成的工具,允许Claude直接与Jupyter Notebook交互和控制。该工具支持AI辅助的代码执行、数据分析、可视化等功能,专为Jupyter Notebook 6.x版本设计。
View on GitHub

Overview

基本能力

产品定位

JupyterMCP旨在通过MCP协议将Jupyter Notebook与Claude AI无缝集成,提供AI辅助的代码执行和数据分析能力。

核心功能

  • 双向通信:通过WebSocket服务器连接Claude AI和Jupyter Notebook
  • 单元格操作:插入、执行和管理笔记本单元格
  • 笔记本管理:保存笔记本和获取笔记本信息
  • 单元格执行:运行特定单元格或执行笔记本中的所有单元格
  • 输出检索:获取执行单元格的输出内容,支持文本限制选项

适用场景

  • AI辅助的代码编写和调试
  • 自动化数据分析和可视化
  • 教学和演示中的实时代码执行
  • 自动化报告生成

工具列表

  • WebSocket Server (jupyter_ws_server.py):在Jupyter中建立WebSocket服务器,桥接笔记本与外部客户端的通信
  • Client JavaScript (client.js):在笔记本中运行以处理操作(插入单元格、执行代码等)
  • MCP Server (jupyter_mcp_server.py):实现Model Context Protocol并连接到WebSocket服务器

常见问题解答

  • 连接问题:如果遇到连接超时,客户端包含重连机制,也可以尝试重启WebSocket服务器
  • 单元格执行问题:检查单元格内容是否为有效的Python/Markdown,并确保笔记本内核正在运行
  • WebSocket端口冲突:如果默认端口(8765)已被使用,服务器会自动尝试找到可用端口

使用教程

使用依赖

  • Python 3.12或更新版本
  • uv包管理器
  • Claude AI桌面应用程序

安装uv

Mac:

brew install uv

Windows (PowerShell):

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

安装教程

  1. 克隆仓库:
git clone https://github.com/jjsantos01/jupyter-notebook-mcp.git
  1. 创建虚拟环境并安装jupyter-mcp内核:
uv run python -m ipykernel install --name jupyter-mcp
  1. (可选) 安装额外的Python包:
uv pip install seaborn
  1. 配置Claude桌面集成: 编辑claude_desktop_config.json文件,添加MCP服务器配置。

调试方式

  1. 启动Jupyter Notebook服务器:
uv run jupyter nbclassic
  1. 创建新笔记本并选择jupyter-mcp内核

  2. 在笔记本单元格中运行初始化代码:

import sys
sys.path.append('/path/to/jupyter-notebook-mcp/src')
from jupyter_ws_server import setup_jupyter_mcp_integration
server, port = setup_jupyter_mcp_integration()
  1. 启动启用了MCP的Claude桌面应用

外部客户端测试

uv run python src/jupyter_ws_external_client.py

批量测试所有命令:

uv run python src/jupyter_ws_external_client.py --batch

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。