DocBuilder MCP Server β Technical Notes
Deep dive on how Sasha wraps
@knowcode/doc-builderinside an MCP runtime. Pair this with the operator playbook (docbuilder-mcp-vercel-playbook.md) for day-to-day usage.
1. Runtime Shape
- Repo location:
claudecodeui/integrations/mcp/docbuilder - Entry point:
server.js(plain ESM, no build step) - Launcher:
run-docbuilder-mcp.js(Node shebang wrapper that setsDOCBUILDER_PROJECT_ROOTand spawns the server) - Transport: Model Context Protocol over stdio (
@modelcontextprotocol/sdk/server/stdio) - Bundled tools:
docbuilder_statusβ summarises config + directories + authdocbuilder_buildβ runs doc-builder build with optional cleandocbuilder_deployβ toggles auth, runs build (unless skipped), deploys to Verceldocbuilder_set_authβ flips Supabase/public mode without a build
2. Config Loading Strategy
- The server always resolves the project root from
DOCBUILDER_PROJECT_ROOT(default/appinside Docker) and then points todoc-builder.config.js. loadMergedConfig()delegates to@knowcode/doc-builder.loadConfigwith acommandhint (status,build, ordeploy).- After load,
applyVercelEnvFromConfig()copiesdeployment.vercel.*into env vars if theyβre not set, so downstream CLI calls inherit known project IDs without interactive prompts. - All writes go through
writeRawConfig(), emitting canonical JSON intodoc-builder.config.js; we avoid mutating the merged config object directly to keep CLI + MCP behaviour consistent. - Secrets (Vercel token, smoke-test metadata) live in
config/mcp/docbuilder.jsonand are encrypted via the sharedencrypt/decrypthelpers. The Settings UI only writes the token whenvercelTokenDirtyis true, which keeps inadvertent blanks from wiping the stored secret.
3. Authentication Toggle
setAuthenticationMode(mode)clones the raw config, updatesfeatures.authentication+features.privateDirectoryAuth, and guards Supabase mode by checkingauth.supabaseUrlandauth.supabaseAnonKey.- When the MCP tool flips the mode it persists the updated config to disk, so subsequent CLI/manual invocations see the same state.
- The doc-builder build step will generate
js/auth.js,login.html,logout.htmlautomatically when Supabase auth is enabled; the MCP server doesnβt touch those assets directly.
4. Vercel Project Handling
deployment.vercelindoc-builder.config.jsstoresprojectName,projectId,orgId,teamSlug.productionUrlcaptures the canonical live URL (shown in status responses and tool output).- The MCP server snapshots
html/.vercel/project.jsonbefore destructive operations (clean=truebuilds) and restores it afterwards. That file contains the Vercel IDs the CLI uses when deploying. - Environment requirements at runtime:
VERCEL_TOKENβ always required- Optional overrides:
VERCEL_PROJECT_ID,VERCEL_ORG_ID,VERCEL_TEAM_SLUG,VERCEL_PROJECT_NAME(automatically set from config if unset) DOCBUILDER_PRODUCTION_URLgets set from config to keep the deploy response consistent.
5. Docker Integration
Dockerfile.sliplanecopies the integration folder into the build stage, runsnpm ci && npm prune --omit=dev, then copies the runtime directory alongside the executable wrapper. The container setsDOCBUILDER_CONFIG_PATH=doc-builder.config.cjsso Node treats the published configuration as CommonJS even though the app default is ESM.- Runtime container exports:
DOCBUILDER_PROJECT_ROOT=/appDOCBUILDER_CONFIG_PATH=doc-builder.config.js- The
docs/,html/, anddoc-builder.config.jstrees so builds/deploys run against the same content as the local repo.
- Claude CLI is pre-installed globally within the image, so registering the MCP server inside the container just needs the standard
claude mcp addcommand with--env VERCEL_TOKEN=β¦.
6. Command Flow (Happy Path)
- Host issues JSON-RPC request (e.g.,
docbuilder_deploy). - Server optionally updates config (
docbuilder_set_auth,docbuilder_deploywith password mode). - If a build is required:
- Output directory cleaned (on
clean=true) - Build executed via
docBuilder.buildDocs .vercel/project.jsonrestored if clean removed it
- Output directory cleaned (on
- Deploy validated (
assertVercelToken), thendocBuilder.deployruns (respectingprodflag). - Response includes text summary for UI + structured payload (deploy URLs, auth status, file counts, timestamps).
7. Error Handling Notes
- Missing Supabase credentials throws before touching the config, so we donβt end up in a half-enabled state.
- If
VERCEL_TOKENis absent we fail fast with a targeted error message. - Underlying doc-builder exceptions bubble up (e.g., Vercel misconfiguration); the MCP server surfaces them verbatim so the UI can present actionable guidance.
- Build/deploy commands run in the project root; any non-fatal stderr logging should go to stderr (stdout corruption would break MCP messaging).
8. Extensibility Hooks
- Add new tools by calling
mcpServer.registerToolinserver.js; ensure input schemas usezodfor validation and respond with{ content, structuredContent }. - For richer logging/telemetry, wrap the doc-builder calls with additional instrumentation before returning.
- If we introduce additional per-env configs, extend
applyVercelEnvFromConfig()(or create similar helper) so the MCP runtime mirrors CLI expectations. - Keep Docker build parity (install/build/prune) any time dependencies change; otherwise the runtime image will lack required modules.
9. Related References
- Operator playbook:
docs/technical/docbuilder-mcp-vercel-playbook.md - MCP onboarding runbook:
docs-developer/tech/add-new-mcp-server.md - Original doc-builder package docs:
node_modules/@knowcode/doc-builder/README.md
This document lives alongside the playbook so engineers can understand the plumbing before making protocol or deployment changes. Update both whenever the tool surface area or config contract changes.