Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Docs Host Visibility
Status: draft Author: Aashu (via ship-it, autonomous mode) Date: 2026-09-02
Reading of the request
What: make every host shown in the docs site either correct for the reader's
instance, or visibly marked as unknown — never a confident wrong hostname.
Why: the docs hardcode https://rest.carbon.ms; that is wrong for
self-hosted customers and for non-default regions, and a reader has no signal
that it is wrong. Where: the docs/ Next app (display + config) and
apps/erp (the handoff that tells docs which instance the reader came from).
Who: two populations — signed-in Carbon users arriving from the ERP's
avatar menu (host is knowable), and search-engine/direct visitors (host is
genuinely unknown, and is the common case).
TLDR
The docs API/MCP reference presents https://rest.carbon.ms as fact in every
endpoint URL, code sample and MCP snippet. That host is correct only for the
default Carbon Cloud deployment. This spec adds (1) an explicit ERP → docs host
handoff via a ?host= query param sourced from CARBON_API_URL, (2) ingestion
of that param into the existing ApiConfigProvider, and (3) a genuine third
config state — host unknown — which renders the origin portion of every URL
as a clickable <your-host> placeholder that opens the existing Configurator,
while leaving paths accurate. Unknown becomes the new default for unconfigured
visitors, replacing today's silent rest.carbon.ms assumption.
Problem Statement
docs/scripts/generate-api-docs.mjs:19 bakes const BASE = "https://rest.carbon.ms"
into every generated sample at build time. At render, applyBase/applyConfig
(docs/components/api/config-context.tsx) string-replace that literal with the
reader's configured base. The substitution machinery works — the defect is the
default:
DEFAULT_API_BASE = "https://rest.carbon.ms"is used as the initial value, so an unconfigured reader sees a fully-formed, authoritative-looking URL that is wrong for their instance. Concretely, a self-hosted reader is told tocurl 'https://rest.carbon.ms/item?limit=1'— a host they cannot reach.isDefaultconflates "the reader deliberately chose Carbon Cloud" with "the reader has never touched the configurator". Those are different facts and only the first justifies displayingrest.carbon.ms.- A reader arriving from their own ERP instance gets no benefit from the fact that the ERP already knows the correct host.
Self-hosted deployments have arbitrary domains — sst.config.ts shows
URL_ERP/DOMAIN fully overridable, with no rest.* naming convention to rely
on — so the host cannot be guessed from anything the docs site knows on its own.
Proposed Solution
Three parts, in dependency order.
Part 1 — ERP → docs host handoff
The ERP already knows its REST origin: CARBON_API_URL (packages/env/src/index.ts:155),
which falls back to SUPABASE_URL — Carbon's REST API is PostgREST served by
Supabase, which is why samples are PostgREST-shaped (/item?select=*&limit=10).
It is already client-safe: it is in getBrowserEnv() (packages/env/src/index.ts:524)
and already flows into apps/erp/app/root.tsx's env payload (root.tsx:84,115).
path.to.apiDocs and path.to.mcpDocs (apps/erp/app/utils/path.ts:320,1383)
become functions taking an optional host and appending ?host=<encoded>.
AvatarMenu.tsx:122 reads CARBON_API_URL from root loader data via the
existing useRouteData idiom and passes it.
Deliberately not referrer-based: the link carries rel="noreferrer", and
even without it strict-origin-when-cross-origin sends only the bare ERP
origin, which does not identify the REST host on a self-hosted deployment where
the two are unrelated domains.
Part 2 — docs ingests the param
A client-side effect in ApiConfigProvider reads ?host= on mount, validates
it with the same rules as the configurator's parseBaseUrl (extracted to a
shared module so validation cannot drift), and adopts it.
Precedence: an explicit saved choice wins over the param. Order:
localStorage (reader set it themselves) → ?host= param → unknown. Rationale:
the param is a hint from a referrer, while localStorage is a decision by the
reader; silently overwriting the latter would make the configurator feel
broken for someone who deliberately set a different instance.
A param host is display-only (revised during review). It is NOT persisted and
never carries the reader's stored API key. Persisting it would let one crafted
link permanently redirect a reader's samples, and pasting their key into samples
aimed at a link-supplied host would hand that link the credential. The dialog is
what turns a host into the reader's own choice. Credentials are additionally
withheld from any cleartext http: host except loopback, since a key in a
copy-pasted http:// sample is a key on the wire.
Two origins, not one. ERP_URL and CARBON_API_URL are configured
independently upstream and need not share a domain, so the ERP sends both
(?host= and ?app=). The rest. → app. rewrite survives only as a fallback
for a host the reader typed themselves.
Part 3 — the unknown-host state (the core)
base becomes string | null, where null means "host unknown". This is a
third state distinct from Cloud and self-hosted:
| State | base |
Displayed origin |
|---|---|---|
| Unknown (new default) | null |
<your-host> placeholder, clickable |
| Carbon Cloud | https://rest.carbon.ms |
real host |
| Self-hosted / regional | reader's URL | real host |
Rendering rules:
- Paths stay real in every state — only the origin is replaced. A reader can always learn the correct route shape even before configuring.
- Rendered UI (
BaseUrlchip,CodePanelheader, inlineMcpEndpoint):<your-host>renders as a distinct clickable control that opens the Configurator, styled with existinged-*tokens. - Code samples: the placeholder appears as literal
<your-host>text — copy-paste-obvious as a placeholder, matching how<api-key>already reads. It is intentionally not clickable inside shiki HTML: injecting interactive markup intodangerouslySetInnerHTMLblocks would mean parsing highlighted HTML, which is fragile. The panel header and the sidebar trigger both offer the clickable path, so the affordance is never more than one glance away. - Escaping:
applyConfigsubstitutes<your-host>through the same encoding-proof path as<api-key>— shiki encodes</>variously (<,<,<), so all three forms are covered, and any substituted value is HTML-escaped before injection.
The configurator gains a third mode card ("Not sure yet" / unknown) so the state is reachable and reversible, and its trigger shows the placeholder rather than a hostname when unknown.
Design Decisions
| Decision | Choice | Rationale |
|---|---|---|
| Host source in ERP | CARBON_API_URL (falls back to SUPABASE_URL) |
Already the REST origin and already client-safe in getBrowserEnv(); no new env var, works for self-hosted |
| Handoff mechanism | Explicit ?host= query param |
Referrer is stripped by rel="noreferrer" and only ever carries the ERP origin, which ≠ REST host when self-hosted |
| Unknown representation | base: string | null |
Makes the third state unrepresentable-as-Cloud; forces every consumer to handle it at the type level |
| Precedence | localStorage > ?host= > unknown |
Reader's own decision outranks a referrer hint |
| Placeholder token | <your-host> |
Mirrors the existing <api-key> convention readers already understand |
| Clickable in code samples | No — rendered UI only | Avoids parsing/injecting into shiki HTML; affordance still present in header + sidebar |
| Default for new visitors | Unknown | The honest state; showing rest.carbon.ms to a self-hosted reader is the bug being fixed |
| Docs i18n | Plain English strings | The docs app has zero Lingui usage in its own components (the SWC plugin exists only for @carbon/glossary); matching local idiom |
| ERP i18n | Lingui Trans/useLingui |
Existing idiom in AvatarMenu.tsx:26 |
| Static generation | Preserved | Host applied client-side only; generateStaticParams prerendering untouched |
Data Model Changes
N/A — no database involvement. Client-side state only (React context +
localStorage key carbon-api-base, which already exists).
API / Service Changes
No server APIs change. Two surface changes:
path.to.apiDocs/path.to.mcpDocs: string →(host?: string) => string. Internal toapps/erp; both call sites are updated. Query param is additive and safe when signed out or absent.docsuseApiConfig()context:base: string→base: string | null, plusisUnknown. Internal to the docs app; all consumers updated in this change.
UI Changes
docs/components/api/config-context.tsx— nullable base, param ingestion, precedence,<your-host>substitution inapplyBase/applyConfig.docs/components/api/configurator.tsx— third mode card; trigger reflects unknown;parseBaseUrlextracted for reuse.docs/components/api/base-url.tsx,code-panel.tsx,config-inline.tsx— render the placeholder control when unknown.- New: a small
HostPlaceholderclient component (the clickable<your-host>), and a shared way to open the Configurator from anywhere in the tree (dialog open state lifted into the config context). apps/erp/app/components/AvatarMenu.tsx— pass the host on the API docs link.docs/app/mcp/page.tsx:25—ENDPOINTconstant is currently a hardcodedhttps://app.carbon.ms/api/mcpbaked into code samples; routed through the same substitution so it respects the configured/unknown host.
Acceptance Criteria
- A visitor loading
/api-reference/items/partwith emptylocalStorageand no query param sees<your-host>/partin the Base chip and<your-host>in the cURL sample — notrest.carbon.ms. - Clicking the
<your-host>chip on that page opens the API configuration dialog. - Entering
https://api.acme-mfg.comand saving makes every endpoint URL, code sample, MCP endpoint and Settings link on the page readapi.acme-mfg.com; reloading the page preserves it. - Choosing "Carbon Cloud" in the dialog shows
rest.carbon.mseverywhere — the Cloud state still works and is now an explicit choice. - Loading
/api-reference?host=https%3A%2F%2Fapi.acme-mfg.comwith emptylocalStorageadopts that host with no dialog interaction. - With
localStoragealready set tohttps://api.foo.com, loading?host=https://api.bar.comkeepsapi.foo.com(explicit choice wins). - An invalid
?host=value (e.g.?host=javascript:alert(1)or?host=notaurl) is rejected and the page falls back to unknown rather than rendering it. - Clicking "API Documentation" in the ERP avatar menu opens the docs with the
deployment's
CARBON_API_URLas?host=, and the docs immediately show that host. - Copying a code sample in the unknown state yields text containing the literal
<your-host>, with no HTML entities (<) leaking into the clipboard. pnpm exec turbo run typecheck --filter=docs --filter=@carbon/erpandpnpm run lintpass.
Non-Goals
- Auto-detecting the host from the
Refererheader (rejected above). - Changing the build-time generator's
BASEliteral or the generated JSON shape. - Persisting host config server-side or per-account — it stays per-browser.
- Rewriting hardcoded
docs.carbon.mslinks inpackages/onboardingorpackages/react/src/LabelWithHelp.tsx— those point at the docs site, not a customer API host, and are correct as-is. - Touching the
.mdxprose indocs/content/**that mentionsapp.carbon.msin a self-hosting/architecture context, where the literal is accurate.
Open Questions
All resolved before writing (autonomous mode).
- Should the host come from the referrer or an explicit param? — Autonomous:
explicit
?host=param. Referrer is unusable here:rel="noreferrer"is on the link and the default referrer policy sends only the origin, which is not the REST host for self-hosted. (Rung 2: codebase evidence.) - Which ERP value is the REST origin? — Autonomous:
CARBON_API_URL, fallbackSUPABASE_URL; already client-safe and already in the root loader. Alternatives (VERCEL_URL, derivingrest.from the ERP origin) are wrong — the former is the ERP's own URL, the latter assumes a naming convention thatsst.config.tsshows does not hold. (Rung 2.) - What wins when both a saved choice and a param exist? — Autonomous: localStorage. A reader's explicit decision should not be silently overwritten by a referrer hint. (Rung 5: product judgement.)
- How is unknown represented in the type? — Autonomous:
base: string | nullover a parallel boolean, so consumers cannot forget the state. (Rung 5.) - Should
<your-host>be clickable inside code samples? — Autonomous: no. Options were: parse shiki HTML and inject a button (fragile, defeats the build-time highlight), render samples from tokens client-side (large rewrite), or keep samples literal and put the affordance in the panel header/sidebar (chosen — smallest change that still leaves the control one glance away). (Rung 5, YAGNI.) - Does new docs copy need Lingui? — Autonomous: no. Zero docs components
use Lingui; the SWC plugin exists only so
@carbon/glossary's macros compile. ERP-side copy does use Lingui. Matching local idiom in each app. (Rung 2.) - Does this break static generation? — Autonomous: no. Host resolution is
client-side;
generateStaticParamsand the prerendered HTML are untouched. (Rung 2.) - What about the hardcoded MCP
ENDPOINTinapp/mcp/page.tsx:25? — Autonomous: route it through the same substitution. Discovered while writing; leaving it hardcoded would make the MCP page contradict the API pages. (Rung 1: the user's stated intent covers MCP routes explicitly.)
Autonomous Decisions
Eight decisions were made without the user. High-stakes first:
Public-ish contract change —
path.to.apiDocs/mcpDocschange from string constants to functions. Confined toapps/erp; both call sites updated. Worth a reviewer's glance sincepath.tois a widely-used object.Context type change —
basebecomes nullable across the docs app, which touches every consumer ofuseApiConfig. Deliberate: it makes the unknown state impossible to ignore.Default behaviour change — unconfigured visitors now see
<your-host>instead ofrest.carbon.ms. This is the point of the feature, but it does change what every anonymous docs reader sees today.Scope narrowing —
<your-host>is not clickable inside code samples (rationale above). This is the one place the implementation is less than the literal request, which asked for it to be clickable; the affordance is preserved in the panel header and sidebar instead.Wider blast radius than requested (in ERP) —
path.to.apiDocsturned out to have seven call sites, not the one named in the request. Rather than make it a function and edit all seven, the host is appended once insidepath.tsviawithDocsHost(). Consequence: the API-docs links in the Help menu, the API Keys table and the Webhooks table now also carry the host. That is more than the literal request (which named only the avatar menu), and it is the reasonAvatarMenu.tsxneeded no edit at all.
Lower-stakes: host source (CARBON_API_URL), precedence rule, no-Lingui in docs,
including the MCP ENDPOINT constant in scope.
Changelog
- 2026-09-02 — Initial spec, written in ship-it autonomous mode. All eight open questions resolved without user input; see Autonomous Decisions.
- 2026-09-02 — During execution, decision 9 added:
apiDocs/mcpDocsstay strings and gain the host insidepath.ts(withDocsHost), instead of becoming host-taking functions. Driven by the seven-call-site discovery and byCARBON_API_URLalready being available onwindow.envvia@carbon/auth.