NotebookLM MCP 是一款专业的 MCP 服务器,用于实现 Google NotebookLM 的自动化操作。它已发布到 PyPI,可直接用于生产环境。
# 安装 UV(现代 Python 包管理器)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 从 PyPI 安装 NotebookLM MCP
uv add notebooklm-mcp
# 使用你的 NotebookLM URL 进行初始化
uv run notebooklm-mcp init https://notebooklm.google.com/notebook/YOUR_NOTEBOOK_ID
初始化后会发生什么:
notebooklm-config.json
文件,保存你的配置信息chrome_profile_notebooklm/
文件夹,用于持久认证# 启动服务器(为 MCP 客户端提供 STDIO 服务)
uv run notebooklm-mcp --config notebooklm-config.json server
# 启动 HTTP 服务器,用于 Web 测试
uv run notebooklm-mcp --config notebooklm-config.json server --transport http --port 8001
# 交互式聊天模式
uv run notebooklm-mcp --config notebooklm-config.json chat --message "Who are you ?"
如果你想为这个项目做贡献,可以查看我们的 Taskfile,以获得更好的开发体验:
git clone https://github.com/khengyun/notebooklm-mcp.git
cd notebooklm-mcp
# 使用开发工具完成设置
task setup
# 显示所有可用的开发任务
task --list
如果你更喜欢使用 pip 而不是 UV,可以按照以下步骤安装:
# 使用 pip 安装
pip install notebooklm-mcp
# 初始化
notebooklm-mcp init https://notebooklm.google.com/notebook/YOUR_NOTEBOOK_ID
# 启动服务器
notebooklm-mcp --config notebooklm-config.json server
运行 init
命令后,你的工作目录将包含以下内容:
your-project/
├── notebooklm-config.json # 配置文件
├── chrome_profile_notebooklm/ # 浏览器配置文件(用于持久认证)
│ ├── Default/ # Chrome 配置文件数据
│ ├── SingletonSocket # 会话文件
│ └── ... # 其他 Chrome 数据
└── your-other-files
关键文件说明:
notebooklm-config.json
:包含笔记本 ID、服务器设置、认证配置等信息chrome_profile_notebooklm/
:存储 Google 认证会话,支持无头操作工具 | 描述 | 参数 |
---|---|---|
healthcheck |
服务器健康状态检查 | 无 |
send_chat_message |
向 NotebookLM 发送消息 | message: str , wait_for_response: bool |
get_chat_response |
超时获取响应 | timeout: int |
chat_with_notebook |
完整的交互操作 | message: str , notebook_id?: str |
navigate_to_notebook |
切换笔记本 | notebook_id: str |
get_default_notebook |
获取当前笔记本 | 无 |
set_default_notebook |
设置默认笔记本 | notebook_id: str |
get_quick_response |
即时响应 | 无 |
对于贡献者和高级用户,为了提高生产力,我们提供了一个包含 20 多个自动化任务的综合 Taskfile:
# 📦 依赖管理
task deps-add -- requests # 添加依赖
task deps-add-dev -- pytest # 添加开发依赖
task deps-remove -- requests # 移除依赖
task deps-list # 列出依赖
task deps-update # 更新所有依赖
# 🧪 测试与质量检查
task test # 运行所有测试
task test-quick # 快速验证测试
task test-coverage # 覆盖率分析
task enforce-test # 函数更改后强制测试
task lint # 运行所有代码检查
task format # 格式化代码(Black + isort + Ruff)
# 🏗️ 构建与发布
task build # 构建包
task clean # 清理构建产物
# 🚀 服务器命令
task server-stdio # 启动 STDIO 服务器
task server-http # 启动 HTTP 服务器
task server-sse # 启动 SSE 服务器
# 显示所有可用任务
task --list
💡 使用建议:安装 Task 可获得最佳开发体验:
go install github.com/go-task/task/v3/cmd/task@latest
task server-stdio
# 适用于:LangGraph、CrewAI、AutoGen
task server-http
# 访问地址:http://localhost:8001/mcp
# 适用于:Web 测试、REST API
task server-sse
# 访问地址:http://localhost:8002/
# 适用于:实时流传输
from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport
transport = StreamableHttpTransport(url="http://localhost:8001/mcp")
async with Client(transport) as client:
tools = await client.list_tools()
result = await client.call_tool("healthcheck", {})
# 使用 curl 进行测试
curl -X POST http://localhost:8001/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}'
from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport
# HTTP 传输
transport = StreamableHttpTransport(url="http://localhost:8001/mcp")
client = Client(transport)
tools = await client.list_tools()
from crewai_tools import BaseTool
from fastmcp import Client
class NotebookLMTool(BaseTool):
name = "notebooklm"
description = "Chat with NotebookLM"
async def _arun(self, message: str):
client = Client("http://localhost:8001/mcp")
result = await client.call_tool("chat_with_notebook", {"message": message})
return result
# 首次使用 - 打开浏览器进行登录
notebooklm-mcp init https://notebooklm.google.com/notebook/abc123
# 后续运行 - 使用保存的会话
notebooklm-mcp --config notebooklm-config.json server
# 交互式浏览器登录
notebooklm-mcp --config notebooklm-config.json server
# 检查连接
notebooklm-mcp --config notebooklm-config.json test --notebook YOUR_NOTEBOOK_ID
# 1. 生成配置文件和 Chrome 配置文件,并引导登录
uv run notebooklm-mcp init https://notebooklm.google.com/notebook/YOUR_NOTEBOOK_ID
# 如果你使用 pip 安装,运行:notebooklm-mcp init https://notebooklm.google.com/notebook/YOUR_NOTEBOOK_ID
# 2. 构建容器镜像
docker build -t notebooklm-mcp .
# 3. 挂载配置文件和配置文件目录,运行服务器
docker run -d \
--name notebooklm-mcp \
--restart unless-stopped \
-v $(pwd)/notebooklm-config.json:/app/notebooklm-config.json:ro \
-v $(pwd)/chrome_profile_notebooklm:/app/chrome_profile_notebooklm \
notebooklm-mcp:latest
version: '3.8'
services:
notebooklm-mcp:
image: notebooklm-mcp:latest
build: .
restart: unless-stopped
volumes:
- ./notebooklm-config.json:/app/notebooklm-config.json:ro
- ./chrome_profile_notebooklm:/app/chrome_profile_notebooklm
在运行一次 init
命令,确保 notebooklm-config.json
和 chrome_profile_notebooklm/
存在后,使用 docker compose up -d
启动服务。服务器默认以 STDIO 模式运行;如果你的客户端需要 HTTP/SSE 端口,请在 docker-compose.yml
中取消注释相应端口。
notebooklm-config.json
){
"default_notebook_id": "your-notebook-id",
"headless": true,
"timeout": 30,
"auth": {
"profile_dir": "./chrome_profile_notebooklm"
},
"debug": false
}
export NOTEBOOKLM_NOTEBOOK_ID="your-notebook-id"
export NOTEBOOKLM_HEADLESS=true
export NOTEBOOKLM_DEBUG=false
特性 | 传统 MCP | FastMCP v2 |
---|---|---|
工具注册 | 手动定义模式 | 自动生成 |
类型验证 | 手动验证 | 自动验证 |
错误处理 | 基本处理 | 增强处理 |
开发速度 | 标准速度 | 快 5 倍 |
HTTP 支持 | 有限支持 | 全面支持 |
git clone https://github.com/khengyun/notebooklm-mcp
cd notebooklm-mcp
# 使用 UV(推荐)
uv sync --all-groups
# 或者使用 pip
pip install -e ".[dev]"
# 使用 UV 运行测试
uv run pytest
# 测试覆盖率
uv run pytest --cov=notebooklm_mcp
# 集成测试
uv run pytest tests/test_integration.py
# 或者使用 Taskfile 进行开发测试
task test
task test-coverage
# 使用 UV 格式化代码
uv run black src/ tests/
uv run ruff check src/ tests/
# 类型检查
uv run mypy src/
# 或者使用 Taskfile 快捷命令
task format
task lint
本项目采用 MIT 许可证,详情请参阅 LICENSE 文件。
本项目由 ❤️ FastMCP v2 构建 - 让现代 MCP 开发变得简单!