这是一个使用 FastMCP 框架 构建的 FastMCP 服务器,提供与 Jupyter 笔记本交互的工具。
确保已安装 uv。 要使用此服务器与 cursor、claude desktop 或任何其他 MCP 客户端一起使用,请在您的 mcp 配置文件中添加以下内容:
{
"mcpServers": {
"jupyter-notebook": {
"command": "uv",
"args": [
"run",
"--with",
"fastmcp>=2.8.1",
"python",
"<绝对路径到 jupyter_mcp_server>/main.py"
]
}
}
}
运行测试客户端以查看所有功能:
python test_client.py
fastmcp - MCP 服务器框架此 MCP 服务器提供了以下用于处理 Jupyter 笔记本的工具:
read_notebook_cells按可选的单元格类型过滤从 Jupyter 笔记本读取单元格。
参数:
notebook_path (str): .ipynb 文件的路径cell_type (可选 str): 按单元格类型过滤 ('code', 'markdown', 'raw')add_cell_to_notebook在指定位置向 Jupyter 笔记本添加一个新单元格。
参数:
notebook_path (str): .ipynb 文件的路径cell_content (str): 新单元格的内容cell_type (str,默认值="code"): 单元格类型 ('code', 'markdown', 'raw')position (可选 int): 插入单元格的位置(默认值:追加到最后)metadata (可选 dict): 可选的单元格元数据execute_notebook_cell执行 Jupyter 笔记本中的特定单元格。
参数:
notebook_path (str): .ipynb 文件的路径cell_index (int): 要执行的单元格索引(基于 0)kernel_name (str,默认值="python3"): 使用的 Jupyter 内核timeout (int,默认值=30): 执行超时时间(秒)execute_entire_notebook顺序执行 Jupyter 笔记本中的所有代码单元格。
参数:
notebook_path (str): .ipynb 文件的路径kernel_name (str,默认值="python3"): 使用的 Jupyter 内核timeout_per_cell (int,默认值=3.0): 每个单元格的超时时间(秒)stop_on_error (bool,默认值=True): 如果单元格失败是否停止执行get_notebook_info获取有关 Jupyter 笔记本的基本信息。
参数:
notebook_path (str): .ipynb 文件的路径