Skip to main content
Glama
caryan

vscode-notebook-mcp

by caryan

vscode-notebook-mcp

一个 VS Code 扩展,将您 VSCode 编辑器中的 Jupyter 笔记本暴露给兼容 MCP 的 AI 代理(例如 Claude Code)。代理可以读取、编辑并在 VS Code 正在使用的同一内核中运行单元格。

状态:预 alpha 版本,个人开发者项目。全新构建;非分支。

工具 (12)

发现

工具

描述

notebook_list_open

列出所有打开的笔记本,包含 URI、文件名、单元格数量以及当前活动的笔记本

notebook_list_cells

列出单元格,包含索引、类型、语言、预览、执行状态

notebook_get_cell_content

获取单元格的完整源代码

notebook_get_cell_output

获取单元格的输出(文本、错误、base64 格式的图像)

单元格操作

工具

描述

notebook_insert_cell

在任意位置插入代码或 Markdown 单元格;可选择是否执行

notebook_edit_cell

替换现有单元格的内容

notebook_delete_cell

按索引删除单元格

执行

工具

描述

notebook_run_cell

执行现有的代码单元格并返回输出

notebook_clear_cell_output

清除单个单元格的输出

notebook_clear_all_outputs

清除所有单元格的输出

内核

工具

描述

notebook_get_kernel_info

语言、状态、笔记本 URI

notebook_select_kernel

通过 kernel_id 以编程方式选择,或在省略时打开内核选择器

所有工具都接受可选的 notebook_uri(省略则使用活动的笔记本编辑器)和 response_format"markdown""json")。

Related MCP server: lsp-mcp

设置

  1. 如果尚未安装,请在 VS Code 中安装 Jupyter 扩展

  2. 构建并运行此扩展:

    npm install
    npm run build

    然后在 VS Code 中打开此文件夹并按 F5 启动加载了该扩展的扩展开发主机。

  3. 添加到您的 MCP 客户端配置中:

    {
      "mcpServers": {
        "notebook": {
          "url": "http://127.0.0.1:49777/mcp"
        }
      }
    }
  4. 在扩展开发主机中打开一个 .ipynb 文件。在状态栏中查找 🪐 :49777 指示器。

配置

设置

默认值

描述

notebook-mcp.port

49777

首选端口。如果被占用则自动递增(最多 +99)。

命令

  • Notebook MCP: Restart Server

  • Notebook MCP: Show Server Info

架构

┌─────────────────────────────────────────────────────────┐
│                    VS Code window                       │
│                                                         │
│  ┌───────────────────────────────────────────────────┐  │
│  │  Jupyter extension (ms-toolsai.jupyter)           │  │
│  │                                                   │  │
│  │  Notebook document  ◄──►  Kernel  ──►  Outputs    │  │
│  └───────────────────────────────────────────────────┘  │
│                          ▲                              │
│                          │ vscode.NotebookEdit,         │
│                          │ notebook.cell.execute,       │
│                          │ jupyter.kernels.getKernel    │
│                          │                              │
│  ┌───────────────────────┴───────────────────────────┐  │
│  │  This extension                                   │  │
│  │                                                   │  │
│  │   HTTP server :49777  ──►  MCP tools (12)         │  │
│  │   (StreamableHTTPServerTransport)                 │  │
│  └───────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────┘
                              │ HTTP (MCP protocol)
                              ▼
                ┌───────────────────────────────┐
                │   AI agent                    │
                │   (Claude Code, Cursor, etc.) │
                └───────────────────────────────┘

实现说明

  • 写入操作通过 vscode.NotebookEdit + vscode.WorkspaceEdit 进行,保留撤销/重做功能。

  • 执行操作分发 notebook.cell.execute,并通过轮询 cell.executionSummary.successboolean 值来等待(VS Code 在执行开始时立即创建摘要,但只有在内核完成时 success 才会变为布尔值)。

  • 插入的单元格被标记有元数据 ID,以便执行器在由于其他并发编辑导致索引偏移后仍能找到它们。

  • 多笔记本支持:每个工具都接受 notebook_uri。解析逻辑:显式 URI → 在 vscode.workspace.notebookDocuments 中查找(或打开它);否则回退到 vscode.window.activeNotebookEditor

开发

npm install
npm run build       # esbuild bundle
npm run watch       # rebuild on change
npm run typecheck   # tsc --noEmit
npm test            # vitest (no tests yet)

在 VS Code 中按 F5 启动扩展开发主机。

参考

与本项目类似的其它项目:

我从零开始构建此项目是为了学习,并留有空间来调整设计和开发新功能。

许可证

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact with VS Code's language server protocol features (definitions, references, diagnostics) and debugger (breakpoints, stepping, variable inspection) via an MCP server.
    9 npm
    1
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables external agents to run, edit, create, and manage the Jupyter notebook the user is actively editing in VS Code, headlessly and without approval dialogs. Works with any MCP client and is Jupyter-optional for document operations.
    1
    MIT