Introduction
Body.
+diff --git a/.dockerignore b/.dockerignore
index 8890e0e..fc77a55 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,5 +1,6 @@
-# The Docker image only needs nginx.conf, nginx.headers.conf and the prebuilt
-# dist/ (see Dockerfile).
+# The Docker image only needs nginx.conf, the two nginx.*headers.conf files and
+# the prebuilt dist/ (see Dockerfile). mcp-server/Dockerfile has its own
+# Dockerfile.dockerignore.
# Keep the build context small and avoid leaking source/secrets into the image.
node_modules
.git
@@ -26,6 +27,7 @@ vite.config.js
tsconfig.json
package-lock.json
apps.json
+mcp-server
# The page manifest is build metadata for the MCP indexer, not site content:
# keep it out of the nginx web root. mcp-server/Dockerfile.dockerignore lets it in.
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index ea8c1dd..a774e49 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,5 +1,5 @@
-# Dependabot keeps npm dependencies, pinned GitHub Actions and the Docker base
-# image up to date.
+# Dependabot keeps npm and uv dependencies, pinned GitHub Actions and the Docker
+# base images up to date.
# Action updates land as SHA bumps with the human-readable tag in a comment.
version: 2
updates:
@@ -39,6 +39,18 @@ updates:
actions-dependencies:
update-types: [minor, patch]
+ # The MCP server's own lockfile (mcp-server/uv.lock). The SDK is pinned
+ # exactly, so an SDK bump is a PR of its own and runs the protocol tests.
+ - package-ecosystem: uv
+ directory: /mcp-server
+ schedule:
+ interval: weekly
+ open-pull-requests-limit: 5
+ groups:
+ mcp-server-dependencies:
+ update-types: [minor, patch]
+ exclude-patterns: [mcp]
+
- package-ecosystem: github-actions
directory: /
schedule:
@@ -56,3 +68,10 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 5
+
+ # mcp-server/Dockerfile pins python and uv by tag and digest.
+ - package-ecosystem: docker
+ directory: /mcp-server
+ schedule:
+ interval: weekly
+ open-pull-requests-limit: 5
diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml
index 885a2e6..3534b1d 100644
--- a/.github/workflows/build-image.yml
+++ b/.github/workflows/build-image.yml
@@ -10,6 +10,7 @@
# with:
# registry: apps.json # in the CALLING repo
# image-name: ghcr.io/org/knowledge-base
+# mcp-image-name: ghcr.io/org/knowledge-base-mcp # optional: the MCP server
# secrets:
# docs-token: ${{ steps.app-token.outputs.token }}
#
@@ -53,6 +54,24 @@ on:
type: string
required: false
default: ''
+ mcp-image-name:
+ description: >-
+ MCP server image to build and push from the same dist/ and with the
+ same tags, e.g. ghcr.io/org/knowledge-base-mcp. It runs beside the
+ site image in one task; see contract/DEPLOYMENT.md. Empty builds no
+ MCP image. Ignored without image-name.
+ type: string
+ required: false
+ default: ''
+ python-index:
+ description: >-
+ Python package index for the MCP image's dependencies, for runners
+ that cannot reach pypi.org — an Artifactory PyPI remote, say. Empty
+ means PyPI. The lockfile needs no change: the image installs from
+ hash-pinned requirements exported from it, which name no index.
+ type: string
+ required: false
+ default: ''
image-tags:
description: 'Newline- or comma-separated tags to push. Defaults to the calling run''s SHA.'
type: string
@@ -108,6 +127,14 @@ on:
node-mirror-token:
description: Authorization header value for `node-mirror`.
required: false
+ python-index-username:
+ description: User name for `python-index`, when it needs credentials.
+ required: false
+ python-index-token:
+ description: >-
+ Password or token for `python-index`. Reaches the image build as a
+ BuildKit secret, never as a build argument or a layer.
+ required: false
ca-certificates:
description: >-
Extra CA certificates (PEM) the image build trusts while `apk upgrade`
@@ -118,6 +145,9 @@ on:
image:
description: 'The first pushed image reference, when one was pushed.'
value: ${{ jobs.build.outputs.image }}
+ mcp-image:
+ description: 'The first pushed MCP image reference, when one was pushed.'
+ value: ${{ jobs.build.outputs.mcp-image }}
permissions:
contents: read
@@ -131,6 +161,7 @@ jobs:
runs-on: ${{ (startsWith(inputs.runs-on, '[') || startsWith(inputs.runs-on, '{')) && fromJSON(inputs.runs-on) || inputs.runs-on }}
outputs:
image: ${{ steps.push.outputs.image }}
+ mcp-image: ${{ steps.push.outputs.mcp-image }}
steps:
# The caller's repo holds the registry; this repo holds the build. They are
# checked out side by side, and the build runs from this one.
@@ -249,19 +280,24 @@ jobs:
# Force the plain `docker login` path instead.
ecr: 'false'
- - name: Build and push the image
+ - name: Build and push the images
id: push
if: ${{ inputs.image-name != '' }}
working-directory: knowledge-base
env:
KB_IMAGE: ${{ inputs.image-name }}
+ KB_MCP_IMAGE: ${{ inputs.mcp-image-name }}
KB_TAGS: ${{ inputs.image-tags }}
KB_SHA: ${{ github.sha }}
KB_CA_CERTIFICATES: ${{ secrets.ca-certificates }}
+ KB_PYTHON_INDEX: ${{ inputs.python-index }}
+ KB_PYTHON_INDEX_USERNAME: ${{ secrets.python-index-username }}
+ KB_PYTHON_INDEX_TOKEN: ${{ secrets.python-index-token }}
run: |
set -euo pipefail
- # The Dockerfile trusts every *.pem in trusted_certs/ for its apk step.
+ # Both Dockerfiles trust every *.pem in trusted_certs/ for their
+ # package downloads.
if [ -n "${KB_CA_CERTIFICATES:-}" ]; then
printf '%s\n' "$KB_CA_CERTIFICATES" > trusted_certs/ca-certificates.pem
fi
@@ -269,22 +305,83 @@ jobs:
tags="${KB_TAGS:-$KB_SHA}"
# Accept either separator; normalise to one tag per line.
tags="$(printf '%s' "$tags" | tr ',' '\n' | sed '/^[[:space:]]*$/d')"
+ first_tag="$(head -n 1 <<< "$tags")"
- args=()
- first=''
- while IFS= read -r tag; do
- ref="$KB_IMAGE:$tag"
- args+=(-t "$ref")
- [ -z "$first" ] && first="$ref"
- done <<< "$tags"
+ # The index URL travels as a BuildKit secret: it may carry credentials,
+ # and a build argument would be recorded in the image history. Checked
+ # before anything is built, so a bad input pushes nothing.
+ secret=()
+ if [ -n "${KB_MCP_IMAGE:-}" ] && [ -n "${KB_PYTHON_INDEX:-}" ]; then
+ case "$KB_PYTHON_INDEX" in
+ *[[:space:]]*|*@*)
+ echo "::error::python-index must be a single URL without credentials; pass them as secrets"
+ exit 1 ;;
+ http://*|https://*) ;;
+ *)
+ echo "::error::python-index must be an http(s) URL, got '$KB_PYTHON_INDEX'"
+ exit 1 ;;
+ esac
+ index="$KB_PYTHON_INDEX"
+ if [ -n "${KB_PYTHON_INDEX_TOKEN:-}" ]; then
+ user="$(jq -rn --arg v "${KB_PYTHON_INDEX_USERNAME:-__token__}" '$v|@uri')"
+ token="$(jq -rn --arg v "$KB_PYTHON_INDEX_TOKEN" '$v|@uri')"
+ # GitHub masks the raw secret; the percent-encoded form is not guaranteed to match.
+ echo "::add-mask::${token}"
+ index="${index%%://*}://${user}:${token}@${index#*://}"
+ echo "::add-mask::${index}"
+ fi
+ export KB_PYTHON_INDEX_URL="$index"
+ secret=(--secret id=python-index,env=KB_PYTHON_INDEX_URL)
+ echo "The MCP image installs from ${KB_PYTHON_INDEX}${KB_PYTHON_INDEX_TOKEN:+ (authenticated)}"
+ fi
- docker build "${args[@]}" .
- while IFS= read -r tag; do
- docker push "$KB_IMAGE:$tag"
- done <<< "$tags"
+ # Never call these inside $(...): errexit is off in a command
+ # substitution, and a failed build would no longer fail the step.
+ build() {
+ local image="$1" dockerfile="$2" tag args=()
+ shift 2
+ while IFS= read -r tag; do
+ args+=(-t "$image:$tag")
+ done <<< "$tags"
+ docker build -f "$dockerfile" "${args[@]}" "$@" .
+ }
+ # Only the first tag goes out before both images are in place; it is
+ # the one reported as an output, so a consumer never sees a pair in
+ # which one image is missing. The other tags (aliases such as
+ # `latest`) are promoted afterwards: if that fails the pair is
+ # published and the aliases can be re-run on their own.
+ publish() {
+ local images=() outputs=() tag i
+ if [ -n "${KB_MCP_IMAGE:-}" ]; then
+ images+=("$KB_MCP_IMAGE")
+ outputs+=(mcp-image)
+ fi
+ images+=("$KB_IMAGE")
+ outputs+=(image)
+ for i in "${!images[@]}"; do
+ docker push "${images[$i]}:$first_tag"
+ done
+ for i in "${!images[@]}"; do
+ echo "${outputs[$i]}=${images[$i]}:$first_tag" >> "$GITHUB_OUTPUT"
+ echo "Pushed \`${images[$i]}:$first_tag\`." >> "$GITHUB_STEP_SUMMARY"
+ done
+ while IFS= read -r tag; do
+ [ "$tag" = "$first_tag" ] && continue
+ for i in "${!images[@]}"; do
+ docker push "${images[$i]}:$tag"
+ done
+ done <<< "$tags"
+ }
- echo "image=$first" >> "$GITHUB_OUTPUT"
- echo "Pushed \`$first\`." >> "$GITHUB_STEP_SUMMARY"
+ # The two images are one version: both are built before either is
+ # pushed, so a failed MCP build leaves both repositories as they were.
+ # The MCP image goes first because its push is the likelier to fail
+ # (a repository nobody created yet).
+ build "$KB_IMAGE" Dockerfile
+ if [ -n "${KB_MCP_IMAGE:-}" ]; then
+ build "$KB_MCP_IMAGE" mcp-server/Dockerfile ${secret[@]+"${secret[@]}"}
+ fi
+ publish
# kb-build.json records which release of which repo produced each app. An
# image is opaque once pushed; this is how "the docs are wrong" becomes an
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0ec7bb0..c384c5e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -8,6 +8,7 @@
# typecheck — astro check (TypeScript / Astro type errors)
# build — headless build from the vendored fixture; uploads dist/
# e2e — Playwright: embedded web-fragment harness + standalone layer
+# mcp — MCP server (mcp-server/, Python): ruff, mypy, import-linter, pytest, and an index of the real build
# image — docker build + container integration tests against real nginx + Trivy scan
# audit — npm dependency vulnerability gate
@@ -208,8 +209,8 @@ jobs:
runs-on: '["ubuntu-latest"]'
# ── 5. Container image ─────────────────────────────────────────────────────
#
- # Builds the runtime image from the dist/ the build job produced, then scans
- # it. `npm audit` below covers JS dependencies only — nothing else in CI looks
+ # Builds both runtime images (the site and the MCP server) from the dist/ the
+ # build job produced, runs them as a deployment's task does, then scans them. `npm audit` below covers JS dependencies only — nothing else in CI looks
# at the nginx base image, which is what the digest pin in the Dockerfile
# exists to control. CRITICAL-only so a routine base-image CVE does not block
# unrelated PRs; the fix is to bump the pinned digest.
@@ -232,6 +233,8 @@ jobs:
# Also proves the Dockerfile's dist/ sanity checks pass on a real build.
- name: Build image
run: docker build -t knowledge-base:ci .
+ - name: Build MCP image
+ run: docker build -f mcp-server/Dockerfile -t knowledge-base-mcp:ci .
# The CSP checks in the container suite need a real browser: a policy that
# blocks something the page needs fails silently, and only a browser
# reports the violation.
@@ -245,6 +248,7 @@ jobs:
run: npm run test:container
env:
KB_IMAGE: knowledge-base:ci
+ KB_MCP_IMAGE: knowledge-base-mcp:ci
KB_SKIP_BUILD: 'true'
- name: Scan image
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
@@ -254,6 +258,14 @@ jobs:
exit-code: '1'
ignore-unfixed: true
severity: CRITICAL
+ - name: Scan MCP image
+ uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
+ with:
+ image-ref: knowledge-base-mcp:ci
+ format: table
+ exit-code: '1'
+ ignore-unfixed: true
+ severity: CRITICAL
- name: Upload Playwright report
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
@@ -262,6 +274,38 @@ jobs:
path: playwright-report/
retention-days: 7
+ # ── 5b. MCP server (Python) ────────────────────────────────────────────────
+ # mcp-server/ is a self-contained uv project. Lint, types, layering and unit
+ # tests need nothing else; the last step indexes the real build from the
+ # `build` job, which is where a page manifest the indexer no longer accepts
+ # would show up.
+ mcp:
+ name: MCP server (Python)
+ runs-on: ubuntu-latest
+ needs: build
+ defaults:
+ run:
+ working-directory: mcp-server
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
+ with:
+ enable-cache: true
+ cache-dependency-glob: mcp-server/uv.lock
+ - run: uv sync --locked --all-extras
+ - run: uv run ruff format --check .
+ - run: uv run ruff check .
+ - run: uv run mypy
+ - run: uv run lint-imports
+ - run: uv run pytest
+ - name: Download dist artifact
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ name: ci-dist
+ path: dist
+ - name: Index the fixture build
+ run: uv run kb-mcp index --dist ../dist --out ../index.sqlite
+
# ── 6. Dependency audit ────────────────────────────────────────────────────
audit:
name: npm audit
diff --git a/.github/workflows/pr-requirements.yml b/.github/workflows/pr-requirements.yml
index b03b66b..10eba64 100644
--- a/.github/workflows/pr-requirements.yml
+++ b/.github/workflows/pr-requirements.yml
@@ -78,4 +78,6 @@ jobs:
# segments in dependabot branches (e.g. dependabot/npm_and_yarn/…).
branch-pattern: "^(feat|feature|fix|bugfix|hotfix|release|support|chore|docs|ci|test|dependabot)/[a-zA-Z0-9._/-]+$"
max-files-changed: "50"
+ # Reported, not enforced: a feature reviewed whole can outgrow it.
+ warn-checks: "pr-size"
allowed-target-branches: ${{ steps.targets.outputs.list }}
diff --git a/AGENTS.md b/AGENTS.md
index 137a43d..51f654c 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -67,7 +67,8 @@ Closes #43
### Size
-**Maximum 50 changed files per PR.** Split larger work.
+**Aim for at most 50 changed files per PR**, and split larger work where practical. The PR
+check reports a bigger PR as a warning; it does not fail it.
## Commits
@@ -92,10 +93,11 @@ that is the bug — fix the change, not the test.
A fourth suite needs Docker and is therefore **not** part of `npm test`:
```bash
-npm run test:container # integration tests against the real nginx image
+npm run test:container # integration tests against the real nginx + MCP images
```
-Run it when touching `nginx.conf`, `nginx.headers.conf` or the `Dockerfile`. It
+Run it when touching `nginx.conf`, `nginx.headers.conf`, `nginx.security-headers.conf`,
+either `Dockerfile` (the site's or `mcp-server/`'s) or the MCP server's HTTP behaviour. It
is the only place the shipped config is executed — the other suites run against
`tests/fragment-server.mjs`, an Express mirror of the nginx rewrites. That mirror
is a second implementation of the same contract and it has drifted twice
@@ -110,6 +112,22 @@ anything there, rebuild, then run it.
`npm audit --omit=dev --audit-level=high` must also stay clean; it gates CI.
+Touching `mcp-server/` (the Python MCP server)? From that directory, all five must
+pass — CI's `mcp` job runs the same:
+
+```bash
+uv run ruff format --check . # format
+uv run ruff check . # lint
+uv run mypy # strict types
+uv run lint-imports # layering contracts in pyproject.toml
+uv run pytest # unit + protocol tests, 90% branch coverage
+```
+
+A change to the page manifest (`scripts/page-manifest.js`) is a change to the
+indexer's input: update `scripts/page-manifest.schema.json`,
+`mcp-server/src/kb_mcp/indexer/manifest.py` and `mcp-server/tests/fixtures/pages.json`
+together.
+
## Repository conventions
### Hermetic by construction
diff --git a/CLAUDE.md b/CLAUDE.md
index cfa98f8..26eae8a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -28,7 +28,7 @@ npm run preview # serve the built dist/ (astro preview, :43
# Test (Playwright E2E — self-contained; auto-starts its own servers)
npm test # embedded web-fragment harness
npx playwright test --config=playwright.config.ci.js # standalone fragment server
-npm run test:container # real nginx image (needs Docker)
+npm run test:container # real nginx + MCP images (needs Docker)
npm run test:ui # Playwright UI
npm run test:headed # visible browser
npm run test:debug # debug mode
@@ -36,6 +36,13 @@ npm run test:debug # debug mode
# Docker
docker build -t knowledge-base .
docker run -p 8080:8080 knowledge-base
+docker build -f mcp-server/Dockerfile -t knowledge-base-mcp . # MCP image, same dist/
+
+# MCP server (Python, mcp-server/; needs uv) — run from mcp-server/
+uv sync --all-extras # runtime + indexer + dev tools
+uv run kb-mcp index --dist ../dist --out index.sqlite # index a build's dist/
+KB_MCP_INDEX=index.sqlite uv run kb-mcp serve # http://127.0.0.1:8081/mcp
+uv run ruff format --check . && uv run ruff check . && uv run mypy && uv run lint-imports && uv run pytest
```
## Build Pipeline
@@ -83,6 +90,7 @@ Orchestrator: `scripts/build-vite.js`. Flags: `--local`, `--headless`.
- `src/utils/registry.js` — Registry validation, manifest reading/validation, expansion map. Shared by the build and by Astro so both resolve the same registry
- `scripts/build-vite.js` — Build orchestrator (4 steps: prepare, hoist, copy assets, astro build)
- `scripts/page-manifest.js` — Build step 3b: writes `dist/_kb/pages.json` (shape: `scripts/page-manifest.schema.json`), the pages Astro published with their app's name, description, tags, kind and source version. It and the HTML under `dist/` are the whole interface for consumers that do not run Node (the MCP indexer); they never read the registry. `.dockerignore` keeps `dist/_kb` out of the nginx image
+- `mcp-server/` — the MCP server: a self-contained Python project (uv, `src/kb_mcp`, pytest) on the official MCP SDK. It shares no code with the site; it reads `dist/_kb/pages.json` and the HTML under `dist/`. `kb-mcp index` builds a SQLite FTS5 index, `kb-mcp serve` serves it over stateless Streamable HTTP. Layering (ports and adapters, the indexer never imported at run time) is enforced by import-linter. Shipped as a second image (`mcp-server/Dockerfile`, build context the repo root, index built in) that runs beside the site image in one task; nginx proxies `/knowledge-base/mcp` to it on `127.0.0.1:8081` (`contract/DEPLOYMENT.md`). See `docs/mcp.md`, `docs/mcp-development.md` and `docs/adr/0001-mcp-server.md`
- `scripts/fetch-apps.js` — GitHub Release artifact downloader. Only *obtains* an artifact; installing it is one shared path in `build-vite.js`
- `scripts/artifacts.js` — Safe tarball extraction + tree copy, shared by both fetch paths. Validates archive members (no traversal, no absolute paths, no symlinks) before anything is written, and replaces the old `cp -r`/`tar` shell-outs so the build runs on Windows
- `scripts/check-artifact.js` — Runs the publish action's contract checker (`actions/lib/check.js`) on every installed artifact, before hoisting; logs findings grouped by rule, and fails a strict build on an error. `check.js` resolves its parsers from `actions/node_modules` or the root; the two may pin different versions, and `tests/artifact-checks.spec.js` runs the checker self-test against whichever the build resolves
@@ -196,19 +204,33 @@ Every embedded test runs twice, as Playwright projects `chromium` (:4201) and
per hop, one `wf-html`, no duplicated stylesheet across a → b → c → a.
- `artifact-checks.spec.js` — the build-side checker: the checker self-test passes with the parsers the build resolves (behaviour, not a version match with `actions/`), findings are grouped by rule, a strict build refuses an error finding.
- `artifact-safety.spec.js` — tarball extraction guards (traversal, absolute paths, symlinks).
-- `nginx-config.spec.js` — static assertions on `nginx.conf`/`nginx.headers.conf`, including
- that the CSP the Express mirror serves is byte-identical to nginx's.
+- `nginx-config.spec.js` — static assertions on `nginx.conf`/`nginx.headers.conf`/
+ `nginx.security-headers.conf`, including that the CSP the Express mirror serves is
+ byte-identical to nginx's, and the MCP location (exact match, loopback upstream with its own
+ Host, security headers without CORS, rate and body limits, its preflight not short-circuited).
+ The site's static locations include `nginx.headers.conf` (CORS + the security file); the MCP
+ location includes only the security file, because the MCP server answers CORS itself.
+- `build-image-workflow.spec.js` — runs `build-image.yml`'s build-and-push script under bash with a
+ stub `docker`: a failed build fails the step, and both images are built before either is pushed,
+ so a failed MCP build or a refused MCP push leaves the site's tags where they were.
- `private-registry.spec.js` — both lockfiles name no registry (no `resolved` URL, an
integrity hash on every package; the committed `.npmrc` sets
`omit-lockfile-registry-resolved`), the `npm-registry`/`npm-token`/`node-mirror` inputs
exist on both actions and `build-image.yml`, and `actions/lib/npm-registry.sh` appends to
- the project `.npmrc` without ever putting the token on disk.
+ the project `.npmrc` without ever putting the token on disk. The MCP image's `python-index`
+ reaches `docker build` as a BuildKit secret and installs hash-pinned requirements.
- `skill.spec.js` — `skills/kb-docs-add/`: frontmatter satisfies the Agent Skills spec
(name ↔ directory, portable fields only), no scripts shipped, every referenced file exists,
`examples/` are byte-identical to the contract's code blocks, and the docs carry the install
command.
- `standalone.spec.js` — the `:3000` fragment server directly (`playwright.config.ci.js`).
-- `container.spec.js` — the real nginx image (`playwright.config.docker.js`, needs Docker).
+- `container.spec.js` — the real images (`playwright.config.docker.js`, needs Docker): the MCP
+ container owns the network namespace and the port, nginx joins it once the MCP container is
+ healthy — a task's shape. MCP through nginx: initialize, search links on the public origin,
+ the browser page, CORS from the server alone, Origin refusal, 413, 429 — and the same calls
+ through the reference web-fragments host (`tests/host/server.mjs` on :8098), which proxies
+ `/knowledge-base/mcp` itself, ahead of the gateway: the gateway's Node middleware cannot forward
+ a request body.
- `support/fragment.js` — shadow-DOM traversal + reframed-body wait/query helpers.
Two build-pipeline pieces support this: `apps.json` entries may carry a `prebuilt` path
@@ -231,6 +253,7 @@ in the committed `apps.json` without breaking CI, which only has this repo.
- `KB_HEADLESS` — `true` produces web-fragment output; **anything else, including unset, means standalone**. `scripts/build-vite.js` always exports an explicit value, so the default only applies when `astro build`/`astro dev` runs directly. Read it through `isHeadlessBuild()`, never inline. A per-app `"headless"` in `apps.json` overrides it in either direction.
- `AWS_REGION`, `ECR_REPOSITORY`, `ECS_CLUSTER`, `ECS_SERVICE` — deployment config
- `KB_EXAMPLE_ARTIFACT` — overrides the packaged artifact `scripts/setup-test-apps.mjs` registers
-- `KB_CONTAINER_PORT`, `KB_SKIP_BUILD` — container-suite harness (`tests/container/serve.mjs`); CI sets `KB_SKIP_BUILD` because its image job already built the image
+- `KB_CONTAINER_PORT`, `KB_SKIP_BUILD`, `KB_IMAGE`, `KB_MCP_IMAGE` — container-suite harness (`tests/container/serve.mjs`); CI sets `KB_SKIP_BUILD` because its image job already built both images
+- `KB_MCP_*` — the MCP server's settings (`mcp-server/src/kb_mcp/config.py`); the deployable ones are listed in `contract/DEPLOYMENT.md`
The URL prefix is **not** an environment variable: it is the `PATH_PREFIX` constant in `src/utils/config.js`. `nginx.conf`, `tests/fragment-server.mjs` and the gateway's route patterns hard-code the same string, so changing it means changing all of them together.
diff --git a/Dockerfile b/Dockerfile
index 36679f7..f1af26d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -40,6 +40,8 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf
# conf.d/ because nginx loads conf.d/*.conf as top-level server configuration
# and this is a fragment, not a server block.
COPY nginx.headers.conf /etc/nginx/kb-headers.conf
+# The security half of that set, which the MCP location includes on its own.
+COPY nginx.security-headers.conf /etc/nginx/kb-security-headers.conf
# `dist/` is built outside the image (npm run build / build:headless) and is not
# reproducible from this Dockerfile alone — see README. Fail loudly here rather
diff --git a/README.md b/README.md
index ec3764e..0780361 100644
--- a/README.md
+++ b/README.md
@@ -468,6 +468,25 @@ docker build -t knowledge-base .
docker run -p 8080:8080 knowledge-base # http://localhost:8080/knowledge-base/
```
+### MCP server for AI agents
+
+Agents can search and read the knowledge base over the Model Context Protocol at
+`/knowledge-base/mcp`. The server is a Python service in [`mcp-server/`](mcp-server),
+shipped as a second image from the same `dist/` and run beside the site image in
+one task; nginx proxies the endpoint to it.
+
+```bash
+docker build -f mcp-server/Dockerfile -t knowledge-base-mcp .
+docker run -d --name kb-mcp -p 8080:8080 knowledge-base-mcp
+docker run --network container:kb-mcp knowledge-base
+claude mcp add --transport http knowledge-base http://localhost:8080/knowledge-base/mcp
+```
+
+Using and operating it: [`docs/mcp.md`](docs/mcp.md). Deploying it:
+[`contract/DEPLOYMENT.md`](contract/DEPLOYMENT.md#the-mcp-server). Developing it:
+[`docs/mcp-development.md`](docs/mcp-development.md). Why it is built this way:
+[`docs/adr/0001-mcp-server.md`](docs/adr/0001-mcp-server.md).
+
### Deploy configuration (example — AWS ECS)
| Variable | Description |
@@ -502,11 +521,13 @@ knowledge-base/
│ ├── config.js ← PATH_PREFIX / BASE_PATH + isHeadlessBuild()
│ ├── registry.js ← registry rules + manifest parsing + expansion
│ └── transform.js ← parse5 URL rewriting + sub-app document splitting
+├── mcp-server/ ← MCP server for AI agents (Python, uv; own Dockerfile)
├── scripts/
│ ├── build-vite.js ← Build orchestrator
│ ├── fetch-apps.js ← GitHub Release download + extract
│ ├── artifacts.js ← Safe tarball extraction + tree copy
│ ├── hoist-inline-scripts.js ← Inline
+
hidden
Visible text.
+ + +Body.
+""" + + assert extract_document(html).text == "Visible text." + + +def test_a_header_inside_the_content_keeps_the_page_heading() -> None: + html = """