@taotao7/notebook2rw
v0.1.2
Published
Jupyter Notebook Read/Write MCP Server
Downloads
4
Maintainers
Readme
Notebook R/W MCP 服务器
一个用于读写 Jupyter notebook 文件的 MCP (Model Context Protocol) 服务器。
功能特性
- 📖 读取 notebook: 完整读取 Jupyter notebook 文件内容
- ✏️ 写入 notebook: 创建或覆盖 notebook 文件
- 📋 获取 cells 信息: 查看 notebook 中所有 cells 的概览信息
- 🔄 更新 cell: 修改指定位置的 cell 内容
- ➕ 添加 cell: 在指定位置插入新的 cell
- 🗑️ 删除 cell: 删除指定位置的 cell
安装依赖
pnpm install构建
pnpm build运行
# 开发模式
pnpm dev
# 生产模式
node dist/main.mjs
# 使用启动脚本
./start-mcp.sh🚀 快速配置 Claude Desktop
运行一键配置脚本:
./install-claude-config.sh这将自动:
- 创建 Claude Desktop 配置文件
- 备份现有配置(如果存在)
- 设置正确的 MCP 服务器路径
配置完成后,重启 Claude Desktop 即可使用!
支持的工具
1. read_notebook
读取完整的 notebook 文件内容
参数:
file_path(string): notebook 文件路径
2. write_notebook
写入 notebook 文件
参数:
file_path(string): notebook 文件路径content(object): notebook 内容(标准 Jupyter 格式)
3. get_notebook_cells
获取 notebook 中所有 cells 的信息概览
参数:
file_path(string): notebook 文件路径
4. update_notebook_cell
更新指定 cell 的内容
参数:
file_path(string): notebook 文件路径cell_index(number): cell 索引(从 0 开始)cell_content(object): 新的 cell 内容
5. add_notebook_cell
向 notebook 添加新的 cell
参数:
file_path(string): notebook 文件路径cell(object): 要添加的 cell 内容index(number, 可选): 插入位置,默认添加到末尾
6. delete_notebook_cell
删除指定的 cell
参数:
file_path(string): notebook 文件路径cell_index(number): 要删除的 cell 索引(从 0 开始)
Cell 格式示例
Code Cell
{
"cell_type": "code",
"source": ["print('Hello, World!')", "x = 42"],
"metadata": {},
"execution_count": null,
"outputs": []
}Markdown Cell
{
"cell_type": "markdown",
"source": ["# 标题", "这是markdown内容"],
"metadata": {}
}Raw Cell
{
"cell_type": "raw",
"source": ["原始文本内容"],
"metadata": {}
}Notebook 格式示例
{
"cells": [
{
"cell_type": "markdown",
"source": ["# 我的Notebook"],
"metadata": {}
},
{
"cell_type": "code",
"source": ["print('Hello!')"],
"metadata": {},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}使用注意事项
- 确保 notebook 文件路径正确且可访问
- 写入操作会覆盖现有文件,请谨慎使用
- cell 索引从 0 开始计算
- 建议在修改前先备份重要的 notebook 文件
错误处理
服务器会返回详细的错误信息,包括:
- 文件不存在
- 无效的 notebook 格式
- 索引超出范围
- 权限问题等
技术栈
- TypeScript: 主要编程语言
- @modelcontextprotocol/sdk: MCP 协议实现
- Node.js: 运行时环境
- tsup: 构建工具
