Generated by /repo-architecture skill v2.0.0

NotebookLM MCP Architecture

An MCP server that enables AI coding agents (Claude Code, Codex, Cursor) to query Google NotebookLM for zero-hallucination, source-grounded answers powered by Gemini 2.5. The server automates a headless Chromium browser via Patchright to interact with the NotebookLM web UI, managing authentication, sessions, and a local notebook library. It communicates with clients over stdio using the Model Context Protocol, and can be exposed over HTTP/SSE via supergateway when containerized.

Author: Gerome Dexheimer — License: MIT — Source: github.com/PleasePrompto/notebooklm-mcp

Component Classification

ComponentClassRole
MCP Server (index.ts)PrimaryEntry point; registers tools, resources, and request handlers
Tool Handlers (tools/handlers.ts)PrimaryImplements all 17 MCP tool operations
Session Manager (session/)PrimaryBrowser session lifecycle, pooling, timeout cleanup
Auth Manager (auth/)PrimaryGoogle login, cookie persistence, state validation
Notebook Library (library/)SecondaryLocal JSON library of saved NotebookLM URLs with metadata
Tool Definitions (tools/definitions/)SecondaryMCP tool schemas and dynamic descriptions
Resource Handlers (resources/)SecondaryMCP resource endpoints for library access
Settings Manager (utils/settings-manager.ts)AuxiliaryTool profile filtering (minimal/standard/full)
Stealth Utils (utils/stealth-utils.ts)AuxiliaryHuman-like typing, mouse movements, random delays
Cleanup Manager (utils/cleanup-manager.ts)AuxiliaryDeep system scan and removal of all NotebookLM data
CLI Handler (utils/cli-handler.ts)Auxiliarynpx notebooklm-mcp config subcommand
Google NotebookLMExternalWeb application providing Gemini 2.5 Q&A over uploaded documents
Patchright / ChromiumExternalStealth browser automation (Playwright fork)
supergatewayExternalBridges stdio MCP to HTTP/SSE for Docker deployment
MCP Tools
17
Source Files
18
Language
TypeScript
Runtime
Node.js 18+
Transport
stdio / HTTP+SSE
Browser Engine
Patchright (Chromium)

2. Runtime Architecture

Diagram A — Runtime Request Flow

stdio stdio (Docker) tool calls auth check Patchright login flow HTTPS Claude Code MCP Client / CLI AI coding agent supergateway HTTP+SSE bridge Docker transport NotebookLM MCP Server TypeScript / @modelcontextprotocol/sdk 17 tools, 2 resources, tool profiles Session Manager BrowserSession + SharedContext Pooled sessions, auto-cleanup Auth Manager Google login + state persistence Cookies, Chrome profile Patchright Chromium Stealth browser automation Human-like typing, mouse, delays Google NotebookLM Gemini 2.5 — zero-hallucination Q&A Legend Primary path Internal call Docker bridge

Request Flow: ask_question

  1. Claude Code sends a tools/call JSON-RPC request over stdio (or HTTP via supergateway in Docker mode).
  2. The MCP Server dispatches to ToolHandlers.handleAskQuestion().
  3. The handler resolves the notebook URL from the library (by ID, URL, or active notebook fallback).
  4. SessionManager returns an existing BrowserSession or creates a new one using the SharedContextManager, which loads persisted auth state into a Patchright browser context.
  5. The BrowserSession navigates to the NotebookLM URL, types the question with human-like behavior (stealth utils), and waits for the Gemini 2.5 answer to fully render.
  6. The answer is extracted from the DOM, appended with a follow-up reminder, and returned as a JSON tool result.

3. Internal Module Map

graph TD subgraph Entry INDEX["index.ts
MCP Server"] end subgraph Tools DEFS["tools/definitions.ts"] HAND["tools/handlers.ts"] D_AQ["definitions/ask-question.ts"] D_NM["definitions/notebook-management.ts"] D_SM["definitions/session-management.ts"] D_SY["definitions/system.ts"] end subgraph Session SMGR["session-manager.ts"] BSESS["browser-session.ts"] SCTX["shared-context-manager.ts"] end subgraph Auth AMGR["auth-manager.ts"] end subgraph Library NLIB["notebook-library.ts"] LTYP["library/types.ts"] end subgraph Utils LOG["logger.ts"] STL["stealth-utils.ts"] CLN["cleanup-manager.ts"] PGU["page-utils.ts"] SET["settings-manager.ts"] CLI["cli-handler.ts"] end subgraph Config CFG["config.ts"] TYP["types.ts"] ERR["errors.ts"] end INDEX --> DEFS INDEX --> HAND INDEX --> SMGR INDEX --> AMGR INDEX --> NLIB INDEX --> SET INDEX --> CLI DEFS --> D_AQ DEFS --> D_NM DEFS --> D_SM DEFS --> D_SY HAND --> SMGR HAND --> AMGR HAND --> NLIB HAND --> CLN SMGR --> BSESS SMGR --> SCTX SMGR --> AMGR BSESS --> SCTX BSESS --> STL BSESS --> PGU AMGR --> STL SCTX --> AMGR

4. Storage Model

All persistent data is stored on the local filesystem under cross-platform paths managed by the env-paths library. In Docker, a named volume maps to /data.

PathFormatContents
~/.local/share/notebooklm-mcp/browser_state/state.jsonJSONSaved browser cookies and localStorage for Google auth
~/.local/share/notebooklm-mcp/browser_state/session.jsonJSONSession metadata (timestamps, message counts)
~/.local/share/notebooklm-mcp/chrome_profile/DirectoryPersistent Chromium user profile (fingerprint, cache)
~/.local/share/notebooklm-mcp/chrome_profile_instances/DirectoryCloned profiles for isolated multi-instance sessions
~/.config/notebooklm-mcp/library.jsonJSONNotebook library: URLs, names, tags, usage counts
~/.config/notebooklm-mcp/settings.jsonJSONTool profile setting (minimal/standard/full)
Docker volume: The notebooklm_data named volume persists auth state and library data across container restarts. It is mapped to /root/.local/share/notebooklm-mcp inside the container.

5. Public Interfaces (MCP Tools)

The server exposes up to 17 MCP tools, filtered by the active profile. Three profiles are available: minimal (5 tools), standard (11 tools), and full (17 tools).

Core Tools (minimal profile)

ToolParametersDescription
ask_questionquestion (required), session_id, notebook_id, notebook_url, show_browser, browser_optionsAsk NotebookLM a question; returns Gemini 2.5 answer grounded in notebook sources
get_healthReturns auth status, active sessions, configuration summary
list_notebooksLists all notebooks in the local library
select_notebookidSets the active default notebook for subsequent queries
get_notebookidFetches metadata for a specific notebook by ID

Library & Sync Tools (standard profile adds these)

ToolParametersDescription
setup_authshow_browser, force_fresh, browser_optionsOpens browser for manual Google login; persists auth state
list_sessionsReturns active browser sessions with age and message counts
add_notebookurl, name, description, topics[], tags[]Adds a NotebookLM URL to the local library with metadata
update_notebookid, optional fieldsModifies metadata fields on a library notebook
search_notebooksqueryFull-text search across notebook names, descriptions, topics, tags
replace_bundle_sourcebundle_path, source_name, remove_existing, notebook selectors, browser optionsReplaces a single source document in a NotebookLM notebook from a local file

Advanced Tools (full profile adds these)

ToolParametersDescription
cleanup_dataconfirm, preserve_libraryDeep system scan; previews or deletes all NotebookLM data
re_authshow_browser, browser_optionsFull re-authentication: closes sessions, clears data, fresh login
remove_notebookidRemoves a notebook from the library and closes its sessions
reset_sessionsession_idResets a session's chat history without closing the browser
close_sessionsession_idCloses a specific browser session and frees resources
get_library_statsAggregate statistics: total notebooks, usage counts, tags

MCP Resources

URIDescription
notebooklm://libraryJSON representation of the full library (active notebook, stats, all entries)
notebooklm://library/{id}Metadata for a specific notebook (template with completion support)

6. Repository Structure

notebooklm-mcp/
  package.json              # npm package config, scripts, dependencies
  tsconfig.json             # TypeScript compiler options (ES2022, Node16)
  Dockerfile                # Multi-stage: node:20-slim + Chromium + supergateway
  docker-compose.yml        # Service definition with hosting_web network
  README.md                 # Usage guide and installation instructions
  CHANGELOG.md              # Version history (1.0.0 through unreleased)
  LICENSE                   # MIT license
  docs/
    tools.md                # Tool reference documentation
    usage-guide.md           # Patterns and workflow tips
    configuration.md         # Environment variable reference
    troubleshooting.md       # Common issues and solutions
  scripts/                  # Utility scripts
  src/
    index.ts                # MCP server entry point (NotebookLMMCPServer class)
    config.ts               # Configuration system (defaults + env overrides)
    types.ts                # Global TypeScript type definitions
    errors.ts               # Custom error classes (RateLimitError, etc.)
    auth/
      auth-manager.ts       # Google auth: login, state persistence, validation
    session/
      session-manager.ts    # Session pool lifecycle, timeout cleanup
      browser-session.ts    # Single browser session: ask, reset, bundle sync
      shared-context-manager.ts  # Shared Patchright browser context singleton
    library/
      notebook-library.ts   # JSON-backed notebook library CRUD
      types.ts              # Library-specific type definitions
    tools/
      index.ts              # Re-exports definitions + handlers
      definitions.ts        # Aggregates tool schemas from sub-modules
      handlers.ts           # All 17 tool handler implementations
      definitions/
        ask-question.ts     # Dynamic ask_question schema with library context
        notebook-management.ts  # add/update/remove/search/select schemas
        session-management.ts   # list/close/reset session schemas
        system.ts           # health, auth, cleanup schemas
    resources/
      resource-handlers.ts  # MCP resource + template handlers
    utils/
      logger.ts             # Structured logging utility
      stealth-utils.ts      # Human-like typing, mouse, delays
      cleanup-manager.ts    # Deep system cleanup scanner
      page-utils.ts         # DOM interaction helpers (wait for answer, etc.)
      settings-manager.ts   # Tool profile filtering + persistence
      cli-handler.ts        # CLI config subcommand handler
        

7. Deployment & Operations

Local (npx / CLI)

The simplest deployment mode. The MCP server runs as a child process of the AI agent, communicating over stdio.

# Install as MCP server for Claude Code
claude mcp add notebooklm npx notebooklm-mcp@latest

# Or run directly
npx notebooklm-mcp@latest

# Configure tool profiles
npx notebooklm-mcp config set profile minimal
        

Docker

The Dockerfile builds a node:20-slim image with Chromium system dependencies, Patchright's bundled Chromium, and supergateway for HTTP/SSE transport.

SettingValue
Base imagenode:20-slim
Exposed port3300 (supergateway HTTP/SSE)
Entry commandsupergateway --port 3300 --stdio "node /app/dist/index.js"
Named volumenotebooklm_data at /root/.local/share/notebooklm-mcp
Networkhosting_web (external, Traefik-connected)
Restart policyunless-stopped

Environment Variables

VariableDefaultDescription
HEADLESStrueRun Chromium in headless mode
MAX_SESSIONS3Maximum concurrent browser sessions
SESSION_TIMEOUT900Session inactivity timeout in seconds
NOTEBOOK_URLDefault NotebookLM notebook URL
AUTO_LOGIN_ENABLEDfalseEnable automatic Google login
LOGIN_EMAILGoogle email for auto-login
LOGIN_PASSWORDGoogle password for auto-login
STEALTH_ENABLEDtrueEnable human-like browser behavior
NOTEBOOKLM_PROFILEstandardTool profile: minimal, standard, or full
NOTEBOOKLM_DISABLED_TOOLSComma-separated list of tools to disable
# Build and start
cd /home/rod/_rod/_notebooklm-mcp
docker compose up -d --build

# View logs
docker logs -f notebooklm-mcp

# Re-authenticate (Docker helper)
docker exec notebooklm-mcp xvfb-reauth
        

8. Dependencies

Runtime Dependencies

PackageVersionPurpose
@modelcontextprotocol/sdk^1.0.0MCP server framework (Server, StdioServerTransport, types)
patchright^1.48.2Stealth Playwright fork for browser automation with anti-detection
zod^3.22.0Runtime schema validation
dotenv^16.4.0Environment variable loading from .env files
env-paths^3.0.0Cross-platform XDG-compliant data/config directory paths
globby^14.1.0Advanced glob file pattern matching (cleanup scanner)

Dev Dependencies

PackageVersionPurpose
typescript^5.3.3TypeScript compiler (target: ES2022)
tsx^4.7.0TypeScript execution for development
@types/node^20.11.0Node.js type definitions

System Dependencies (Docker)

PackagePurpose
xvfbVirtual framebuffer for headless Chromium rendering
[email protected]Bridges stdio MCP server to HTTP/SSE endpoints
Chromium system libs (20+ packages)GTK, NSS, ALSA, Cairo, etc. required by Patchright's Chromium

9. Constraints & Risks

ItemSeverityDetails
Browser automation fragility Medium The server scrapes the NotebookLM web UI via DOM selectors. Google UI changes can break question submission or answer extraction at any time.
Rate limiting Medium Free Google accounts are limited to ~50 queries/day per account. The server detects rate limits and suggests account switching via re_auth.
Google account risk Medium Automated browser usage may trigger Google's abuse detection. Stealth mode (human-like typing, random delays) mitigates this, but a dedicated Google account is recommended.
No official API High NotebookLM has no public API. This project relies entirely on browser automation of the web UI, making it inherently brittle.
Auth cookie expiry Low Google session cookies expire after ~24 hours. The auth manager validates cookie age and prompts re-authentication when needed.
supergateway SSE reconnection Low The Dockerfile includes a runtime patch to supergateway to handle SSE reconnections gracefully (clears old transport before reconnecting).