Skip to content

Bundle the docs into the app image with a build manifest so the MCP docs tools always match the shipped version #2602

Closed

Description

@propr-dev

Context

The docs tools from the previous issue read Markdown from disk. In a source checkout docs/ is present; in production the API runs from the propr/app image built by docker/app/Dockerfile (via scripts/build-images.sh), which does not copy docs/. Without this issue the tools answer DOCS_UNAVAILABLE on real installs.

The request also asks: "Consider how the docs are kept current with the shipped version." The answer should be structural: the docs served by an instance must come from the same commit as the code it runs, and the tools must say which version that is.

Requirements

  1. New script scripts/build-docs-manifest.mjs that reads docs/sidebars.ts ordering (without executing TypeScript: parse the doc ids with a conservative regex over string literals, falling back to alphabetical), and writes docs/docs-manifest.json:
    { "schemaVersion": 1, "version": "<root package.json version>", "sourceRevision": "<GIT_SHA env or git rev-parse HEAD or null>",
      "generatedAt": "<ISO>", "order": ["tutorials/setup", "features/overview", ...], "pageCount": 87 }
    docs-manifest.json is git-ignored (generated).
  2. docker/app/Dockerfile: in the final stage, run the manifest script in the build stage and COPY only docs/docs/, docs/mcp.md, docs/mcp-coverage.md, docs/mcp-operator-surface.md and docs/docs-manifest.json into /app/docs/ (no node_modules, no build output, no images — keeps the image small). Pass GIT_SHA as a build arg (already provided by scripts/build-images.sh).
  3. docsIndex.ts already prefers the manifest when present (version, sourceRevision, order). Additionally, if the manifest version differs from the running @propr/api package version, list_docs returns versionMismatch: { docs, api } and a warning so an operator mounting stale docs through PROPR_DOCS_DIR sees it.
  4. get_connection output gains docs: { available: boolean, version, sourceRevision, pages } so an agent can check docs availability in its first call.
  5. scripts/smoke-test-images.sh gains an assertion that /app/docs/docs-manifest.json exists in the app image and its version equals the image's package version.
  6. .dockerignore at repo root (if it excludes docs/) must allow the copied paths.
  7. docs/README.md documents that docs are shipped inside the app image and exposed to MCP clients, and that editing docs in a PR is enough to update what agents see after the next release.

Implementation Specification

  • New scripts/build-docs-manifest.mjs + test/buildDocsManifest.test.mjs (root test dir, node:test).
  • Edit docker/app/Dockerfile, scripts/smoke-test-images.sh, .dockerignore, .gitignore (add docs/docs-manifest.json).
  • Edit packages/api/mcp/toolsDocs.ts (versionMismatch) and packages/api/mcp/tools.ts (get_connection.docs).
  • Edit docs/README.md.

Acceptance Criteria

  • node scripts/build-docs-manifest.mjs produces a manifest whose order starts with the first ids in docs/sidebars.ts and whose pageCount equals the number of .md/.mdx files under docs/docs.
  • A built propr/app image contains /app/docs/docs/features/pr-commands.md and the manifest; list_docs inside the container returns pages with docsVersion equal to the release version and sourceRevision equal to the image's git SHA.
  • get_connection reports docs.available: true in the image and false when no docs root exists.
  • Image size increase is under 3 MB (docs are Markdown only).
  • Smoke test fails if the manifest is missing.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Sep 28, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    We ship the Markdown inside the app image built from the same commit. Alternatives considered: fetching docs from the public docs site at runtime (rejected: network dependency, and the public site tracks main, not the operator's installed version) and reading the optional propr/docs container (rejected: it is optional and serves rendered HTML). Baking in a small manifest with version and sourceRevision makes "which docs am I reading?" answerable and lets us detect a mismatched PROPR_DOCS_DIR override.

    File: scripts/build-docs-manifest.mjs (new file)

    Why this file: Produces the version/ordering metadata at build time, so the runtime never has to execute sidebars.ts.

    #!/usr/bin/env node
    // Generates docs/docs-manifest.json: version, source revision and sidebar order
    // for the MCP docs tools. Pure Node, no TypeScript execution.
    import { execFileSync } from 'node:child_process';
    import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
    import path from 'node:path';
    import { fileURLToPath } from 'node:url';
    
    const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
    const docsDir = path.join(root, 'docs', 'docs');
    
    function listPages(directory, prefix = '') {
      return readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
        if (entry.isSymbolicLink()) return [];
        if (entry.isDirectory()) return listPages(path.join(directory, entry.name), `${prefix}${entry.name}/`);
        return /\.mdx?$/.test(entry.name) ? [`${prefix}${entry.name.replace(/\.mdx?$/, '')}`] : [];
      });
    }
    
    export function sidebarOrder(sidebarsSource, pages) {
      // Doc ids appear as string literals ('features/pr-commands') or as `id: '...'`.
      // Only literals that name an existing page are kept, in first-seen order.
      const known = new Set(pages);
      const order = [];
      for (const match of sidebarsSource.matchAll(/['"`]([a-z0-9][a-z0-9/_-]*)['"`]/gi)) {
        if (known.has(match[1]) && !order.includes(match[1])) order.push(match[1]);
      }
      // Pages the sidebar does not list keep a stable alphabetical tail.
      return [...order, ...pages.filter(page => !order.includes(page)).sort()];
    }
    
    function sourceRevision() {
      if (process.env.GIT_SHA && /^[0-9a-f]{7,40}$/.test(process.env.GIT_SHA)) return process.env.GIT_SHA;
      try { return execFileSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8' }).trim(); } catch { return null; }
    }
    
    export function buildManifest() {
      const pages = listPages(docsDir);
      const version = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')).version;
      const order = sidebarOrder(readFileSync(path.join(root, 'docs', 'sidebars.ts'), 'utf8'), pages);
      return { schemaVersion: 1, version, sourceRevision: sourceRevision(), generatedAt: new Date().toISOString(), order, pageCount: pages.length };
    }
    
    if (import.meta.url === `file://${process.argv[1]}`) {
      const manifest = buildManifest();
      writeFileSync(path.join(root, 'docs', 'docs-manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`);
      console.log(`docs-manifest.json: ${manifest.pageCount} pages, version ${manifest.version}`);
    }

    If the root package.json version is not the release version, read packages/api/package.json instead — use whichever get_connection.version already reports, so both agree.

    File: docker/app/Dockerfile

    Why this file: Only the app image serves the API; docs must be copied into it from the same build context and commit.

    --- a/docker/app/Dockerfile
    +++ b/docker/app/Dockerfile
    @@ (build stage, after sources are copied)
    +ARG GIT_SHA
    +# Docs manifest pins the served docs to this exact build (version + commit).
    +RUN GIT_SHA="$GIT_SHA" node scripts/build-docs-manifest.mjs
    @@ (final/runtime stage)
    +# Markdown only: the MCP docs tools read these. No node_modules or site build.
    +COPY --from=build /app/docs/docs /app/docs/docs
    +COPY --from=build /app/docs/mcp.md /app/docs/mcp-coverage.md /app/docs/mcp-operator-surface.md /app/docs/docs-manifest.json /app/docs/
    +ENV PROPR_DOCS_DIR=/app/docs

    Adjust the stage name (build) and source path (/app) to the names used in the existing Dockerfile.

    File: scripts/smoke-test-images.sh

    Why this file: Release gate: an image without docs would silently make the MCP docs tools unavailable.

    # Docs are shipped for the MCP docs tools and must match the image version.
    docs_version="$(docker run --rm --entrypoint node "$APP_IMAGE" -e 'console.log(require("/app/docs/docs-manifest.json").version)')"
    if [ -z "$docs_version" ]; then
      echo "App image is missing /app/docs/docs-manifest.json" >&2
      exit 1
    fi
    echo "Docs manifest version: $docs_version"

    File: packages/api/mcp/toolsDocs.ts

    Why this file: Surfaces a version mismatch when an operator overrides PROPR_DOCS_DIR with docs from another release.

    +import packageInfo from '../package.json' with { type: 'json' };
    @@ list_docs run
    -      return ok({ docsVersion: index.version, ...
    +      // Docs from a different release can describe tools this instance lacks.
    +      const versionMismatch = index.version !== packageInfo.version ? { docs: index.version, api: packageInfo.version } : undefined;
    +      return ok({ docsVersion: index.version, ...(versionMismatch ? { versionMismatch,
    +        warning: 'These docs were built for a different ProPR version than this instance; some details may not apply.' } : {}), ...

    File: packages/api/mcp/tools.ts

    Why this file: get_connection is the first call agents make; advertising docs availability there saves a failing round trip.

    +import { loadDocsIndex } from './docsIndex.js';
    @@ tools.push({ name: 'get_connection', ... run: async ({ principal }) => ok({
         version: packageInfo.version, connectContractVersion: 'propr-connect-mcp/1', ...
    +    docs: (() => { const index = loadDocsIndex(); return index
    +      ? { available: true, version: index.version, sourceRevision: index.sourceRevision, pages: index.pages.length, tools: ['list_docs', 'search_docs', 'get_doc'] }
    +      : { available: false }; })(),

    File: test/buildDocsManifest.test.mjs (new file)

    Why this file: Guards the sidebar parsing so a sidebar refactor cannot silently scramble page order.

    import assert from 'node:assert/strict';
    import { test } from 'node:test';
    import { sidebarOrder } from '../scripts/build-docs-manifest.mjs';
    
    test('sidebar order keeps listed pages first and appends unlisted pages', () => {
      const source = `const s = { docs: ['tutorials/setup', { type: 'category', items: ['features/overview', 'missing/page'] }] };`;
      assert.deepEqual(sidebarOrder(source, ['features/overview', 'tutorials/setup', 'operations/zeta', 'operations/alpha']),
        ['tutorials/setup', 'features/overview', 'operations/alpha', 'operations/zeta']);
    });

    File: .gitignore and docs/README.md

    --- a/.gitignore
    +++ b/.gitignore
    +# Generated at image build for the MCP docs tools
    +docs/docs-manifest.json
    ## Docs inside ProPR
    
    The `propr/app` image ships this Markdown (not the rendered site) at `/app/docs`
    together with `docs-manifest.json` (version + commit). MCP clients read it with
    `list_docs`, `search_docs` and `get_doc`, so documentation merged in a PR reaches
    agents with the next release of the app image. Set `PROPR_DOCS_DIR` only for
    development; a mismatched version is reported by `list_docs`.
  2. propr-dev commented on Sep 29, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: codex
    • Model: gpt-5.6-sol
    • Branch: 2602/gpt-5.6-sol-bundle-the-docs-into-the--20260929-2059-nsm
    • Base Branch: 2593-epic-mcp-observability-cf6
    • Worktree: issue-2602-20260929-2059-gpt-5.6-sol-nsm

    🔍 Track Task Execution

  3. added a commit that references this issue on Sep 29, 2026
  4. added a commit that references this issue on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions