@takazudo/zudo-doc 10.0.3 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/asset-index-page/index.js +1 -1
  3. package/dist/asset-page/index.js +1 -1
  4. package/dist/asset-path/index.d.ts +2 -0
  5. package/dist/asset-path/index.js +1 -0
  6. package/dist/catalog.js +1 -1
  7. package/dist/chrome/derive.js +14 -2
  8. package/dist/compiled.css +178 -30
  9. package/dist/config-assertions/index.d.ts +54 -0
  10. package/dist/config-assertions/index.js +205 -0
  11. package/dist/config.d.ts +12 -9
  12. package/dist/config.js +8 -0
  13. package/dist/content/index.d.ts +1 -0
  14. package/dist/content/index.js +2 -0
  15. package/dist/content/wide-section-heading.d.ts +12 -0
  16. package/dist/content/wide-section-heading.js +8 -0
  17. package/dist/doc-body-end-islands/index.d.ts +0 -7
  18. package/dist/doc-body-end-islands/index.js +0 -6
  19. package/dist/doc-card-nav/index.d.ts +78 -0
  20. package/dist/doc-card-nav/index.js +82 -0
  21. package/dist/doc-card-nav/slug.d.ts +6 -0
  22. package/dist/doc-card-nav/slug.js +6 -0
  23. package/dist/doc-page-renderer/index.d.ts +1 -0
  24. package/dist/doc-page-renderer/index.js +2 -0
  25. package/dist/doc-page-shell/index.d.ts +3 -0
  26. package/dist/doc-page-shell/index.js +4 -1
  27. package/dist/docs-schema/index.d.ts +2 -0
  28. package/dist/docs-schema/index.js +9 -0
  29. package/dist/features.css +201 -0
  30. package/dist/frontmatter-preview-defaults/index.js +3 -1
  31. package/dist/head-with-defaults/index.d.ts +11 -0
  32. package/dist/head-with-defaults/index.js +15 -3
  33. package/dist/home-hero/index.d.ts +36 -0
  34. package/dist/home-hero/index.js +128 -0
  35. package/dist/home-page/index.js +149 -58
  36. package/dist/i18n-defaults/index.js +8 -0
  37. package/dist/mcp/constants.d.ts +11 -0
  38. package/dist/mcp/constants.js +20 -0
  39. package/dist/mcp/discovery.d.ts +45 -0
  40. package/dist/mcp/discovery.js +138 -0
  41. package/dist/mcp/handler.js +4 -2
  42. package/dist/mcp/index.d.ts +3 -0
  43. package/dist/mcp/index.js +37 -1
  44. package/dist/nav-indexing/doc-card-grid.d.ts +6 -0
  45. package/dist/nav-indexing/doc-card-grid.js +26 -16
  46. package/dist/plugins/internal/llms-txt/dev-middleware.js +5 -1
  47. package/dist/plugins/internal/llms-txt/emit.js +5 -1
  48. package/dist/plugins/internal/llms-txt/generate.d.ts +2 -0
  49. package/dist/plugins/internal/llms-txt/generate.js +3 -0
  50. package/dist/plugins/routes.js +6 -1
  51. package/dist/preset.d.ts +4 -1
  52. package/dist/preset.js +8 -0
  53. package/dist/robots.d.ts +14 -0
  54. package/dist/robots.js +22 -4
  55. package/dist/routes/404.js +1 -1
  56. package/dist/routes/ai-catalog.d.ts +5 -0
  57. package/dist/routes/ai-catalog.js +28 -0
  58. package/dist/routes/mcp-server-card.d.ts +5 -0
  59. package/dist/routes/mcp-server-card.js +24 -0
  60. package/dist/settings-defaults.js +1 -1
  61. package/dist/settings.d.ts +102 -6
  62. package/dist/sidebar/client-data.d.ts +1 -1
  63. package/dist/sidebar/client-data.js +2 -0
  64. package/dist/sidebar/types.d.ts +4 -0
  65. package/dist/sidebar-tree/build-tree.js +1 -0
  66. package/dist/sidebar-tree/types.d.ts +4 -0
  67. package/dist/site-schema/nav-tree.js +2 -0
  68. package/dist/site-schema/types.d.ts +3 -0
  69. package/dist/site-tree-nav/index.d.ts +18 -0
  70. package/dist/site-tree-nav/index.js +18 -3
  71. package/dist/site-tree-nav/normalize-island-props.d.ts +6 -0
  72. package/dist/site-tree-nav/normalize-island-props.js +15 -0
  73. package/dist/site-tree-nav-island/count.d.ts +3 -0
  74. package/dist/site-tree-nav-island/count.js +11 -0
  75. package/dist/site-tree-nav-island/index.d.ts +22 -2
  76. package/dist/site-tree-nav-island/index.js +272 -221
  77. package/dist/tag-pages/index.d.ts +1 -0
  78. package/dist/tag-pages/index.js +2 -2
  79. package/dist/theme-packs/bauhaus/meta.json +1 -1
  80. package/dist/theme-packs/bauhaus/pack.css +2 -2
  81. package/dist/theme-packs/beacon/meta.json +1 -1
  82. package/dist/theme-packs/beacon/pack.css +0 -15
  83. package/dist/theme-packs/eink/meta.json +1 -1
  84. package/dist/theme-packs/eink/pack.css +1 -14
  85. package/dist/theme.css +0 -16
  86. package/dist/versions-page/index.d.ts +1 -0
  87. package/dist/versions-page/index.js +1 -1
  88. package/dist/wind.json +4 -6
  89. package/eject/sidebar/client-data.ts +3 -1
  90. package/eject/sidebar/types.ts +4 -0
  91. package/eject/site-tree-nav-island/count.ts +11 -0
  92. package/eject/site-tree-nav-island/index.tsx +359 -256
  93. package/package.json +19 -7
  94. package/routes-src/404.tsx +1 -1
  95. package/routes-src/ai-catalog.tsx +26 -0
  96. package/routes-src/mcp-server-card.tsx +21 -0
  97. package/dist/find-in-page/find-bar.d.ts +0 -11
  98. package/dist/find-in-page/find-bar.js +0 -103
  99. package/dist/find-in-page/find-in-page.d.ts +0 -17
  100. package/dist/find-in-page/find-in-page.js +0 -131
  101. package/dist/find-in-page/index.d.ts +0 -5
  102. package/dist/find-in-page/index.js +0 -52
@@ -1,11 +1,19 @@
1
1
  import { Fragment, jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
2
2
  import { Island } from "@takazudo/zfb";
3
- import { AutoLogo } from "../auto-logo/index.js";
3
+ import { HomeHero, homeAssetHref } from "../home-hero/index.js";
4
4
  import { DocLayoutWithDefaults } from "../doclayout/index.js";
5
5
  import { CompactProse, HOME_SECTION_HEADING_CLASS, resolveHomeIntro } from "../home-intro/index.js";
6
6
  import { SiteTreeNav } from "../site-tree-nav-island/index.js";
7
7
  import { TagNav } from "../nav-indexing/tag-nav.js";
8
8
  import { CategoryLinkIcon } from "../tree-nav-shared/index.js";
9
+ import { WideSectionHeading } from "../content/wide-section-heading.js";
10
+ import { DocCardGrid } from "../nav-indexing/doc-card-grid.js";
11
+ import {
12
+ reportDocCardDiagnostics,
13
+ resolveDocCards
14
+ } from "../doc-card-nav/index.js";
15
+ import { resolveSiteTreeNavCountLabels } from "../site-tree-nav/index.js";
16
+ import { getNoteTrayItems } from "../note-tray-model/index.js";
9
17
  import { createHeadWithDefaults } from "../head-with-defaults/index.js";
10
18
  import { resolveThemePackSsrSlug } from "../theme/theme-pack-provider.js";
11
19
  import { deriveComposeMetaTitle, deriveBodyEndIslands, deriveDateFormats } from "../chrome/derive.js";
@@ -48,12 +56,25 @@ function selectSecondaryNodes(tree, secondary, categoryIgnore) {
48
56
  }
49
57
  return moved;
50
58
  }
51
- function cssUrl(url) {
52
- return `url("${url.replace(/[\\"]/g, "\\$&")}")`;
59
+ function sectionText(section, locale, field) {
60
+ for (const value of [section.locales?.[locale]?.[field], section[field]]) {
61
+ if (value?.trim()) return value;
62
+ }
63
+ return void 0;
64
+ }
65
+ function hasCover(nodes) {
66
+ return nodes.some((node) => node.cover !== void 0 || hasCover(node.children));
67
+ }
68
+ function withoutCovers(node) {
69
+ const { cover: _cover, ...rest } = node;
70
+ return { ...rest, children: node.children.map(withoutCovers) };
53
71
  }
54
- function logoMaskStyle(url) {
55
- const mask = `${cssUrl(url)} center/contain no-repeat`;
56
- return { "-webkit-mask": mask, mask };
72
+ function withCoverHrefs(tree, base) {
73
+ if (!hasCover(tree)) return tree;
74
+ return tree.map((node) => {
75
+ const stripped = withoutCovers(node);
76
+ return node.cover === void 0 ? stripped : { ...stripped, coverHref: homeAssetHref(base, node.cover) };
77
+ });
57
78
  }
58
79
  function createHomePageView(ctx) {
59
80
  assertChromeContext(ctx, "createHomePageView");
@@ -87,12 +108,14 @@ function createHomePageView(ctx) {
87
108
  wide
88
109
  }) {
89
110
  const prefix = locale === defaultLocale ? "" : `/${locale}`;
111
+ const homePath = withBase(prefix === "" ? "/" : prefix);
90
112
  const effectiveInitiallyCollapsedCategorySlugs = initiallyCollapsedCategorySlugs ?? settings.siteTreeNavInitiallyCollapsed;
91
113
  const rawDescription = settings.locales[locale]?.description ?? settings.siteDescription;
92
114
  const description = rawDescription?.trim() ? rawDescription : void 0;
93
115
  const ctaNav = settings.headerNav[0] ?? null;
94
116
  const primary = heroLink ? { href: withBase(`${prefix}${heroLink.path}`), label: t(heroLink.labelKey, locale) } : ctaNav ? { href: withBase(`${prefix}${ctaNav.path}`), label: t("nav.overview", locale) } : null;
95
117
  const logoSetting = settings.logo ?? "auto";
118
+ const homeImage = settings.home?.image;
96
119
  const resolvedExtras = extras ?? homeExtras?.({ locale });
97
120
  const intro = homeIntros?.[locale] ?? null;
98
121
  const hasIntro = Boolean(intro?.nodes.length);
@@ -135,17 +158,103 @@ function createHomePageView(ctx) {
135
158
  if (hasExtras) {
136
159
  rowItems.push(resolvedExtras);
137
160
  }
138
- const rowContent = [];
139
- rowItems.forEach((item, index) => {
140
- if (index > 0) rowContent.push(/* @__PURE__ */ jsx("span", { class: "text-muted", children: "/" }));
141
- rowContent.push(item);
142
- });
161
+ const homeSections = settings.home?.sections;
162
+ const ignoredRoots = /* @__PURE__ */ new Set([...categoryIgnore, ...movedNodes.map((n) => n.slug)]);
163
+ const treeRootCount = tree.filter(
164
+ (n) => !ignoredRoots.has(n.slug) && (n.shape !== "note-tray" || getNoteTrayItems(n).length > 0)
165
+ ).length;
166
+ const siteTreeIsland = (variant) => {
167
+ const countLabels = variant === "described" ? resolveSiteTreeNavCountLabels(t, locale) : void 0;
168
+ return Island({
169
+ when: "idle",
170
+ children: /* @__PURE__ */ jsx(
171
+ SiteTreeNav,
172
+ {
173
+ tree: withCoverHrefs(tree, settings.base),
174
+ categoryOrder,
175
+ categoryIgnore: [...ignoredRoots],
176
+ ...effectiveInitiallyCollapsedCategorySlugs !== void 0 ? { initiallyCollapsedCategorySlugs: effectiveInitiallyCollapsedCategorySlugs } : {},
177
+ ...variant === "described" ? { variant } : {},
178
+ ...countLabels ? { countLabels } : {},
179
+ locale,
180
+ updatedLabel: t("doc.updated", locale),
181
+ dateFormats: dateFormatsFor(locale)
182
+ }
183
+ )
184
+ });
185
+ };
186
+ const secondaryRow = movedNodes.length > 0 && /* @__PURE__ */ jsx(
187
+ "nav",
188
+ {
189
+ "aria-label": t("home.secondaryNav", locale),
190
+ "data-home-secondary-nav": true,
191
+ class: "flex flex-wrap items-center gap-x-hsp-xl gap-y-vsp-xs",
192
+ children: movedNodes.map((n) => /* @__PURE__ */ jsx(HomeMetaLink, { href: n.href, children: n.label }, n.slug))
193
+ }
194
+ );
195
+ function renderSiteTreeSection(section) {
196
+ const variant = section.variant ?? "default";
197
+ const headingId = "zd-home-site-tree-heading";
198
+ const sectionDescription = sectionText(section, locale, "description");
199
+ const capped = treeRootCount === 1;
200
+ return /* @__PURE__ */ jsxs(
201
+ "section",
202
+ {
203
+ "data-zd-home-sitemap": true,
204
+ "data-zd-home-section": "site-tree",
205
+ "aria-labelledby": headingId,
206
+ class: `flex w-full min-w-0 flex-col gap-vsp-md${capped ? " mx-auto max-w-[80rem]" : ""}`,
207
+ children: [
208
+ /* @__PURE__ */ jsx(WideSectionHeading, { id: headingId, children: sectionText(section, locale, "heading") ?? sitemapHeading }),
209
+ sectionDescription && /* @__PURE__ */ jsx("p", { class: "text-muted", children: sectionDescription }),
210
+ siteTreeIsland(variant),
211
+ secondaryRow
212
+ ]
213
+ }
214
+ );
215
+ }
216
+ function renderDocCardsSection(section) {
217
+ const { items, diagnostics } = resolveDocCards(section.docs, {
218
+ docs: ctx.resolveNavSource(locale, void 0, {
219
+ applyDefaultLocaleOnlyFilter: true,
220
+ keepUnlisted: true
221
+ }).navDocs,
222
+ locale,
223
+ toRouteSlug: ctx.toRouteSlug,
224
+ docsUrl: (slug, loc) => ctx.docsUrl(slug, loc)
225
+ });
226
+ reportDocCardDiagnostics(diagnostics, "home.sections doc-cards");
227
+ if (items.length === 0) return null;
228
+ const headingId = "zd-home-doc-cards-heading";
229
+ const sectionDescription = sectionText(section, locale, "description");
230
+ return /* @__PURE__ */ jsxs(
231
+ "section",
232
+ {
233
+ "data-zd-home-section": "doc-cards",
234
+ "aria-labelledby": headingId,
235
+ class: "mx-auto flex w-full min-w-0 max-w-[80rem] flex-col gap-vsp-md",
236
+ children: [
237
+ /* @__PURE__ */ jsx(WideSectionHeading, { id: headingId, children: sectionText(section, locale, "heading") ?? t("home.selectedDocsHeading", locale) }),
238
+ sectionDescription && /* @__PURE__ */ jsx("p", { class: "text-muted", children: sectionDescription }),
239
+ /* @__PURE__ */ jsx(DocCardGrid, { items, ariaLabel: t("home.selectedDocsNav", locale), layout: "auto" })
240
+ ]
241
+ }
242
+ );
243
+ }
143
244
  return /* @__PURE__ */ jsxs(
144
245
  DocLayoutWithDefaults,
145
246
  {
146
247
  title: composeMetaTitle(settings.siteName),
147
248
  description: settings.metaTags.description ? description : void 0,
148
- head: /* @__PURE__ */ jsx(HeadWithDefaults, { title: settings.siteName, description }),
249
+ head: /* @__PURE__ */ jsx(
250
+ HeadWithDefaults,
251
+ {
252
+ title: settings.siteName,
253
+ description,
254
+ canonical: ctx.absoluteUrl(homePath),
255
+ locale
256
+ }
257
+ ),
149
258
  lang: locale,
150
259
  dataThemePack,
151
260
  noindex: settings.noindex,
@@ -158,59 +267,41 @@ function createHomePageView(ctx) {
158
267
  bodyEndComponents: /* @__PURE__ */ jsx(BodyEndIslands, { basePath: settings.base ?? "/" }),
159
268
  enableClientRouter: settings.dynamicPageTransition,
160
269
  children: [
161
- /* @__PURE__ */ jsx("div", { "data-zd-home-hero": true, class: "mb-vsp-xl", children: /* @__PURE__ */ jsxs("div", { class: "zd-home-inner flex flex-col items-center justify-center text-center gap-hsp-md lg:flex-row lg:text-left lg:gap-hsp-xl", children: [
162
- logoSetting === "auto" ? /* @__PURE__ */ jsx(
163
- AutoLogo,
164
- {
165
- seed: settings.siteName,
166
- class: "w-[320px] max-w-full aspect-[1200/630] text-fg shrink-0"
167
- }
168
- ) : logoSetting !== false ? /* @__PURE__ */ jsx(
169
- "div",
170
- {
171
- class: "w-[320px] max-w-full aspect-[1200/630] bg-fg shrink-0",
172
- style: logoMaskStyle(withBase(logoSetting)),
173
- "aria-hidden": "true"
174
- }
175
- ) : null,
176
- /* @__PURE__ */ jsxs("div", { class: "zd-home-copy min-w-0 lg:flex-1", children: [
177
- /* @__PURE__ */ jsx("h1", { class: "text-heading font-bold mb-vsp-2xs zd-wrap-anywhere", "data-zd-site-name": true, children: settings.siteName }),
178
- /* @__PURE__ */ jsx("p", { class: "text-muted text-small mb-vsp-sm", children: rawDescription }),
179
- /* @__PURE__ */ jsx("div", { class: "zd-home-links flex flex-wrap items-center justify-center lg:justify-start gap-hsp-md text-small", children: rowContent })
180
- ] })
181
- ] }) }),
270
+ /* @__PURE__ */ jsx(
271
+ HomeHero,
272
+ {
273
+ siteName: settings.siteName,
274
+ description: rawDescription,
275
+ logo: logoSetting,
276
+ image: homeImage,
277
+ imageLayout: settings.home?.imageLayout,
278
+ base: settings.base,
279
+ links: rowItems,
280
+ logoHref: withBase
281
+ }
282
+ ),
182
283
  hasIntro && /* @__PURE__ */ jsxs(Fragment, { children: [
183
284
  /* @__PURE__ */ jsx("hr", { class: "zd-home-rule", "data-home-rule": "upper" }),
184
285
  /* @__PURE__ */ jsx("div", { "data-zd-home-intro": true, children: /* @__PURE__ */ jsx("div", { class: "zd-home-inner", children: /* @__PURE__ */ jsx(CompactProse, { intro }) }) })
185
286
  ] }),
186
- /* @__PURE__ */ jsx("hr", { class: "zd-home-rule", "data-home-rule": "lower" }),
187
- /* @__PURE__ */ jsxs("section", { "data-zd-home-sitemap": true, children: [
188
- /* @__PURE__ */ jsx(HomeSectionHeading, { children: sitemapHeading }),
189
- Island({
190
- when: "idle",
191
- children: /* @__PURE__ */ jsx(
192
- SiteTreeNav,
287
+ homeSections === void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
288
+ /* @__PURE__ */ jsx("hr", { class: "zd-home-rule", "data-home-rule": "lower" }),
289
+ /* @__PURE__ */ jsxs("section", { "data-zd-home-sitemap": true, children: [
290
+ /* @__PURE__ */ jsx(HomeSectionHeading, { children: sitemapHeading }),
291
+ siteTreeIsland("default"),
292
+ movedNodes.length > 0 && /* @__PURE__ */ jsx(
293
+ "nav",
193
294
  {
194
- tree,
195
- categoryOrder,
196
- categoryIgnore: [...categoryIgnore, ...movedNodes.map((n) => n.slug)],
197
- ...effectiveInitiallyCollapsedCategorySlugs !== void 0 ? { initiallyCollapsedCategorySlugs: effectiveInitiallyCollapsedCategorySlugs } : {},
198
- locale,
199
- updatedLabel: t("doc.updated", locale),
200
- dateFormats: dateFormatsFor(locale)
295
+ "aria-label": t("home.secondaryNav", locale),
296
+ "data-home-secondary-nav": true,
297
+ class: "mt-vsp-md flex flex-wrap items-center gap-x-hsp-xl gap-y-vsp-xs",
298
+ children: movedNodes.map((n) => /* @__PURE__ */ jsx(HomeMetaLink, { href: n.href, children: n.label }, n.slug))
201
299
  }
202
300
  )
203
- }),
204
- movedNodes.length > 0 && /* @__PURE__ */ jsx(
205
- "nav",
206
- {
207
- "aria-label": t("home.secondaryNav", locale),
208
- "data-home-secondary-nav": true,
209
- class: "mt-vsp-md flex flex-wrap items-center gap-x-hsp-xl gap-y-vsp-xs",
210
- children: movedNodes.map((n) => /* @__PURE__ */ jsx(HomeMetaLink, { href: n.href, children: n.label }, n.slug))
211
- }
212
- )
213
- ] }),
301
+ ] })
302
+ ] }) : /* @__PURE__ */ jsx("div", { "data-zd-home-sections": true, class: "mt-vsp-2xl flex flex-col gap-vsp-2xl", children: homeSections.map(
303
+ (section) => section.type === "doc-cards" ? renderDocCardsSection(section) : renderSiteTreeSection(section)
304
+ ) }),
214
305
  settings.docTags && tagCount > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
215
306
  /* @__PURE__ */ jsx("hr", { class: "zd-home-rule", "data-home-rule": "tags" }),
216
307
  /* @__PURE__ */ jsx("section", { "data-zd-home-tags": true, children: tags && tags.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -2,6 +2,10 @@ const defaultTranslations = {
2
2
  en: {
3
3
  "home.sitemapHeading": "Explore the documentation",
4
4
  "home.secondaryNav": "More categories",
5
+ "home.selectedDocsHeading": "Start here",
6
+ "home.selectedDocsNav": "Selected documents",
7
+ "siteTreeNav.documentCount.one": "{count} document",
8
+ "siteTreeNav.documentCount.other": "{count} documents",
5
9
  "nav.gettingStarted": "Getting Started",
6
10
  "nav.learn": "Learn",
7
11
  "nav.guides": "Guides",
@@ -137,6 +141,10 @@ const defaultTranslations = {
137
141
  ja: {
138
142
  "home.sitemapHeading": "\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u63A2\u3059",
139
143
  "home.secondaryNav": "\u305D\u306E\u4ED6\u306E\u30AB\u30C6\u30B4\u30EA",
144
+ "home.selectedDocsHeading": "\u307E\u305A\u306F\u3053\u3053\u304B\u3089",
145
+ "home.selectedDocsNav": "\u9078\u3093\u3060\u6587\u66F8",
146
+ "siteTreeNav.documentCount.one": "{count} \u4EF6\u306E\u6587\u66F8",
147
+ "siteTreeNav.documentCount.other": "{count} \u4EF6\u306E\u6587\u66F8",
140
148
  "nav.gettingStarted": "\u306F\u3058\u3081\u306B",
141
149
  "nav.learn": "\u5B66\u3076",
142
150
  "nav.guides": "\u30AC\u30A4\u30C9",
@@ -0,0 +1,11 @@
1
+ /** `serverInfo` reported by `initialize`; the Server Card restates the version. */
2
+ export declare const MCP_SERVER_NAME = "zudo-doc";
3
+ export declare const MCP_SERVER_VERSION = "1.0.0";
4
+ /** Streamable HTTP endpoint under the site base; SEP-2127 reserves `<endpoint>/server-card` for a hosted card. */
5
+ export declare const MCP_ENDPOINT_PATH = "/mcp";
6
+ export declare const MCP_SERVER_CARD_PATH = "/mcp/server-card";
7
+ export declare const MCP_SERVER_CARD_SCHEMA = "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json";
8
+ export declare const MCP_SERVER_CARD_MEDIA_TYPE = "application/mcp-server-card+json";
9
+ export declare const AI_CATALOG_MEDIA_TYPE = "application/ai-catalog+json";
10
+ export declare const AI_CATALOG_SPEC_VERSION = "1.0";
11
+ export declare const AI_CATALOG_WELL_KNOWN_PATH = "/.well-known/ai-catalog.json";
@@ -0,0 +1,20 @@
1
+ const MCP_SERVER_NAME = "zudo-doc";
2
+ const MCP_SERVER_VERSION = "1.0.0";
3
+ const MCP_ENDPOINT_PATH = "/mcp";
4
+ const MCP_SERVER_CARD_PATH = `${MCP_ENDPOINT_PATH}/server-card`;
5
+ const MCP_SERVER_CARD_SCHEMA = "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json";
6
+ const MCP_SERVER_CARD_MEDIA_TYPE = "application/mcp-server-card+json";
7
+ const AI_CATALOG_MEDIA_TYPE = "application/ai-catalog+json";
8
+ const AI_CATALOG_SPEC_VERSION = "1.0";
9
+ const AI_CATALOG_WELL_KNOWN_PATH = "/.well-known/ai-catalog.json";
10
+ export {
11
+ AI_CATALOG_MEDIA_TYPE,
12
+ AI_CATALOG_SPEC_VERSION,
13
+ AI_CATALOG_WELL_KNOWN_PATH,
14
+ MCP_ENDPOINT_PATH,
15
+ MCP_SERVER_CARD_MEDIA_TYPE,
16
+ MCP_SERVER_CARD_PATH,
17
+ MCP_SERVER_CARD_SCHEMA,
18
+ MCP_SERVER_NAME,
19
+ MCP_SERVER_VERSION
20
+ };
@@ -0,0 +1,45 @@
1
+ export interface McpServerCard {
2
+ $schema: string;
3
+ name: string;
4
+ version: string;
5
+ description: string;
6
+ title?: string;
7
+ websiteUrl: string;
8
+ remotes: Array<{
9
+ type: "streamable-http";
10
+ url: string;
11
+ supportedProtocolVersions: string[];
12
+ }>;
13
+ }
14
+ export interface AiCatalog {
15
+ specVersion: string;
16
+ host: {
17
+ displayName: string;
18
+ identifier: string;
19
+ documentationUrl: string;
20
+ };
21
+ entries: Array<{
22
+ identifier: string;
23
+ displayName: string;
24
+ type: string;
25
+ url: string;
26
+ }>;
27
+ }
28
+ export interface McpDiscoveryOptions {
29
+ /** Configured site base, e.g. `/` or `/manual/`. */
30
+ base: string;
31
+ siteName: string;
32
+ /** Public origin, from {@link mcpPublicOrigin}. */
33
+ origin: string;
34
+ }
35
+ /** `""` for a root deployment, otherwise `/segment[/segment…]` without a trailing slash. */
36
+ export declare function mcpBasePath(base: string): string;
37
+ /** The origin the MCP handler cites and the discovery documents advertise: an http(s) `siteUrl` origin, else the request origin. */
38
+ export declare function mcpPublicOrigin(siteUrl: string | undefined, requestUrl: string): string;
39
+ export declare function mcpEndpointUrl(options: Pick<McpDiscoveryOptions, "base" | "origin">): string;
40
+ export declare function mcpServerCardUrl(options: Pick<McpDiscoveryOptions, "base" | "origin">): string;
41
+ export declare function buildMcpServerCard(options: McpDiscoveryOptions): McpServerCard;
42
+ /** Root-deployment catalog. ARD §4.2 requires an entry `displayName`; the AI Catalog spec leaves `description` and `version` to the card. */
43
+ export declare function buildAiCatalog(options: McpDiscoveryOptions): AiCatalog;
44
+ /** Read-only JSON discovery response: GET/HEAD with a validator, CORS preflight, 405 otherwise. */
45
+ export declare function respondWithDiscoveryDocument(request: Request, document: unknown, mediaType: string): Promise<Response>;
@@ -0,0 +1,138 @@
1
+ import { SUPPORTED_PROTOCOL_VERSIONS } from "@modelcontextprotocol/sdk/types.js";
2
+ import {
3
+ AI_CATALOG_SPEC_VERSION,
4
+ MCP_ENDPOINT_PATH,
5
+ MCP_SERVER_CARD_MEDIA_TYPE,
6
+ MCP_SERVER_CARD_PATH,
7
+ MCP_SERVER_CARD_SCHEMA,
8
+ MCP_SERVER_VERSION
9
+ } from "./constants.js";
10
+ const TITLE_MAX = 100;
11
+ const DESCRIPTION_MAX = 100;
12
+ const NAME_MAX = 200;
13
+ const SERVER_NAME_MAX = 64;
14
+ const ALLOW = "GET, HEAD, OPTIONS";
15
+ const CORS_HEADERS = {
16
+ "access-control-allow-origin": "*",
17
+ "access-control-allow-methods": "GET",
18
+ "access-control-allow-headers": "Content-Type, If-None-Match",
19
+ "access-control-expose-headers": "ETag"
20
+ };
21
+ const CACHE_CONTROL = "public, max-age=3600";
22
+ function mcpBasePath(base) {
23
+ const segments = base.split("/").filter(Boolean);
24
+ return segments.length > 0 ? `/${segments.join("/")}` : "";
25
+ }
26
+ function mcpPublicOrigin(siteUrl2, requestUrl) {
27
+ if (siteUrl2) {
28
+ try {
29
+ const url = new URL(siteUrl2);
30
+ if (url.protocol === "http:" || url.protocol === "https:") return url.origin;
31
+ } catch {
32
+ }
33
+ }
34
+ return new URL(requestUrl).origin;
35
+ }
36
+ function siteUrl(options, path) {
37
+ return new URL(`${mcpBasePath(options.base)}${path}`, options.origin).href;
38
+ }
39
+ function mcpEndpointUrl(options) {
40
+ return siteUrl(options, MCP_ENDPOINT_PATH);
41
+ }
42
+ function mcpServerCardUrl(options) {
43
+ return siteUrl(options, MCP_SERVER_CARD_PATH);
44
+ }
45
+ function clip(text, max) {
46
+ const chars = Array.from(text);
47
+ return chars.length <= max ? text : `${chars.slice(0, max - 1).join("")}\u2026`;
48
+ }
49
+ function cardTitle(siteName) {
50
+ const name = siteName.trim();
51
+ return name ? clip(name, TITLE_MAX) : void 0;
52
+ }
53
+ function serverName(base) {
54
+ const name = base.split("/").filter(Boolean).join("-").replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^[._-]+|[._-]+$/g, "").slice(0, SERVER_NAME_MAX);
55
+ return name || "docs";
56
+ }
57
+ function cardName(hostname, base) {
58
+ const server = serverName(base);
59
+ const namespace = hostname.toLowerCase().split(".").filter(Boolean).reverse().join(".").replace(/[^a-z0-9.-]+/g, "-").slice(0, NAME_MAX - server.length - 1).replace(/^[.-]+|[.-]+$/g, "");
60
+ return `${namespace || "localhost"}/${server}`;
61
+ }
62
+ function buildMcpServerCard(options) {
63
+ const { hostname } = new URL(options.origin);
64
+ const siteName = options.siteName.trim();
65
+ const title = cardTitle(siteName);
66
+ const describedSite = `Read-only search and fetch for the ${siteName} documentation.`;
67
+ return {
68
+ $schema: MCP_SERVER_CARD_SCHEMA,
69
+ name: cardName(hostname, options.base),
70
+ version: MCP_SERVER_VERSION,
71
+ description: siteName && Array.from(describedSite).length <= DESCRIPTION_MAX ? describedSite : "Read-only search and fetch for this documentation site.",
72
+ ...title === void 0 ? {} : { title },
73
+ websiteUrl: siteUrl(options, "/"),
74
+ remotes: [{
75
+ type: "streamable-http",
76
+ url: mcpEndpointUrl(options),
77
+ supportedProtocolVersions: [...SUPPORTED_PROTOCOL_VERSIONS]
78
+ }]
79
+ };
80
+ }
81
+ function buildAiCatalog(options) {
82
+ const { hostname } = new URL(options.origin);
83
+ return {
84
+ specVersion: AI_CATALOG_SPEC_VERSION,
85
+ host: {
86
+ displayName: options.siteName.trim() || hostname,
87
+ identifier: hostname,
88
+ documentationUrl: siteUrl(options, "/")
89
+ },
90
+ entries: [{
91
+ identifier: `urn:air:${hostname}:mcp:${serverName(options.base)}`,
92
+ displayName: cardTitle(options.siteName) ?? hostname,
93
+ type: MCP_SERVER_CARD_MEDIA_TYPE,
94
+ url: mcpServerCardUrl(options)
95
+ }]
96
+ };
97
+ }
98
+ async function strongEtag(body) {
99
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body));
100
+ const hex = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
101
+ return `"${hex.slice(0, 32)}"`;
102
+ }
103
+ function ifNoneMatchHits(header, etag) {
104
+ if (header === null) return false;
105
+ if (header.trim() === "*") return true;
106
+ return header.split(",").some((tag) => tag.trim().replace(/^W\//, "") === etag);
107
+ }
108
+ async function respondWithDiscoveryDocument(request, document, mediaType) {
109
+ if (request.method === "OPTIONS") {
110
+ return new Response(null, { status: 204, headers: { ...CORS_HEADERS, allow: ALLOW, "access-control-max-age": "86400" } });
111
+ }
112
+ if (request.method !== "GET" && request.method !== "HEAD") {
113
+ return new Response(JSON.stringify({ error: "Method not allowed." }), {
114
+ status: 405,
115
+ headers: { allow: ALLOW, "content-type": "application/json; charset=utf-8", "cache-control": "no-store" }
116
+ });
117
+ }
118
+ const body = `${JSON.stringify(document, null, 2)}
119
+ `;
120
+ const etag = await strongEtag(body);
121
+ const headers = { ...CORS_HEADERS, "cache-control": CACHE_CONTROL, etag, "x-content-type-options": "nosniff" };
122
+ if (ifNoneMatchHits(request.headers.get("if-none-match"), etag)) {
123
+ return new Response(null, { status: 304, headers });
124
+ }
125
+ return new Response(request.method === "HEAD" ? null : body, {
126
+ status: 200,
127
+ headers: { ...headers, "content-type": mediaType }
128
+ });
129
+ }
130
+ export {
131
+ buildAiCatalog,
132
+ buildMcpServerCard,
133
+ mcpBasePath,
134
+ mcpEndpointUrl,
135
+ mcpPublicOrigin,
136
+ mcpServerCardUrl,
137
+ respondWithDiscoveryDocument
138
+ };
@@ -4,6 +4,8 @@ import { z } from "zod";
4
4
  import { AGENT_MAX_POST_BYTES, AGENT_MAX_TOOL_RESPONSE_BYTES } from "../agent-docs/limits.js";
5
5
  import { searchAgentIndex } from "../agent-docs/search.js";
6
6
  import { AgentCorpusLoader, CorpusUnavailable } from "./loader.js";
7
+ import { MCP_SERVER_NAME, MCP_SERVER_VERSION } from "./constants.js";
8
+ import { mcpPublicOrigin } from "./discovery.js";
7
9
  const encoder = new TextEncoder();
8
10
  const annotations = { readOnlyHint: true, idempotentHint: true, destructiveHint: false, openWorldHint: false };
9
11
  function json(body, status) {
@@ -91,8 +93,8 @@ function createMcpHandler(options) {
91
93
  if (error instanceof CorpusUnavailable) return finish(json({ error: error.message }, 503));
92
94
  throw error;
93
95
  }
94
- const server = new McpServer({ name: "zudo-doc", version: "1.0.0" });
95
- const publicOrigin = options.siteUrl ? new URL(options.siteUrl).origin : requestOrigin;
96
+ const server = new McpServer({ name: MCP_SERVER_NAME, version: MCP_SERVER_VERSION });
97
+ const publicOrigin = mcpPublicOrigin(options.siteUrl, request.url);
96
98
  server.registerTool("search", { description: "Search published documentation.", inputSchema: { query: z.string() }, outputSchema: { results: z.array(z.object({ id: z.string(), title: z.string(), url: z.string() })) }, annotations }, async ({ query }) => {
97
99
  const corpus = await loader.corpus();
98
100
  const outcome = searchAgentIndex(corpus.index, query);
@@ -2,3 +2,6 @@ export { createMcpHandler } from "./handler.js";
2
2
  export { AgentCorpusLoader, CorpusUnavailable } from "./loader.js";
3
3
  export type { McpHandlerOptions } from "./handler.js";
4
4
  export type { ReadAsset } from "./loader.js";
5
+ export { AI_CATALOG_MEDIA_TYPE, AI_CATALOG_SPEC_VERSION, AI_CATALOG_WELL_KNOWN_PATH, MCP_ENDPOINT_PATH, MCP_SERVER_CARD_MEDIA_TYPE, MCP_SERVER_CARD_PATH, MCP_SERVER_CARD_SCHEMA, MCP_SERVER_NAME, MCP_SERVER_VERSION, } from "./constants.js";
6
+ export { buildAiCatalog, buildMcpServerCard, mcpBasePath, mcpEndpointUrl, mcpPublicOrigin, mcpServerCardUrl, respondWithDiscoveryDocument, } from "./discovery.js";
7
+ export type { AiCatalog, McpDiscoveryOptions, McpServerCard } from "./discovery.js";
package/dist/mcp/index.js CHANGED
@@ -1,7 +1,43 @@
1
1
  import { createMcpHandler } from "./handler.js";
2
2
  import { AgentCorpusLoader, CorpusUnavailable } from "./loader.js";
3
+ import {
4
+ AI_CATALOG_MEDIA_TYPE,
5
+ AI_CATALOG_SPEC_VERSION,
6
+ AI_CATALOG_WELL_KNOWN_PATH,
7
+ MCP_ENDPOINT_PATH,
8
+ MCP_SERVER_CARD_MEDIA_TYPE,
9
+ MCP_SERVER_CARD_PATH,
10
+ MCP_SERVER_CARD_SCHEMA,
11
+ MCP_SERVER_NAME,
12
+ MCP_SERVER_VERSION
13
+ } from "./constants.js";
14
+ import {
15
+ buildAiCatalog,
16
+ buildMcpServerCard,
17
+ mcpBasePath,
18
+ mcpEndpointUrl,
19
+ mcpPublicOrigin,
20
+ mcpServerCardUrl,
21
+ respondWithDiscoveryDocument
22
+ } from "./discovery.js";
3
23
  export {
24
+ AI_CATALOG_MEDIA_TYPE,
25
+ AI_CATALOG_SPEC_VERSION,
26
+ AI_CATALOG_WELL_KNOWN_PATH,
4
27
  AgentCorpusLoader,
5
28
  CorpusUnavailable,
6
- createMcpHandler
29
+ MCP_ENDPOINT_PATH,
30
+ MCP_SERVER_CARD_MEDIA_TYPE,
31
+ MCP_SERVER_CARD_PATH,
32
+ MCP_SERVER_CARD_SCHEMA,
33
+ MCP_SERVER_NAME,
34
+ MCP_SERVER_VERSION,
35
+ buildAiCatalog,
36
+ buildMcpServerCard,
37
+ createMcpHandler,
38
+ mcpBasePath,
39
+ mcpEndpointUrl,
40
+ mcpPublicOrigin,
41
+ mcpServerCardUrl,
42
+ respondWithDiscoveryDocument
7
43
  };
@@ -16,6 +16,12 @@ export interface DocCardGridProps {
16
16
  ariaLabel?: string;
17
17
  /** Optional extra CSS classes appended to the `<nav>` element. */
18
18
  class?: string;
19
+ /**
20
+ * Column layout. Omitted keeps the established one column, two from `sm`.
21
+ * `"auto"` fits as many ~18rem columns as the available width allows,
22
+ * capped at three: a lone card fills its section and further cards wrap.
23
+ */
24
+ layout?: "auto";
19
25
  }
20
26
  /**
21
27
  * DocCardGrid — server renderer for a flat list of documentation cards.
@@ -1,4 +1,5 @@
1
1
  import { jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
2
+ const AUTO_GRID_COLUMNS = "repeat(auto-fit, minmax(min(100%, max(18rem, calc((100% - 2 * var(--spacing-hsp-lg)) / 3))), 1fr))";
2
3
  function ArrowIcon() {
3
4
  return /* @__PURE__ */ jsx(
4
5
  "svg",
@@ -12,27 +13,36 @@ function ArrowIcon() {
12
13
  );
13
14
  }
14
15
  function DocCardGrid(props) {
15
- const { items, ariaLabel = "Child pages", class: className } = props;
16
+ const { items, ariaLabel = "Child pages", class: className, layout } = props;
16
17
  if (items.length === 0) return null;
18
+ const auto = layout === "auto";
17
19
  const navClass = [
18
- "grid grid-cols-1 gap-x-hsp-lg gap-y-vsp-md sm:grid-cols-2",
20
+ auto ? "grid gap-x-hsp-lg gap-y-vsp-md" : "grid grid-cols-1 gap-x-hsp-lg gap-y-vsp-md sm:grid-cols-2",
19
21
  className
20
22
  ].filter(Boolean).join(" ");
21
- return /* @__PURE__ */ jsx("nav", { "aria-label": ariaLabel, class: navClass, children: items.map((item, i) => /* @__PURE__ */ jsxs(
22
- "a",
23
+ return /* @__PURE__ */ jsx(
24
+ "nav",
23
25
  {
24
- href: item.href,
25
- class: "group block rounded border border-muted bg-surface px-hsp-lg py-vsp-md hover:border-accent",
26
- children: [
27
- /* @__PURE__ */ jsxs("span", { class: "flex items-center gap-hsp-xs", children: [
28
- /* @__PURE__ */ jsx(ArrowIcon, {}),
29
- /* @__PURE__ */ jsx("span", { class: "font-medium text-fg group-hover:text-accent group-hover:underline group-focus-visible:text-accent group-focus-visible:underline", children: item.title })
30
- ] }),
31
- item.description && /* @__PURE__ */ jsx("span", { class: "mt-vsp-2xs block text-small text-muted group-hover:text-accent group-focus-visible:text-accent", children: item.description })
32
- ]
33
- },
34
- `doc-card-${i}`
35
- )) });
26
+ "aria-label": ariaLabel,
27
+ class: navClass,
28
+ ...auto ? { "data-layout": "auto", style: { "grid-template-columns": AUTO_GRID_COLUMNS } } : {},
29
+ children: items.map((item, i) => /* @__PURE__ */ jsxs(
30
+ "a",
31
+ {
32
+ href: item.href,
33
+ class: "group block rounded border border-muted bg-surface px-hsp-lg py-vsp-md hover:border-accent",
34
+ children: [
35
+ /* @__PURE__ */ jsxs("span", { class: "flex items-center gap-hsp-xs", children: [
36
+ /* @__PURE__ */ jsx(ArrowIcon, {}),
37
+ /* @__PURE__ */ jsx("span", { class: "font-medium text-fg group-hover:text-accent group-hover:underline group-focus-visible:text-accent group-focus-visible:underline", children: item.title })
38
+ ] }),
39
+ item.description && /* @__PURE__ */ jsx("span", { class: "mt-vsp-2xs block text-small text-muted group-hover:text-accent group-focus-visible:text-accent", children: item.description })
40
+ ]
41
+ },
42
+ `doc-card-${i}`
43
+ ))
44
+ }
45
+ );
36
46
  }
37
47
  export {
38
48
  DocCardGrid