@assistant-ui/mcp-docs-server 0.2.0 → 0.2.1

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 (126) hide show
  1. package/.docs/organized/code-examples/waterfall.md +12 -13
  2. package/.docs/organized/code-examples/with-a2a.md +16 -11
  3. package/.docs/organized/code-examples/with-ag-ui.md +14 -12
  4. package/.docs/organized/code-examples/with-ai-sdk-v7.md +13 -12
  5. package/.docs/organized/code-examples/with-artifacts.md +13 -12
  6. package/.docs/organized/code-examples/with-assistant-transport.md +19 -27
  7. package/.docs/organized/code-examples/with-browser-extension.md +17 -10
  8. package/.docs/organized/code-examples/with-chain-of-thought.md +16 -14
  9. package/.docs/organized/code-examples/with-cloud-standalone.md +9 -10
  10. package/.docs/organized/code-examples/with-cloud.md +18 -13
  11. package/.docs/organized/code-examples/with-custom-thread-list.md +13 -12
  12. package/.docs/organized/code-examples/with-elevenlabs-conversational.md +13 -13
  13. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +17 -15
  14. package/.docs/organized/code-examples/with-eve.md +65 -11
  15. package/.docs/organized/code-examples/with-expo.md +20 -19
  16. package/.docs/organized/code-examples/with-external-store.md +16 -11
  17. package/.docs/organized/code-examples/with-ffmpeg.md +20 -14
  18. package/.docs/organized/code-examples/with-generative-ui.md +16 -17
  19. package/.docs/organized/code-examples/with-google-adk.md +17 -12
  20. package/.docs/organized/code-examples/with-heat-graph.md +6 -7
  21. package/.docs/organized/code-examples/with-image-generation.md +9 -10
  22. package/.docs/organized/code-examples/with-interactables.md +13 -12
  23. package/.docs/organized/code-examples/with-langchain.md +7 -8
  24. package/.docs/organized/code-examples/with-langgraph.md +17 -11
  25. package/.docs/organized/code-examples/with-livekit.md +12 -12
  26. package/.docs/organized/code-examples/with-mcp.md +13 -14
  27. package/.docs/organized/code-examples/with-nuxt.md +2492 -0
  28. package/.docs/organized/code-examples/with-opencode.md +23 -14
  29. package/.docs/organized/code-examples/with-pi.md +59 -57
  30. package/.docs/organized/code-examples/with-react-hook-form.md +14 -13
  31. package/.docs/organized/code-examples/with-react-ink-web.md +7 -8
  32. package/.docs/organized/code-examples/with-react-ink.md +5 -5
  33. package/.docs/organized/code-examples/with-react-router.md +15 -9
  34. package/.docs/organized/code-examples/with-resumable-stream.md +11 -12
  35. package/.docs/organized/code-examples/with-store.md +27 -16
  36. package/.docs/organized/code-examples/with-tanstack.md +18 -12
  37. package/.docs/organized/code-examples/with-tap-runtime.md +15 -15
  38. package/.docs/organized/code-examples/with-virtualized-thread.md +8 -9
  39. package/.docs/organized/code-examples/with-vue.md +408 -0
  40. package/.docs/raw/docs/(docs)/cli.mdx +1 -1
  41. package/.docs/raw/docs/(docs)/index.mdx +9 -76
  42. package/.docs/raw/docs/(docs)/installation.mdx +4 -18
  43. package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +24 -4
  44. package/.docs/raw/docs/(reference)/api-reference/integrations/eve.mdx +8 -0
  45. package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +24 -1
  46. package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +1 -1
  47. package/.docs/raw/docs/cloud/ai-sdk.mdx +2 -2
  48. package/.docs/raw/docs/copilots/model-context.mdx +4 -3
  49. package/.docs/raw/docs/copilots/motivation.mdx +4 -4
  50. package/.docs/raw/docs/guides/chain-of-thought.mdx +1 -1
  51. package/.docs/raw/docs/guides/electron.mdx +1 -1
  52. package/.docs/raw/docs/guides/resumable-streams.mdx +74 -3
  53. package/.docs/raw/docs/guides/suggestions.mdx +9 -9
  54. package/.docs/raw/docs/ink/hooks.mdx +9 -4
  55. package/.docs/raw/docs/ink/primitives.mdx +4 -3
  56. package/.docs/raw/docs/integrations/attachments/custom-adapter.mdx +16 -0
  57. package/.docs/raw/docs/integrations/auth/better-auth.mdx +1 -1
  58. package/.docs/raw/docs/integrations/auth/clerk.mdx +1 -1
  59. package/.docs/raw/docs/integrations/auth/next-auth.mdx +1 -1
  60. package/.docs/raw/docs/integrations/frameworks/cloudflare-agents/overview.mdx +1 -1
  61. package/.docs/raw/docs/integrations/frameworks/mastra/full-stack.mdx +2 -2
  62. package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +1 -1
  63. package/.docs/raw/docs/integrations/gateways/index.mdx +2 -2
  64. package/.docs/raw/docs/integrations/observability/helicone.mdx +2 -2
  65. package/.docs/raw/docs/integrations/observability/langfuse.mdx +1 -1
  66. package/.docs/raw/docs/integrations/observability/langsmith.mdx +2 -2
  67. package/.docs/raw/docs/migrations/toolkit-tools.mdx +15 -13
  68. package/.docs/raw/docs/migrations/v0-15.mdx +84 -4
  69. package/.docs/raw/docs/primitives/attachment.mdx +2 -2
  70. package/.docs/raw/docs/primitives/composer.mdx +2 -2
  71. package/.docs/raw/docs/primitives/message.mdx +33 -1
  72. package/.docs/raw/docs/primitives/suggestion.mdx +1 -1
  73. package/.docs/raw/docs/react-native/hooks.mdx +14 -4
  74. package/.docs/raw/docs/react-native/index.mdx +1 -1
  75. package/.docs/raw/docs/react-native/primitives.mdx +2 -2
  76. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +1 -1
  77. package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +1 -1
  78. package/.docs/raw/docs/runtimes/ai-sdk/v6-legacy.mdx +9 -10
  79. package/.docs/raw/docs/runtimes/ai-sdk/v7.mdx +9 -10
  80. package/.docs/raw/docs/runtimes/concepts/threads.mdx +40 -1
  81. package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +18 -0
  82. package/.docs/raw/docs/runtimes/custom/external-store.mdx +30 -1
  83. package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +36 -9
  84. package/.docs/raw/docs/runtimes/eve/overview.mdx +51 -0
  85. package/.docs/raw/docs/runtimes/eve/quickstart.mdx +51 -2
  86. package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +9 -12
  87. package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +1 -1
  88. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +7 -7
  89. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +4 -4
  90. package/.docs/raw/docs/runtimes/opencode/hooks.mdx +1 -0
  91. package/.docs/raw/docs/runtimes/opencode/overview.mdx +10 -0
  92. package/.docs/raw/docs/tools/backend.mdx +2 -2
  93. package/.docs/raw/docs/tools/defining-tools.mdx +9 -7
  94. package/.docs/raw/docs/tools/dynamic-tools.mdx +6 -4
  95. package/.docs/raw/docs/tools/interactables-legacy.mdx +24 -11
  96. package/.docs/raw/docs/tools/interactables.mdx +24 -13
  97. package/.docs/raw/docs/tools/mcp-apps.mdx +35 -6
  98. package/.docs/raw/docs/tools/mcp.mdx +9 -7
  99. package/.docs/raw/docs/tools/tool-ui.mdx +26 -22
  100. package/.docs/raw/docs/tools/user-managed-mcp.mdx +12 -7
  101. package/.docs/raw/docs/ui/file.mdx +6 -1
  102. package/.docs/raw/docs/ui/mcp-config.mdx +8 -3
  103. package/.docs/raw/docs/ui/model-selector.mdx +8 -8
  104. package/.docs/raw/docs/ui/part-grouping.mdx +1 -1
  105. package/.docs/raw/docs/ui/thread.mdx +24 -5
  106. package/.docs/raw/docs/utilities/react-o11y.mdx +7 -9
  107. package/dist/constants.js +2 -2
  108. package/dist/constants.js.map +1 -1
  109. package/dist/index.js.map +1 -1
  110. package/dist/prepare-docs/prepare.js.map +1 -1
  111. package/dist/tools/docs.js +4 -2
  112. package/dist/tools/docs.js.map +1 -1
  113. package/dist/tools/examples.js +2 -1
  114. package/dist/tools/examples.js.map +1 -1
  115. package/dist/tools/resources.js +2 -1
  116. package/dist/tools/resources.js.map +1 -1
  117. package/dist/tools/tests/test-setup.js +2 -1
  118. package/dist/tools/tests/test-setup.js.map +1 -1
  119. package/dist/tools/xulux-templates.js +4 -2
  120. package/dist/tools/xulux-templates.js.map +1 -1
  121. package/dist/utils/mdx.js +2 -1
  122. package/dist/utils/mdx.js.map +1 -1
  123. package/dist/xulux/catalog-client.js +1 -1
  124. package/dist/xulux/catalog-client.js.map +1 -1
  125. package/package.json +4 -4
  126. package/src/tools/tests/docs.test.ts +2 -2
@@ -22,7 +22,8 @@ async function readDocumentation(docPath) {
22
22
  };
23
23
  }
24
24
  try {
25
- const fullPath = join(DOCS_PATH, sanitizePath(docPath));
25
+ const sanitized = sanitizePath(docPath);
26
+ const fullPath = join(DOCS_PATH, sanitized);
26
27
  try {
27
28
  if ((await lstat(fullPath)).isSymbolicLink()) {
28
29
  logger.warn(`Symlink detected at path: ${fullPath}`);
@@ -121,10 +122,11 @@ async function readDocumentation(docPath) {
121
122
  };
122
123
  }
123
124
  }
125
+ const availablePaths = await getAvailablePaths();
124
126
  return {
125
127
  path: docPath,
126
128
  found: false,
127
- suggestions: findNearestPaths(docPath, await getAvailablePaths())
129
+ suggestions: findNearestPaths(docPath, availablePaths)
128
130
  };
129
131
  } catch (error) {
130
132
  if (error instanceof Error && error.message.includes("Invalid path")) return {
@@ -1 +1 @@
1
- {"version":3,"file":"docs.js","names":[],"sources":["../../src/tools/docs.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { stat, lstat } from \"node:fs/promises\";\nimport { join, extname } from \"node:path\";\nimport {\n DOCS_PATH,\n MDX_EXTENSION,\n MAX_FILE_SIZE,\n MAX_DIRECTORY_CONTENT_SIZE,\n} from \"../constants.js\";\nimport { logger } from \"../utils/logger.js\";\nimport {\n listDirContents,\n getAvailablePaths,\n findNearestPaths,\n pathExists,\n} from \"../utils/paths.js\";\nimport { readMDXFile, formatMDXContent } from \"../utils/mdx.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { sanitizePath } from \"../utils/security.js\";\n\nconst docsInputSchema = z.object({\n paths: z\n .array(z.string())\n .min(1)\n .describe(\n 'Documentation paths to retrieve (e.g., [\"getting-started\", \"api-reference/primitives/thread\"])',\n ),\n});\n\ninterface DocResult {\n path: string;\n found: boolean;\n type?: \"file\" | \"directory\";\n content?: string;\n files?: string[];\n directories?: string[];\n summaries?: Array<{ name: string; title?: string; excerpt?: string }>;\n title?: string;\n excerpt?: string;\n suggestions?: string[];\n hint?: string;\n error?: string;\n}\n\nasync function readDocumentation(docPath: string): Promise<DocResult> {\n logger.debug(`Reading documentation for path: ${docPath}`);\n\n if (docPath === \"/\" || docPath === \"\") {\n const { directories, files } = await listDirContents(DOCS_PATH);\n return {\n path: \"/\",\n found: true,\n type: \"directory\",\n directories,\n files: files.map((f) => f.replace(MDX_EXTENSION, \"\")),\n };\n }\n\n try {\n const sanitized = sanitizePath(docPath);\n const fullPath = join(DOCS_PATH, sanitized);\n\n try {\n const lstats = await lstat(fullPath);\n if (lstats.isSymbolicLink()) {\n logger.warn(`Symlink detected at path: ${fullPath}`);\n return {\n path: docPath,\n found: false,\n error: \"Symlinks are not allowed for security reasons\",\n };\n }\n } catch {}\n\n if (await pathExists(fullPath)) {\n const stats = await stat(fullPath);\n\n if (stats.isFile() && stats.size > MAX_FILE_SIZE) {\n logger.warn(`File too large: ${fullPath} (${stats.size} bytes)`);\n return {\n path: docPath,\n found: false,\n error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`,\n };\n }\n\n if (stats.isDirectory()) {\n const { directories, files } = await listDirContents(fullPath);\n\n const contents: Record<string, string> = {};\n const summaries: Array<{\n name: string;\n title?: string;\n excerpt?: string;\n }> = [];\n let aggregateSize = 0;\n let truncated = false;\n for (const file of files) {\n let fileSize: number;\n try {\n fileSize = (await stat(join(fullPath, file))).size;\n } catch (error) {\n logger.warn(\n `Failed to stat MDX file: ${join(fullPath, file)}`,\n error,\n );\n continue;\n }\n aggregateSize += fileSize;\n if (aggregateSize > MAX_DIRECTORY_CONTENT_SIZE) {\n truncated = true;\n break;\n }\n const mdxContent = await readMDXFile(join(fullPath, file));\n if (mdxContent) {\n const name = file.replace(MDX_EXTENSION, \"\");\n contents[name] = formatMDXContent(mdxContent);\n const title = mdxContent.frontmatter[\"title\"];\n summaries.push({\n name,\n ...(typeof title === \"string\" && { title }),\n ...(mdxContent.excerpt !== undefined && {\n excerpt: mdxContent.excerpt,\n }),\n });\n }\n }\n\n const content =\n !truncated && Object.keys(contents).length > 0\n ? JSON.stringify(contents, null, 2)\n : undefined;\n return {\n path: docPath,\n found: true,\n type: \"directory\",\n directories,\n files: files.map((f) => f.replace(MDX_EXTENSION, \"\")),\n ...(summaries.length > 0 && { summaries }),\n ...(content !== undefined && { content }),\n ...(truncated && {\n hint: `Directory content exceeds ${MAX_DIRECTORY_CONTENT_SIZE} bytes and was omitted; summaries cover only the files read before the limit. Request individual files by path to retrieve their content.`,\n }),\n };\n }\n }\n\n const mdxPath =\n extname(fullPath) === MDX_EXTENSION\n ? fullPath\n : `${fullPath}${MDX_EXTENSION}`;\n\n try {\n const mdxLstats = await lstat(mdxPath);\n if (mdxLstats.isSymbolicLink()) {\n logger.warn(`Symlink detected at MDX path: ${mdxPath}`);\n return {\n path: docPath,\n found: false,\n error: \"Symlinks are not allowed for security reasons\",\n };\n }\n\n if (mdxLstats.size > MAX_FILE_SIZE) {\n logger.warn(`MDX file too large: ${mdxPath} (${mdxLstats.size} bytes)`);\n return {\n path: docPath,\n found: false,\n error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`,\n };\n }\n } catch {}\n\n if (await pathExists(mdxPath)) {\n const mdxContent = await readMDXFile(mdxPath);\n\n if (mdxContent) {\n const title = mdxContent.frontmatter[\"title\"];\n return {\n path: docPath,\n found: true,\n type: \"file\",\n content: formatMDXContent(mdxContent),\n ...(typeof title === \"string\" && { title }),\n ...(mdxContent.excerpt !== undefined && {\n excerpt: mdxContent.excerpt,\n }),\n };\n }\n }\n\n const availablePaths = await getAvailablePaths();\n const suggestions = findNearestPaths(docPath, availablePaths);\n\n return {\n path: docPath,\n found: false,\n suggestions,\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Invalid path\")) {\n return {\n path: docPath,\n found: false,\n error: error.message,\n };\n }\n throw error;\n }\n}\n\nexport const docsTools = {\n name: \"assistantUIDocs\",\n description:\n 'Retrieve assistant-ui documentation by path. Use \"/\" to list all sections. Supports multiple paths in a single request.',\n parameters: docsInputSchema,\n execute: async ({ paths }: z.infer<typeof docsInputSchema>) => {\n logger.info(`Retrieving documentation for paths: ${paths.join(\", \")}`);\n\n try {\n const results = await Promise.all(\n paths.map((path) => readDocumentation(path)),\n );\n\n if (results.length === 1) {\n const result = results[0]!;\n if (result.error) {\n return formatMCPResponse({\n error: result.error,\n path: result.path,\n });\n }\n if (!result.found) {\n return formatMCPResponse({\n error: `Documentation not found for path: ${result.path}`,\n suggestions: result.suggestions,\n hint: 'Use \"/\" to list all available documentation sections',\n });\n }\n return formatMCPResponse(result);\n }\n\n return formatMCPResponse({\n results,\n summary: `Retrieved ${results.filter((r) => r.found).length} of ${results.length} requested paths`,\n });\n } catch (error) {\n logger.error(\"Failed to retrieve documentation\", error);\n return formatMCPResponse({\n error: \"Failed to retrieve documentation\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,kBAAkB,EAAE,OAAO,EAC/B,OAAO,EACJ,MAAM,EAAE,OAAO,CAAC,CAAC,CACjB,IAAI,CAAC,CAAC,CACN,SACC,oGACF,EACJ,CAAC;AAiBD,eAAe,kBAAkB,SAAqC;CACpE,OAAO,MAAM,mCAAmC,SAAS;CAEzD,IAAI,YAAY,OAAO,YAAY,IAAI;EACrC,MAAM,EAAE,aAAa,UAAU,MAAM,gBAAgB,SAAS;EAC9D,OAAO;GACL,MAAM;GACN,OAAO;GACP,MAAM;GACN;GACA,OAAO,MAAM,KAAK,MAAM,EAAE,QAAQ,eAAe,EAAE,CAAC;EACtD;CACF;CAEA,IAAI;EAEF,MAAM,WAAW,KAAK,WADJ,aAAa,OACU,CAAC;EAE1C,IAAI;GAEF,KAAI,MADiB,MAAM,QAAQ,EAAA,CACxB,eAAe,GAAG;IAC3B,OAAO,KAAK,6BAA6B,UAAU;IACnD,OAAO;KAC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,KAAK,uCAAuC,MAAM,KAAK,IAAI,GAAG;EAErE,IAAI;GACF,MAAM,UAAU,MAAM,QAAQ,IAC5B,MAAM,KAAK,SAAS,kBAAkB,IAAI,CAAC,CAC7C;GAEA,IAAI,QAAQ,WAAW,GAAG;IACxB,MAAM,SAAS,QAAQ;IACvB,IAAI,OAAO,OACT,OAAO,kBAAkB;KACvB,OAAO,OAAO;KACd,MAAM,OAAO;IACf,CAAC;IAEH,IAAI,CAAC,OAAO,OACV,OAAO,kBAAkB;KACvB,OAAO,qCAAqC,OAAO;KACnD,aAAa,OAAO;KACpB,MAAM;IACR,CAAC;IAEH,OAAO,kBAAkB,MAAM;GACjC;GAEA,OAAO,kBAAkB;IACvB;IACA,SAAS,aAAa,QAAQ,QAAQ,MAAM,EAAE,KAAK,CAAC,CAAC,OAAO,MAAM,QAAQ,OAAO;GACnF,CAAC;EACH,SAAS,OAAO;GACd,OAAO,MAAM,oCAAoC,KAAK;GACtD,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"docs.js","names":[],"sources":["../../src/tools/docs.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { stat, lstat } from \"node:fs/promises\";\nimport { join, extname } from \"node:path\";\nimport {\n DOCS_PATH,\n MDX_EXTENSION,\n MAX_FILE_SIZE,\n MAX_DIRECTORY_CONTENT_SIZE,\n} from \"../constants.js\";\nimport { logger } from \"../utils/logger.js\";\nimport {\n listDirContents,\n getAvailablePaths,\n findNearestPaths,\n pathExists,\n} from \"../utils/paths.js\";\nimport { readMDXFile, formatMDXContent } from \"../utils/mdx.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { sanitizePath } from \"../utils/security.js\";\n\nconst docsInputSchema = z.object({\n paths: z\n .array(z.string())\n .min(1)\n .describe(\n 'Documentation paths to retrieve (e.g., [\"getting-started\", \"api-reference/primitives/thread\"])',\n ),\n});\n\ninterface DocResult {\n path: string;\n found: boolean;\n type?: \"file\" | \"directory\";\n content?: string;\n files?: string[];\n directories?: string[];\n summaries?: Array<{ name: string; title?: string; excerpt?: string }>;\n title?: string;\n excerpt?: string;\n suggestions?: string[];\n hint?: string;\n error?: string;\n}\n\nasync function readDocumentation(docPath: string): Promise<DocResult> {\n logger.debug(`Reading documentation for path: ${docPath}`);\n\n if (docPath === \"/\" || docPath === \"\") {\n const { directories, files } = await listDirContents(DOCS_PATH);\n return {\n path: \"/\",\n found: true,\n type: \"directory\",\n directories,\n files: files.map((f) => f.replace(MDX_EXTENSION, \"\")),\n };\n }\n\n try {\n const sanitized = sanitizePath(docPath);\n const fullPath = join(DOCS_PATH, sanitized);\n\n try {\n const lstats = await lstat(fullPath);\n if (lstats.isSymbolicLink()) {\n logger.warn(`Symlink detected at path: ${fullPath}`);\n return {\n path: docPath,\n found: false,\n error: \"Symlinks are not allowed for security reasons\",\n };\n }\n } catch {}\n\n if (await pathExists(fullPath)) {\n const stats = await stat(fullPath);\n\n if (stats.isFile() && stats.size > MAX_FILE_SIZE) {\n logger.warn(`File too large: ${fullPath} (${stats.size} bytes)`);\n return {\n path: docPath,\n found: false,\n error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`,\n };\n }\n\n if (stats.isDirectory()) {\n const { directories, files } = await listDirContents(fullPath);\n\n const contents: Record<string, string> = {};\n const summaries: Array<{\n name: string;\n title?: string;\n excerpt?: string;\n }> = [];\n let aggregateSize = 0;\n let truncated = false;\n for (const file of files) {\n let fileSize: number;\n try {\n fileSize = (await stat(join(fullPath, file))).size;\n } catch (error) {\n logger.warn(\n `Failed to stat MDX file: ${join(fullPath, file)}`,\n error,\n );\n continue;\n }\n aggregateSize += fileSize;\n if (aggregateSize > MAX_DIRECTORY_CONTENT_SIZE) {\n truncated = true;\n break;\n }\n const mdxContent = await readMDXFile(join(fullPath, file));\n if (mdxContent) {\n const name = file.replace(MDX_EXTENSION, \"\");\n contents[name] = formatMDXContent(mdxContent);\n const title = mdxContent.frontmatter[\"title\"];\n summaries.push({\n name,\n ...(typeof title === \"string\" && { title }),\n ...(mdxContent.excerpt !== undefined && {\n excerpt: mdxContent.excerpt,\n }),\n });\n }\n }\n\n const content =\n !truncated && Object.keys(contents).length > 0\n ? JSON.stringify(contents, null, 2)\n : undefined;\n return {\n path: docPath,\n found: true,\n type: \"directory\",\n directories,\n files: files.map((f) => f.replace(MDX_EXTENSION, \"\")),\n ...(summaries.length > 0 && { summaries }),\n ...(content !== undefined && { content }),\n ...(truncated && {\n hint: `Directory content exceeds ${MAX_DIRECTORY_CONTENT_SIZE} bytes and was omitted; summaries cover only the files read before the limit. Request individual files by path to retrieve their content.`,\n }),\n };\n }\n }\n\n const mdxPath =\n extname(fullPath) === MDX_EXTENSION\n ? fullPath\n : `${fullPath}${MDX_EXTENSION}`;\n\n try {\n const mdxLstats = await lstat(mdxPath);\n if (mdxLstats.isSymbolicLink()) {\n logger.warn(`Symlink detected at MDX path: ${mdxPath}`);\n return {\n path: docPath,\n found: false,\n error: \"Symlinks are not allowed for security reasons\",\n };\n }\n\n if (mdxLstats.size > MAX_FILE_SIZE) {\n logger.warn(`MDX file too large: ${mdxPath} (${mdxLstats.size} bytes)`);\n return {\n path: docPath,\n found: false,\n error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`,\n };\n }\n } catch {}\n\n if (await pathExists(mdxPath)) {\n const mdxContent = await readMDXFile(mdxPath);\n\n if (mdxContent) {\n const title = mdxContent.frontmatter[\"title\"];\n return {\n path: docPath,\n found: true,\n type: \"file\",\n content: formatMDXContent(mdxContent),\n ...(typeof title === \"string\" && { title }),\n ...(mdxContent.excerpt !== undefined && {\n excerpt: mdxContent.excerpt,\n }),\n };\n }\n }\n\n const availablePaths = await getAvailablePaths();\n const suggestions = findNearestPaths(docPath, availablePaths);\n\n return {\n path: docPath,\n found: false,\n suggestions,\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Invalid path\")) {\n return {\n path: docPath,\n found: false,\n error: error.message,\n };\n }\n throw error;\n }\n}\n\nexport const docsTools = {\n name: \"assistantUIDocs\",\n description:\n 'Retrieve assistant-ui documentation by path. Use \"/\" to list all sections. Supports multiple paths in a single request.',\n parameters: docsInputSchema,\n execute: async ({ paths }: z.infer<typeof docsInputSchema>) => {\n logger.info(`Retrieving documentation for paths: ${paths.join(\", \")}`);\n\n try {\n const results = await Promise.all(\n paths.map((path) => readDocumentation(path)),\n );\n\n if (results.length === 1) {\n const result = results[0]!;\n if (result.error) {\n return formatMCPResponse({\n error: result.error,\n path: result.path,\n });\n }\n if (!result.found) {\n return formatMCPResponse({\n error: `Documentation not found for path: ${result.path}`,\n suggestions: result.suggestions,\n hint: 'Use \"/\" to list all available documentation sections',\n });\n }\n return formatMCPResponse(result);\n }\n\n return formatMCPResponse({\n results,\n summary: `Retrieved ${results.filter((r) => r.found).length} of ${results.length} requested paths`,\n });\n } catch (error) {\n logger.error(\"Failed to retrieve documentation\", error);\n return formatMCPResponse({\n error: \"Failed to retrieve documentation\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,kBAAkB,EAAE,OAAO,EAC/B,OAAO,EACJ,MAAM,EAAE,OAAO,CAAC,CAAC,CACjB,IAAI,CAAC,CAAC,CACN,SACC,oGACF,EACJ,CAAC;AAiBD,eAAe,kBAAkB,SAAqC;CACpE,OAAO,MAAM,mCAAmC,SAAS;CAEzD,IAAI,YAAY,OAAO,YAAY,IAAI;EACrC,MAAM,EAAE,aAAa,UAAU,MAAM,gBAAgB,SAAS;EAC9D,OAAO;GACL,MAAM;GACN,OAAO;GACP,MAAM;GACN;GACA,OAAO,MAAM,KAAK,MAAM,EAAE,QAAQ,eAAe,EAAE,CAAC;EACtD;CACF;CAEA,IAAI;EACF,MAAM,YAAY,aAAa,OAAO;EACtC,MAAM,WAAW,KAAK,WAAW,SAAS;EAE1C,IAAI;GAEF,KAAI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AEF,MAAM;CACR;AACF;AAEA,MAAa,YAAY;CACvB,MAAM;CACN,aACE;CACF,YAAY;CACZ,SAAS,OAAO,EAAE,YAA6C;EAC7D,OAAO,KAAK,uCAAuC,MAAM,KAAK,IAAI,GAAG;EAErE,IAAI;GACF,MAAM,UAAU,MAAM,QAAQ,IAC5B,MAAM,KAAK,SAAS,kBAAkB,IAAI,CAAC,CAC7C;GAEA,IAAI,QAAQ,WAAW,GAAG;IACxB,MAAM,SAAS,QAAQ;IACvB,IAAI,OAAO,OACT,OAAO,kBAAkB;KACvB,OAAO,OAAO;KACd,MAAM,OAAO;IACf,CAAC;IAEH,IAAI,CAAC,OAAO,OACV,OAAO,kBAAkB;KACvB,OAAO,qCAAqC,OAAO;KACnD,aAAa,OAAO;KACpB,MAAM;IACR,CAAC;IAEH,OAAO,kBAAkB,MAAM;GACjC;GAEA,OAAO,kBAAkB;IACvB;IACA,SAAS,aAAa,QAAQ,QAAQ,MAAM,EAAE,KAAK,CAAC,CAAC,OAAO,MAAM,QAAQ,OAAO;GACnF,CAAC;EACH,SAAS,OAAO;GACd,OAAO,MAAM,oCAAoC,KAAK;GACtD,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF"}
@@ -20,7 +20,8 @@ async function scanCodeExamples() {
20
20
  }
21
21
  async function readCodeExample(exampleName) {
22
22
  try {
23
- const filePath = join(CODE_EXAMPLES_PATH, `${sanitizePath(exampleName)}.md`);
23
+ const sanitized = sanitizePath(exampleName);
24
+ const filePath = join(CODE_EXAMPLES_PATH, `${sanitized}.md`);
24
25
  const stats = await lstat(filePath);
25
26
  if (stats.isSymbolicLink()) {
26
27
  logger.warn(`Attempted to read symlink: ${filePath}`);
@@ -1 +1 @@
1
- {"version":3,"file":"examples.js","names":[],"sources":["../../src/tools/examples.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { readFile, readdir, lstat } from \"node:fs/promises\";\nimport { join, extname } from \"node:path\";\nimport { CODE_EXAMPLES_PATH, MAX_FILE_SIZE } from \"../constants.js\";\nimport { cacheListing } from \"../utils/cache.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { sanitizePath } from \"../utils/security.js\";\n\nconst examplesInputSchema = z.object({\n example: z\n .string()\n .optional()\n .describe(\n 'Example name (e.g., \"with-ai-sdk-v7\"). Leave empty to list all examples.',\n ),\n});\n\nconst loadCodeExamples = cacheListing(scanCodeExamples);\n\nexport function listCodeExamples(): Promise<string[]> {\n return loadCodeExamples().catch((error) => {\n logger.error(\"Failed to list code examples\", error);\n return [];\n });\n}\n\nasync function scanCodeExamples(): Promise<string[]> {\n const files = await readdir(CODE_EXAMPLES_PATH);\n return files\n .filter((file) => extname(file) === \".md\")\n .map((file) => file.replace(\".md\", \"\"))\n .sort();\n}\n\nexport async function readCodeExample(\n exampleName: string,\n): Promise<string | null> {\n try {\n const sanitized = sanitizePath(exampleName);\n const filePath = join(CODE_EXAMPLES_PATH, `${sanitized}.md`);\n\n const stats = await lstat(filePath);\n if (stats.isSymbolicLink()) {\n logger.warn(`Attempted to read symlink: ${filePath}`);\n return null;\n }\n\n if (stats.size > MAX_FILE_SIZE) {\n logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);\n return null;\n }\n\n const content = await readFile(filePath, \"utf-8\");\n return content;\n } catch (error) {\n logger.error(`Failed to read example: ${exampleName}`, error);\n return null;\n }\n}\n\nexport const examplesTools = {\n name: \"assistantUIExamples\",\n description:\n \"List available examples or retrieve complete code for a specific example\",\n parameters: examplesInputSchema,\n execute: async ({ example }: z.infer<typeof examplesInputSchema>) => {\n try {\n if (!example) {\n logger.info(\"Listing all available examples\");\n const examples = await listCodeExamples();\n\n if (examples.length === 0) {\n return formatMCPResponse({\n error:\n \"No examples found. Please run documentation preparation first.\",\n hint: \"Run: pnpm prepare-docs\",\n });\n }\n\n return formatMCPResponse({\n type: \"list\",\n examples,\n total: examples.length,\n hint: \"Use example parameter to get complete code for any example\",\n });\n }\n\n logger.info(`Retrieving example: ${example}`);\n const content = await readCodeExample(example);\n\n if (!content) {\n const availableExamples = await listCodeExamples();\n return formatMCPResponse({\n error: `Example not found: ${example}`,\n availableExamples,\n hint: \"Use without example parameter to list all available examples\",\n });\n }\n\n return formatMCPResponse({\n type: \"example\",\n name: example,\n content,\n });\n } catch (error) {\n logger.error(\"Failed to retrieve examples\", error);\n return formatMCPResponse({\n error: \"Failed to retrieve examples\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;;;;AASA,MAAM,sBAAsB,EAAE,OAAO,EACnC,SAAS,EACN,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,4EACF,EACJ,CAAC;AAED,MAAM,mBAAmB,aAAa,gBAAgB;AAEtD,SAAgB,mBAAsC;CACpD,OAAO,iBAAiB,CAAC,CAAC,OAAO,UAAU;EACzC,OAAO,MAAM,gCAAgC,KAAK;EAClD,OAAO,CAAC;CACV,CAAC;AACH;AAEA,eAAe,mBAAsC;CAEnD,QAAO,MADa,QAAQ,kBAAkB,EAAA,CAE3C,QAAQ,SAAS,QAAQ,IAAI,MAAM,KAAK,CAAC,CACzC,KAAK,SAAS,KAAK,QAAQ,OAAO,EAAE,CAAC,CAAC,CACtC,KAAK;AACV;AAEA,eAAsB,gBACpB,aACwB;CACxB,IAAI;EAEF,MAAM,WAAW,KAAK,oBAAoB,GADxB,aAAa,WACsB,EAAE,IAAI;EAE3D,MAAM,QAAQ,MAAM,MAAM,QAAQ;EAClC,IAAI,MAAM,eAAe,GAAG;GAC1B,OAAO,KAAK,8BAA8B,UAAU;GACpD,OAAO;EACT;EAEA,IAAI,MAAM,OAAA,UAAsB;GAC9B,OAAO,KAAK,4BAA4B,SAAS,IAAI,MAAM,KAAK,QAAQ;GACxE,OAAO;EACT;EAGA,OAAO,MADe,SAAS,UAAU,OAAO;CAElD,SAAS,OAAO;EACd,OAAO,MAAM,2BAA2B,eAAe,KAAK;EAC5D,OAAO;CACT;AACF;AAEA,MAAa,gBAAgB;CAC3B,MAAM;CACN,aACE;CACF,YAAY;CACZ,SAAS,OAAO,EAAE,cAAmD;EACnE,IAAI;GACF,IAAI,CAAC,SAAS;IACZ,OAAO,KAAK,gCAAgC;IAC5C,MAAM,WAAW,MAAM,iBAAiB;IAExC,IAAI,SAAS,WAAW,GACtB,OAAO,kBAAkB;KACvB,OACE;KACF,MAAM;IACR,CAAC;IAGH,OAAO,kBAAkB;KACvB,MAAM;KACN;KACA,OAAO,SAAS;KAChB,MAAM;IACR,CAAC;GACH;GAEA,OAAO,KAAK,uBAAuB,SAAS;GAC5C,MAAM,UAAU,MAAM,gBAAgB,OAAO;GAE7C,IAAI,CAAC,SAAS;IACZ,MAAM,oBAAoB,MAAM,iBAAiB;IACjD,OAAO,kBAAkB;KACvB,OAAO,sBAAsB;KAC7B;KACA,MAAM;IACR,CAAC;GACH;GAEA,OAAO,kBAAkB;IACvB,MAAM;IACN,MAAM;IACN;GACF,CAAC;EACH,SAAS,OAAO;GACd,OAAO,MAAM,+BAA+B,KAAK;GACjD,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"examples.js","names":[],"sources":["../../src/tools/examples.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { readFile, readdir, lstat } from \"node:fs/promises\";\nimport { join, extname } from \"node:path\";\nimport { CODE_EXAMPLES_PATH, MAX_FILE_SIZE } from \"../constants.js\";\nimport { cacheListing } from \"../utils/cache.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { sanitizePath } from \"../utils/security.js\";\n\nconst examplesInputSchema = z.object({\n example: z\n .string()\n .optional()\n .describe(\n 'Example name (e.g., \"with-ai-sdk-v7\"). Leave empty to list all examples.',\n ),\n});\n\nconst loadCodeExamples = cacheListing(scanCodeExamples);\n\nexport function listCodeExamples(): Promise<string[]> {\n return loadCodeExamples().catch((error) => {\n logger.error(\"Failed to list code examples\", error);\n return [];\n });\n}\n\nasync function scanCodeExamples(): Promise<string[]> {\n const files = await readdir(CODE_EXAMPLES_PATH);\n return files\n .filter((file) => extname(file) === \".md\")\n .map((file) => file.replace(\".md\", \"\"))\n .sort();\n}\n\nexport async function readCodeExample(\n exampleName: string,\n): Promise<string | null> {\n try {\n const sanitized = sanitizePath(exampleName);\n const filePath = join(CODE_EXAMPLES_PATH, `${sanitized}.md`);\n\n const stats = await lstat(filePath);\n if (stats.isSymbolicLink()) {\n logger.warn(`Attempted to read symlink: ${filePath}`);\n return null;\n }\n\n if (stats.size > MAX_FILE_SIZE) {\n logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);\n return null;\n }\n\n const content = await readFile(filePath, \"utf-8\");\n return content;\n } catch (error) {\n logger.error(`Failed to read example: ${exampleName}`, error);\n return null;\n }\n}\n\nexport const examplesTools = {\n name: \"assistantUIExamples\",\n description:\n \"List available examples or retrieve complete code for a specific example\",\n parameters: examplesInputSchema,\n execute: async ({ example }: z.infer<typeof examplesInputSchema>) => {\n try {\n if (!example) {\n logger.info(\"Listing all available examples\");\n const examples = await listCodeExamples();\n\n if (examples.length === 0) {\n return formatMCPResponse({\n error:\n \"No examples found. Please run documentation preparation first.\",\n hint: \"Run: pnpm prepare-docs\",\n });\n }\n\n return formatMCPResponse({\n type: \"list\",\n examples,\n total: examples.length,\n hint: \"Use example parameter to get complete code for any example\",\n });\n }\n\n logger.info(`Retrieving example: ${example}`);\n const content = await readCodeExample(example);\n\n if (!content) {\n const availableExamples = await listCodeExamples();\n return formatMCPResponse({\n error: `Example not found: ${example}`,\n availableExamples,\n hint: \"Use without example parameter to list all available examples\",\n });\n }\n\n return formatMCPResponse({\n type: \"example\",\n name: example,\n content,\n });\n } catch (error) {\n logger.error(\"Failed to retrieve examples\", error);\n return formatMCPResponse({\n error: \"Failed to retrieve examples\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;;;;AASA,MAAM,sBAAsB,EAAE,OAAO,EACnC,SAAS,EACN,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,4EACF,EACJ,CAAC;AAED,MAAM,mBAAmB,aAAa,gBAAgB;AAEtD,SAAgB,mBAAsC;CACpD,OAAO,iBAAiB,CAAC,CAAC,OAAO,UAAU;EACzC,OAAO,MAAM,gCAAgC,KAAK;EAClD,OAAO,CAAC;CACV,CAAC;AACH;AAEA,eAAe,mBAAsC;CAEnD,QAAO,MADa,QAAQ,kBAAkB,EAAA,CAE3C,QAAQ,SAAS,QAAQ,IAAI,MAAM,KAAK,CAAC,CACzC,KAAK,SAAS,KAAK,QAAQ,OAAO,EAAE,CAAC,CAAC,CACtC,KAAK;AACV;AAEA,eAAsB,gBACpB,aACwB;CACxB,IAAI;EACF,MAAM,YAAY,aAAa,WAAW;EAC1C,MAAM,WAAW,KAAK,oBAAoB,GAAG,UAAU,IAAI;EAE3D,MAAM,QAAQ,MAAM,MAAM,QAAQ;EAClC,IAAI,MAAM,eAAe,GAAG;GAC1B,OAAO,KAAK,8BAA8B,UAAU;GACpD,OAAO;EACT;EAEA,IAAI,MAAM,OAAA,UAAsB;GAC9B,OAAO,KAAK,4BAA4B,SAAS,IAAI,MAAM,KAAK,QAAQ;GACxE,OAAO;EACT;EAGA,OAAO,MADe,SAAS,UAAU,OAAO;CAElD,SAAS,OAAO;EACd,OAAO,MAAM,2BAA2B,eAAe,KAAK;EAC5D,OAAO;CACT;AACF;AAEA,MAAa,gBAAgB;CAC3B,MAAM;CACN,aACE;CACF,YAAY;CACZ,SAAS,OAAO,EAAE,cAAmD;EACnE,IAAI;GACF,IAAI,CAAC,SAAS;IACZ,OAAO,KAAK,gCAAgC;IAC5C,MAAM,WAAW,MAAM,iBAAiB;IAExC,IAAI,SAAS,WAAW,GACtB,OAAO,kBAAkB;KACvB,OACE;KACF,MAAM;IACR,CAAC;IAGH,OAAO,kBAAkB;KACvB,MAAM;KACN;KACA,OAAO,SAAS;KAChB,MAAM;IACR,CAAC;GACH;GAEA,OAAO,KAAK,uBAAuB,SAAS;GAC5C,MAAM,UAAU,MAAM,gBAAgB,OAAO;GAE7C,IAAI,CAAC,SAAS;IACZ,MAAM,oBAAoB,MAAM,iBAAiB;IACjD,OAAO,kBAAkB;KACvB,OAAO,sBAAsB;KAC7B;KACA,MAAM;IACR,CAAC;GACH;GAEA,OAAO,kBAAkB;IACvB,MAAM;IACN,MAAM;IACN;GACF,CAAC;EACH,SAAS,OAAO;GACd,OAAO,MAAM,+BAA+B,KAAK;GACjD,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF"}
@@ -42,7 +42,8 @@ function registerMarkdownResource(server, config) {
42
42
  });
43
43
  }
44
44
  async function readDocResource(path) {
45
- const mdx = await readMDXFileSafe(join(DOCS_PATH, `${sanitizePath(path)}${MDX_EXTENSION}`));
45
+ const sanitized = sanitizePath(path);
46
+ const mdx = await readMDXFileSafe(join(DOCS_PATH, `${sanitized}${MDX_EXTENSION}`));
46
47
  return mdx ? formatMDXContent(mdx) : null;
47
48
  }
48
49
  function registerResources(server) {
@@ -1 +1 @@
1
- {"version":3,"file":"resources.js","names":[],"sources":["../../src/tools/resources.ts"],"sourcesContent":["import { type McpServer, ResourceTemplate } from \"@modelcontextprotocol/server\";\nimport { join } from \"node:path\";\nimport { DOCS_PATH, MDX_EXTENSION } from \"../constants.js\";\nimport { getAvailableDocFiles } from \"../utils/paths.js\";\nimport { readMDXFileSafe, formatMDXContent } from \"../utils/mdx.js\";\nimport { sanitizePath } from \"../utils/security.js\";\nimport { listCodeExamples, readCodeExample } from \"./examples.js\";\nimport { logger } from \"../utils/logger.js\";\n\nconst MARKDOWN_MIME_TYPE = \"text/markdown\";\nconst DOCS_SCHEME = \"aui-docs\";\nconst EXAMPLE_SCHEME = \"aui-example\";\n\nfunction templateVarToPath(value: string | string[] | undefined): string {\n if (Array.isArray(value)) return value.join(\"/\");\n return value ?? \"\";\n}\n\ninterface MarkdownResourceConfig {\n name: string;\n scheme: string;\n variable: string;\n title: string;\n description: string;\n notFoundLabel: string;\n list: () => Promise<string[]>;\n read: (key: string) => Promise<string | null>;\n}\n\nfunction registerMarkdownResource(\n server: McpServer,\n config: MarkdownResourceConfig,\n): void {\n const {\n name,\n scheme,\n variable,\n title,\n description,\n notFoundLabel,\n list,\n read,\n } = config;\n server.registerResource(\n name,\n new ResourceTemplate(`${scheme}:///{+${variable}}`, {\n list: async () => ({\n resources: (await list()).map((key) => ({\n uri: `${scheme}:///${key}`,\n name: key,\n mimeType: MARKDOWN_MIME_TYPE,\n })),\n }),\n complete: {\n [variable]: async (value) => {\n const needle = value.toLowerCase();\n return (await list()).filter((key) =>\n key.toLowerCase().includes(needle),\n );\n },\n },\n }),\n { title, description, mimeType: MARKDOWN_MIME_TYPE },\n async (uri, variables) => {\n const key = templateVarToPath(variables[variable]);\n const text = await read(key);\n if (text === null) {\n throw new Error(`${notFoundLabel} not found: ${key}`);\n }\n return {\n contents: [{ uri: uri.href, mimeType: MARKDOWN_MIME_TYPE, text }],\n };\n },\n );\n}\n\nasync function readDocResource(path: string): Promise<string | null> {\n const sanitized = sanitizePath(path);\n const mdx = await readMDXFileSafe(\n join(DOCS_PATH, `${sanitized}${MDX_EXTENSION}`),\n );\n return mdx ? formatMDXContent(mdx) : null;\n}\n\nexport function registerResources(server: McpServer): void {\n registerMarkdownResource(server, {\n name: \"assistant-ui-docs\",\n scheme: DOCS_SCHEME,\n variable: \"path\",\n title: \"assistant-ui Documentation\",\n description:\n \"Individual assistant-ui documentation pages, readable as markdown by path.\",\n notFoundLabel: \"Documentation\",\n list: getAvailableDocFiles,\n read: readDocResource,\n });\n\n registerMarkdownResource(server, {\n name: \"assistant-ui-examples\",\n scheme: EXAMPLE_SCHEME,\n variable: \"name\",\n title: \"assistant-ui Examples\",\n description:\n \"Complete assistant-ui example projects, readable as markdown.\",\n notFoundLabel: \"Example\",\n list: listCodeExamples,\n read: readCodeExample,\n });\n\n logger.debug(\"Registered docs and examples resources\");\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,qBAAqB;AAC3B,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAEvB,SAAS,kBAAkB,OAA8C;CACvE,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,KAAK,GAAG;CAC/C,OAAO,SAAS;AAClB;AAaA,SAAS,yBACP,QACA,QACM;CACN,MAAM,EACJ,MACA,QACA,UACA,OACA,aACA,eACA,MACA,SACE;CACJ,OAAO,iBACL,MACA,IAAI,iBAAiB,GAAG,OAAO,QAAQ,SAAS,IAAI;EAClD,MAAM,aAAa,EACjB,YAAY,MAAM,KAAK,EAAA,CAAG,KAAK,SAAS;GACtC,KAAK,GAAG,OAAO,MAAM;GACrB,MAAM;GACN,UAAU;EACZ,EAAE,EACJ;EACA,UAAU,GACP,WAAW,OAAO,UAAU;GAC3B,MAAM,SAAS,MAAM,YAAY;GACjC,QAAQ,MAAM,KAAK,EAAA,CAAG,QAAQ,QAC5B,IAAI,YAAY,CAAC,CAAC,SAAS,MAAM,CACnC;EACF,EACF;CACF,CAAC,GACD;EAAE;EAAO;EAAa,UAAU;CAAmB,GACnD,OAAO,KAAK,cAAc;EACxB,MAAM,MAAM,kBAAkB,UAAU,SAAS;EACjD,MAAM,OAAO,MAAM,KAAK,GAAG;EAC3B,IAAI,SAAS,MACX,MAAM,IAAI,MAAM,GAAG,cAAc,cAAc,KAAK;EAEtD,OAAO,EACL,UAAU,CAAC;GAAE,KAAK,IAAI;GAAM,UAAU;GAAoB;EAAK,CAAC,EAClE;CACF,CACF;AACF;AAEA,eAAe,gBAAgB,MAAsC;CAEnE,MAAM,MAAM,MAAM,gBAChB,KAAK,WAAW,GAFA,aAAa,IAEF,IAAI,eAAe,CAChD;CACA,OAAO,MAAM,iBAAiB,GAAG,IAAI;AACvC;AAEA,SAAgB,kBAAkB,QAAyB;CACzD,yBAAyB,QAAQ;EAC/B,MAAM;EACN,QAAQ;EACR,UAAU;EACV,OAAO;EACP,aACE;EACF,eAAe;EACf,MAAM;EACN,MAAM;CACR,CAAC;CAED,yBAAyB,QAAQ;EAC/B,MAAM;EACN,QAAQ;EACR,UAAU;EACV,OAAO;EACP,aACE;EACF,eAAe;EACf,MAAM;EACN,MAAM;CACR,CAAC;CAED,OAAO,MAAM,wCAAwC;AACvD"}
1
+ {"version":3,"file":"resources.js","names":[],"sources":["../../src/tools/resources.ts"],"sourcesContent":["import { type McpServer, ResourceTemplate } from \"@modelcontextprotocol/server\";\nimport { join } from \"node:path\";\nimport { DOCS_PATH, MDX_EXTENSION } from \"../constants.js\";\nimport { getAvailableDocFiles } from \"../utils/paths.js\";\nimport { readMDXFileSafe, formatMDXContent } from \"../utils/mdx.js\";\nimport { sanitizePath } from \"../utils/security.js\";\nimport { listCodeExamples, readCodeExample } from \"./examples.js\";\nimport { logger } from \"../utils/logger.js\";\n\nconst MARKDOWN_MIME_TYPE = \"text/markdown\";\nconst DOCS_SCHEME = \"aui-docs\";\nconst EXAMPLE_SCHEME = \"aui-example\";\n\nfunction templateVarToPath(value: string | string[] | undefined): string {\n if (Array.isArray(value)) return value.join(\"/\");\n return value ?? \"\";\n}\n\ninterface MarkdownResourceConfig {\n name: string;\n scheme: string;\n variable: string;\n title: string;\n description: string;\n notFoundLabel: string;\n list: () => Promise<string[]>;\n read: (key: string) => Promise<string | null>;\n}\n\nfunction registerMarkdownResource(\n server: McpServer,\n config: MarkdownResourceConfig,\n): void {\n const {\n name,\n scheme,\n variable,\n title,\n description,\n notFoundLabel,\n list,\n read,\n } = config;\n server.registerResource(\n name,\n new ResourceTemplate(`${scheme}:///{+${variable}}`, {\n list: async () => ({\n resources: (await list()).map((key) => ({\n uri: `${scheme}:///${key}`,\n name: key,\n mimeType: MARKDOWN_MIME_TYPE,\n })),\n }),\n complete: {\n [variable]: async (value) => {\n const needle = value.toLowerCase();\n return (await list()).filter((key) =>\n key.toLowerCase().includes(needle),\n );\n },\n },\n }),\n { title, description, mimeType: MARKDOWN_MIME_TYPE },\n async (uri, variables) => {\n const key = templateVarToPath(variables[variable]);\n const text = await read(key);\n if (text === null) {\n throw new Error(`${notFoundLabel} not found: ${key}`);\n }\n return {\n contents: [{ uri: uri.href, mimeType: MARKDOWN_MIME_TYPE, text }],\n };\n },\n );\n}\n\nasync function readDocResource(path: string): Promise<string | null> {\n const sanitized = sanitizePath(path);\n const mdx = await readMDXFileSafe(\n join(DOCS_PATH, `${sanitized}${MDX_EXTENSION}`),\n );\n return mdx ? formatMDXContent(mdx) : null;\n}\n\nexport function registerResources(server: McpServer): void {\n registerMarkdownResource(server, {\n name: \"assistant-ui-docs\",\n scheme: DOCS_SCHEME,\n variable: \"path\",\n title: \"assistant-ui Documentation\",\n description:\n \"Individual assistant-ui documentation pages, readable as markdown by path.\",\n notFoundLabel: \"Documentation\",\n list: getAvailableDocFiles,\n read: readDocResource,\n });\n\n registerMarkdownResource(server, {\n name: \"assistant-ui-examples\",\n scheme: EXAMPLE_SCHEME,\n variable: \"name\",\n title: \"assistant-ui Examples\",\n description:\n \"Complete assistant-ui example projects, readable as markdown.\",\n notFoundLabel: \"Example\",\n list: listCodeExamples,\n read: readCodeExample,\n });\n\n logger.debug(\"Registered docs and examples resources\");\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,qBAAqB;AAC3B,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAEvB,SAAS,kBAAkB,OAA8C;CACvE,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,KAAK,GAAG;CAC/C,OAAO,SAAS;AAClB;AAaA,SAAS,yBACP,QACA,QACM;CACN,MAAM,EACJ,MACA,QACA,UACA,OACA,aACA,eACA,MACA,SACE;CACJ,OAAO,iBACL,MACA,IAAI,iBAAiB,GAAG,OAAO,QAAQ,SAAS,IAAI;EAClD,MAAM,aAAa,EACjB,YAAY,MAAM,KAAK,EAAA,CAAG,KAAK,SAAS;GACtC,KAAK,GAAG,OAAO,MAAM;GACrB,MAAM;GACN,UAAU;EACZ,EAAE,EACJ;EACA,UAAU,GACP,WAAW,OAAO,UAAU;GAC3B,MAAM,SAAS,MAAM,YAAY;GACjC,QAAQ,MAAM,KAAK,EAAA,CAAG,QAAQ,QAC5B,IAAI,YAAY,CAAC,CAAC,SAAS,MAAM,CACnC;EACF,EACF;CACF,CAAC,GACD;EAAE;EAAO;EAAa,UAAU;CAAmB,GACnD,OAAO,KAAK,cAAc;EACxB,MAAM,MAAM,kBAAkB,UAAU,SAAS;EACjD,MAAM,OAAO,MAAM,KAAK,GAAG;EAC3B,IAAI,SAAS,MACX,MAAM,IAAI,MAAM,GAAG,cAAc,cAAc,KAAK;EAEtD,OAAO,EACL,UAAU,CAAC;GAAE,KAAK,IAAI;GAAM,UAAU;GAAoB;EAAK,CAAC,EAClE;CACF,CACF;AACF;AAEA,eAAe,gBAAgB,MAAsC;CACnE,MAAM,YAAY,aAAa,IAAI;CACnC,MAAM,MAAM,MAAM,gBAChB,KAAK,WAAW,GAAG,YAAY,eAAe,CAChD;CACA,OAAO,MAAM,iBAAiB,GAAG,IAAI;AACvC;AAEA,SAAgB,kBAAkB,QAAyB;CACzD,yBAAyB,QAAQ;EAC/B,MAAM;EACN,QAAQ;EACR,UAAU;EACV,OAAO;EACP,aACE;EACF,eAAe;EACf,MAAM;EACN,MAAM;CACR,CAAC;CAED,yBAAyB,QAAQ;EAC/B,MAAM;EACN,QAAQ;EACR,UAAU;EACV,OAAO;EACP,aACE;EACF,eAAe;EACf,MAAM;EACN,MAAM;CACR,CAAC;CAED,OAAO,MAAM,wCAAwC;AACvD"}
@@ -27,7 +27,8 @@ const testContext = { callTool: async (name, args) => {
27
27
  }
28
28
  } };
29
29
  beforeAll(() => {
30
- if (!existsSync(join(PACKAGE_DIR, ".docs"))) throw new Error("Documentation not prepared. Run: pnpm build");
30
+ const docsPath = join(PACKAGE_DIR, ".docs");
31
+ if (!existsSync(docsPath)) throw new Error("Documentation not prepared. Run: pnpm build");
31
32
  });
32
33
  //#endregion
33
34
  export { testContext };
@@ -1 +1 @@
1
- {"version":3,"file":"test-setup.js","names":[],"sources":["../../../src/tools/tests/test-setup.ts"],"sourcesContent":["import { beforeAll } from \"vitest\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { PACKAGE_DIR } from \"../../constants.js\";\nimport { docsTools } from \"../docs.js\";\nimport { examplesTools } from \"../examples.js\";\nimport { searchTools } from \"../search.js\";\nimport {\n xuluxTemplatesListTool,\n xuluxTemplateDetailsTool,\n xuluxTemplatePreviewTool,\n} from \"../xulux-templates.js\";\n\nconst tools = {\n assistantUIDocs: docsTools,\n assistantUIExamples: examplesTools,\n assistantUISearch: searchTools,\n assistantUITemplates: xuluxTemplatesListTool,\n assistantUITemplateDetails: xuluxTemplateDetailsTool,\n assistantUITemplatePreview: xuluxTemplatePreviewTool,\n};\n\nexport const testContext = {\n callTool: async (name: string, args: any) => {\n const tool = tools[name as keyof typeof tools];\n if (!tool) {\n throw new Error(`Tool ${name} not found`);\n }\n const result = await tool.execute(args);\n\n const text = result.content?.[0]?.text;\n if (text === undefined) {\n throw new Error(`Tool ${name} returned no content`);\n }\n try {\n return JSON.parse(text);\n } catch (error) {\n throw new Error(\n `Tool ${name} returned invalid JSON. Output: ${text}\\nParse error: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n};\n\nbeforeAll(() => {\n const docsPath = join(PACKAGE_DIR, \".docs\");\n if (!existsSync(docsPath)) {\n throw new Error(\"Documentation not prepared. Run: pnpm build\");\n }\n});\n"],"mappings":";;;;;;;;;AAaA,MAAM,QAAQ;CACZ,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,sBAAsB;CACtB,4BAA4B;CAC5B,4BAA4B;AAC9B;AAEA,MAAa,cAAc,EACzB,UAAU,OAAO,MAAc,SAAc;CAC3C,MAAM,OAAO,MAAM;CACnB,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,QAAQ,KAAK,WAAW;CAI1C,MAAM,QAAO,MAFQ,KAAK,QAAQ,IAAI,EAAA,CAElB,UAAU,EAAE,EAAE;CAClC,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MAAM,QAAQ,KAAK,qBAAqB;CAEpD,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;CACxB,SAAS,OAAO;EACd,MAAM,IAAI,MACR,QAAQ,KAAK,kCAAkC,KAAK,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC5H;CACF;AACF,EACF;AAEA,gBAAgB;CAEd,IAAI,CAAC,WADY,KAAK,aAAa,OACZ,CAAC,GACtB,MAAM,IAAI,MAAM,6CAA6C;AAEjE,CAAC"}
1
+ {"version":3,"file":"test-setup.js","names":[],"sources":["../../../src/tools/tests/test-setup.ts"],"sourcesContent":["import { beforeAll } from \"vitest\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { PACKAGE_DIR } from \"../../constants.js\";\nimport { docsTools } from \"../docs.js\";\nimport { examplesTools } from \"../examples.js\";\nimport { searchTools } from \"../search.js\";\nimport {\n xuluxTemplatesListTool,\n xuluxTemplateDetailsTool,\n xuluxTemplatePreviewTool,\n} from \"../xulux-templates.js\";\n\nconst tools = {\n assistantUIDocs: docsTools,\n assistantUIExamples: examplesTools,\n assistantUISearch: searchTools,\n assistantUITemplates: xuluxTemplatesListTool,\n assistantUITemplateDetails: xuluxTemplateDetailsTool,\n assistantUITemplatePreview: xuluxTemplatePreviewTool,\n};\n\nexport const testContext = {\n callTool: async (name: string, args: any) => {\n const tool = tools[name as keyof typeof tools];\n if (!tool) {\n throw new Error(`Tool ${name} not found`);\n }\n const result = await tool.execute(args);\n\n const text = result.content?.[0]?.text;\n if (text === undefined) {\n throw new Error(`Tool ${name} returned no content`);\n }\n try {\n return JSON.parse(text);\n } catch (error) {\n throw new Error(\n `Tool ${name} returned invalid JSON. Output: ${text}\\nParse error: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n};\n\nbeforeAll(() => {\n const docsPath = join(PACKAGE_DIR, \".docs\");\n if (!existsSync(docsPath)) {\n throw new Error(\"Documentation not prepared. Run: pnpm build\");\n }\n});\n"],"mappings":";;;;;;;;;AAaA,MAAM,QAAQ;CACZ,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,sBAAsB;CACtB,4BAA4B;CAC5B,4BAA4B;AAC9B;AAEA,MAAa,cAAc,EACzB,UAAU,OAAO,MAAc,SAAc;CAC3C,MAAM,OAAO,MAAM;CACnB,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,QAAQ,KAAK,WAAW;CAI1C,MAAM,QAAO,MAFQ,KAAK,QAAQ,IAAI,EAAA,CAElB,UAAU,EAAE,EAAE;CAClC,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MAAM,QAAQ,KAAK,qBAAqB;CAEpD,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;CACxB,SAAS,OAAO;EACd,MAAM,IAAI,MACR,QAAQ,KAAK,kCAAkC,KAAK,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC5H;CACF;AACF,EACF;AAEA,gBAAgB;CACd,MAAM,WAAW,KAAK,aAAa,OAAO;CAC1C,IAAI,CAAC,WAAW,QAAQ,GACtB,MAAM,IAAI,MAAM,6CAA6C;AAEjE,CAAC"}
@@ -48,7 +48,8 @@ const xuluxTemplateDetailsTool = {
48
48
  logger.info(`Getting assistant-ui template details for: ${args.templateId}`);
49
49
  try {
50
50
  const { catalog, degraded, degradedReason } = await getXuluxCatalog();
51
- return formatMCPResponse(withDegradedNote(await getTemplateDetails(catalog, args), degraded, degradedReason));
51
+ const details = await getTemplateDetails(catalog, args);
52
+ return formatMCPResponse(withDegradedNote(details, degraded, degradedReason));
52
53
  } catch (error) {
53
54
  logger.error("Failed to get assistant-ui template details", error);
54
55
  return formatMCPResponse({
@@ -66,7 +67,8 @@ const xuluxTemplatePreviewTool = {
66
67
  logger.info(`Creating assistant-ui template preview for: ${args.templateId}`);
67
68
  try {
68
69
  const { catalog, degraded, degradedReason } = await getXuluxCatalog();
69
- return formatMCPResponse(withDegradedNote(await createTemplatePreview(catalog, args), degraded, degradedReason));
70
+ const result = await createTemplatePreview(catalog, args);
71
+ return formatMCPResponse(withDegradedNote(result, degraded, degradedReason));
70
72
  } catch (error) {
71
73
  logger.error("Failed to create assistant-ui template preview", error);
72
74
  return formatMCPResponse({
@@ -1 +1 @@
1
- {"version":3,"file":"xulux-templates.js","names":[],"sources":["../../src/tools/xulux-templates.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { logger } from \"../utils/logger.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { getXuluxCatalog } from \"../xulux/catalog-client.js\";\nimport {\n createTemplatePreview,\n getTemplateDetails,\n listTemplates,\n} from \"../xulux/template-service.js\";\n\nconst emptyInputSchema = z.object({});\n\nconst detailsInputSchema = z.object({\n templateId: z.string().describe(\"The template id from assistantUITemplates\"),\n versionId: z\n .string()\n .optional()\n .describe(\n \"Optional version id. When provided, exampleConfig reflects that version's resolved defaults.\",\n ),\n});\n\nconst previewInputSchema = z.object({\n templateId: z.string().describe(\"The template id from assistantUITemplates\"),\n versionId: z\n .string()\n .optional()\n .describe(\"Version id to use. Uses the template default if omitted.\"),\n config: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Customization config for the preview. Must contain only the top-level keys: hostUi, assistant, and brandTheme. \" +\n \"Use the schemas from assistantUITemplateDetails.configRoots as the source of truth for each root. \" +\n \"Do not pass any other root keys.\",\n ),\n});\n\nfunction withDegradedNote<T extends Record<string, unknown>>(\n payload: T,\n degraded: boolean,\n degradedReason?: string,\n): T & { catalogDegraded?: true; catalogDegradedReason?: string } {\n if (!degraded) return payload;\n return {\n ...payload,\n catalogDegraded: true,\n ...(degradedReason ? { catalogDegradedReason: degradedReason } : {}),\n };\n}\n\nexport const xuluxTemplatesListTool = {\n name: \"assistantUITemplates\",\n description:\n \"List the available assistant-ui hosted app templates and fixed demos with their features, customizable surfaces, and versions. \" +\n \"Call this first for any assistant-ui app-building request. Use the features and customizable fields to decide which template fits. \" +\n \"If customizable is empty, the entry is a fixed demo that should be used as-is rather than configured. \" +\n \"Call assistantUITemplateDetails on the chosen template before requesting a preview.\",\n parameters: emptyInputSchema,\n execute: async (_args: z.infer<typeof emptyInputSchema>) => {\n logger.info(\"Listing assistant-ui templates\");\n try {\n const { catalog, degraded, degradedReason } = await getXuluxCatalog();\n return formatMCPResponse(\n withDegradedNote(listTemplates(catalog), degraded, degradedReason),\n );\n } catch (error) {\n logger.error(\"Failed to list assistant-ui templates\", error);\n return formatMCPResponse({\n error: \"Failed to list assistant-ui templates\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n\nexport const xuluxTemplateDetailsTool = {\n name: \"assistantUITemplateDetails\",\n description:\n \"Get the full authoring surface for a specific assistant-ui hosted template. \" +\n \"Returns configRoots schemas (with types, defaults, and enums), rules, built-in tool input/outputShape, renderer contracts, and an exampleConfig. \" +\n \"Fixed demos return no configRoots; use those as-is without config. \" +\n \"Use this before calling assistantUITemplatePreview to understand exactly what config to write. \" +\n \"If assistantUITemplatePreview returns validationWarnings, call this again and cross-reference configRoots to correct the config.\",\n parameters: detailsInputSchema,\n execute: async (args: z.infer<typeof detailsInputSchema>) => {\n logger.info(\n `Getting assistant-ui template details for: ${args.templateId}`,\n );\n try {\n const { catalog, degraded, degradedReason } = await getXuluxCatalog();\n const details = await getTemplateDetails(catalog, args);\n return formatMCPResponse(\n withDegradedNote(\n details as unknown as Record<string, unknown>,\n degraded,\n degradedReason,\n ),\n );\n } catch (error) {\n logger.error(\"Failed to get assistant-ui template details\", error);\n return formatMCPResponse({\n error: \"Failed to get assistant-ui template details\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n\nexport const xuluxTemplatePreviewTool = {\n name: \"assistantUITemplatePreview\",\n description:\n \"Return preview and download URLs for a selected assistant-ui hosted template. \" +\n \"The previewUrl is a hosted app URL; show it to the user first, or open it with an available browser/in-app-browser tool if your client provides one. \" +\n \"If you pass config, a preview session is created on the hosted template sandbox and the returned URLs reflect that configuration. \" +\n \"Do not pass config for fixed demos that have no configRoots in assistantUITemplateDetails. \" +\n \"This tool only returns URLs.\",\n parameters: previewInputSchema,\n execute: async (args: z.infer<typeof previewInputSchema>) => {\n logger.info(\n `Creating assistant-ui template preview for: ${args.templateId}`,\n );\n try {\n const { catalog, degraded, degradedReason } = await getXuluxCatalog();\n const result = await createTemplatePreview(catalog, args);\n return formatMCPResponse(\n withDegradedNote(\n result as unknown as Record<string, unknown>,\n degraded,\n degradedReason,\n ),\n );\n } catch (error) {\n logger.error(\"Failed to create assistant-ui template preview\", error);\n return formatMCPResponse({\n error: \"Failed to create assistant-ui template preview\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;AAUA,MAAM,mBAAmB,EAAE,OAAO,CAAC,CAAC;AAEpC,MAAM,qBAAqB,EAAE,OAAO;CAClC,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,2CAA2C;CAC3E,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,8FACF;AACJ,CAAC;AAED,MAAM,qBAAqB,EAAE,OAAO;CAClC,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,2CAA2C;CAC3E,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,0DAA0D;CACtE,QAAQ,EACL,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAC/B,SAAS,CAAC,CACV,SACC,mPAGF;AACJ,CAAC;AAED,SAAS,iBACP,SACA,UACA,gBACgE;CAChE,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO;EACL,GAAG;EACH,iBAAiB;EACjB,GAAI,iBAAiB,EAAE,uBAA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AAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"xulux-templates.js","names":[],"sources":["../../src/tools/xulux-templates.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { logger } from \"../utils/logger.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { getXuluxCatalog } from \"../xulux/catalog-client.js\";\nimport {\n createTemplatePreview,\n getTemplateDetails,\n listTemplates,\n} from \"../xulux/template-service.js\";\n\nconst emptyInputSchema = z.object({});\n\nconst detailsInputSchema = z.object({\n templateId: z.string().describe(\"The template id from assistantUITemplates\"),\n versionId: z\n .string()\n .optional()\n .describe(\n \"Optional version id. When provided, exampleConfig reflects that version's resolved defaults.\",\n ),\n});\n\nconst previewInputSchema = z.object({\n templateId: z.string().describe(\"The template id from assistantUITemplates\"),\n versionId: z\n .string()\n .optional()\n .describe(\"Version id to use. Uses the template default if omitted.\"),\n config: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Customization config for the preview. Must contain only the top-level keys: hostUi, assistant, and brandTheme. \" +\n \"Use the schemas from assistantUITemplateDetails.configRoots as the source of truth for each root. \" +\n \"Do not pass any other root keys.\",\n ),\n});\n\nfunction withDegradedNote<T extends Record<string, unknown>>(\n payload: T,\n degraded: boolean,\n degradedReason?: string,\n): T & { catalogDegraded?: true; catalogDegradedReason?: string } {\n if (!degraded) return payload;\n return {\n ...payload,\n catalogDegraded: true,\n ...(degradedReason ? { catalogDegradedReason: degradedReason } : {}),\n };\n}\n\nexport const xuluxTemplatesListTool = {\n name: \"assistantUITemplates\",\n description:\n \"List the available assistant-ui hosted app templates and fixed demos with their features, customizable surfaces, and versions. \" +\n \"Call this first for any assistant-ui app-building request. Use the features and customizable fields to decide which template fits. \" +\n \"If customizable is empty, the entry is a fixed demo that should be used as-is rather than configured. \" +\n \"Call assistantUITemplateDetails on the chosen template before requesting a preview.\",\n parameters: emptyInputSchema,\n execute: async (_args: z.infer<typeof emptyInputSchema>) => {\n logger.info(\"Listing assistant-ui templates\");\n try {\n const { catalog, degraded, degradedReason } = await getXuluxCatalog();\n return formatMCPResponse(\n withDegradedNote(listTemplates(catalog), degraded, degradedReason),\n );\n } catch (error) {\n logger.error(\"Failed to list assistant-ui templates\", error);\n return formatMCPResponse({\n error: \"Failed to list assistant-ui templates\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n\nexport const xuluxTemplateDetailsTool = {\n name: \"assistantUITemplateDetails\",\n description:\n \"Get the full authoring surface for a specific assistant-ui hosted template. \" +\n \"Returns configRoots schemas (with types, defaults, and enums), rules, built-in tool input/outputShape, renderer contracts, and an exampleConfig. \" +\n \"Fixed demos return no configRoots; use those as-is without config. \" +\n \"Use this before calling assistantUITemplatePreview to understand exactly what config to write. \" +\n \"If assistantUITemplatePreview returns validationWarnings, call this again and cross-reference configRoots to correct the config.\",\n parameters: detailsInputSchema,\n execute: async (args: z.infer<typeof detailsInputSchema>) => {\n logger.info(\n `Getting assistant-ui template details for: ${args.templateId}`,\n );\n try {\n const { catalog, degraded, degradedReason } = await getXuluxCatalog();\n const details = await getTemplateDetails(catalog, args);\n return formatMCPResponse(\n withDegradedNote(\n details as unknown as Record<string, unknown>,\n degraded,\n degradedReason,\n ),\n );\n } catch (error) {\n logger.error(\"Failed to get assistant-ui template details\", error);\n return formatMCPResponse({\n error: \"Failed to get assistant-ui template details\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n\nexport const xuluxTemplatePreviewTool = {\n name: \"assistantUITemplatePreview\",\n description:\n \"Return preview and download URLs for a selected assistant-ui hosted template. \" +\n \"The previewUrl is a hosted app URL; show it to the user first, or open it with an available browser/in-app-browser tool if your client provides one. \" +\n \"If you pass config, a preview session is created on the hosted template sandbox and the returned URLs reflect that configuration. \" +\n \"Do not pass config for fixed demos that have no configRoots in assistantUITemplateDetails. \" +\n \"This tool only returns URLs.\",\n parameters: previewInputSchema,\n execute: async (args: z.infer<typeof previewInputSchema>) => {\n logger.info(\n `Creating assistant-ui template preview for: ${args.templateId}`,\n );\n try {\n const { catalog, degraded, degradedReason } = await getXuluxCatalog();\n const result = await createTemplatePreview(catalog, args);\n return formatMCPResponse(\n withDegradedNote(\n result as unknown as Record<string, unknown>,\n degraded,\n degradedReason,\n ),\n );\n } catch (error) {\n logger.error(\"Failed to create assistant-ui template preview\", error);\n return formatMCPResponse({\n error: \"Failed to create assistant-ui template preview\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;AAUA,MAAM,mBAAmB,EAAE,OAAO,CAAC,CAAC;AAEpC,MAAM,qBAAqB,EAAE,OAAO;CAClC,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,2CAA2C;CAC3E,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,8FACF;AACJ,CAAC;AAED,MAAM,qBAAqB,EAAE,OAAO;CAClC,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,2CAA2C;CAC3E,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,0DAA0D;CACtE,QAAQ,EACL,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAC/B,SAAS,CAAC,CACV,SACC,mPAGF;AACJ,CAAC;AAED,SAAS,iBACP,SACA,UACA,gBACgE;CAChE,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO;EACL,GAAG;EACH,iBAAiB;EACjB,GAAI,iBAAiB,EAAE,uBAAuB,eAAe,IAAI,CAAC;CACpE;AACF;AAEA,MAAa,yBAAyB;CACpC,MAAM;CACN,aACE;CAIF,YAAY;CACZ,SAAS,OAAO,UAA4C;EAC1D,OAAO,KAAK,gCAAgC;EAC5C,IAAI;GACF,MAAM,EAAE,SAAS,UAAU,mBAAmB,MAAM,gBAAgB;GACpE,OAAO,kBACL,iBAAiB,cAAc,OAAO,GAAG,UAAU,cAAc,CACnE;EACF,SAAS,OAAO;GACd,OAAO,MAAM,yCAAyC,KAAK;GAC3D,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF;AAEA,MAAa,2BAA2B;CACtC,MAAM;CACN,aACE;CAKF,YAAY;CACZ,SAAS,OAAO,SAA6C;EAC3D,OAAO,KACL,8CAA8C,KAAK,YACrD;EACA,IAAI;GACF,MAAM,EAAE,SAAS,UAAU,mBAAmB,MAAM,gBAAgB;GACpE,MAAM,UAAU,MAAM,mBAAmB,SAAS,IAAI;GACtD,OAAO,kBACL,iBACE,SACA,UACA,cACF,CACF;EACF,SAAS,OAAO;GACd,OAAO,MAAM,+CAA+C,KAAK;GACjE,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF;AAEA,MAAa,2BAA2B;CACtC,MAAM;CACN,aACE;CAKF,YAAY;CACZ,SAAS,OAAO,SAA6C;EAC3D,OAAO,KACL,+CAA+C,KAAK,YACtD;EACA,IAAI;GACF,MAAM,EAAE,SAAS,UAAU,mBAAmB,MAAM,gBAAgB;GACpE,MAAM,SAAS,MAAM,sBAAsB,SAAS,IAAI;GACxD,OAAO,kBACL,iBACE,QACA,UACA,cACF,CACF;EACF,SAAS,OAAO;GACd,OAAO,MAAM,kDAAkD,KAAK;GACpE,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF"}
package/dist/utils/mdx.js CHANGED
@@ -5,7 +5,8 @@ import matter from "gray-matter";
5
5
  //#region src/utils/mdx.ts
6
6
  async function readMDXFile(filePath) {
7
7
  try {
8
- const { content, data } = matter(await readFile(filePath, "utf-8"));
8
+ const fileContent = await readFile(filePath, "utf-8");
9
+ const { content, data } = matter(fileContent);
9
10
  const excerptMatch = content.match(/^(.+?)(?:\n\n|$)/);
10
11
  const excerpt = excerptMatch?.[1] !== void 0 ? excerptMatch[1].replace(/^#+ /, "") : void 0;
11
12
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"mdx.js","names":[],"sources":["../../src/utils/mdx.ts"],"sourcesContent":["import { readFile, lstat } from \"node:fs/promises\";\nimport matter from \"gray-matter\";\nimport { MAX_FILE_SIZE } from \"../constants.js\";\nimport { logger } from \"./logger.js\";\n\ninterface MDXContent {\n content: string;\n frontmatter: Record<string, any>;\n excerpt?: string;\n}\n\nexport async function readMDXFile(\n filePath: string,\n): Promise<MDXContent | null> {\n try {\n const fileContent = await readFile(filePath, \"utf-8\");\n const { content, data } = matter(fileContent);\n\n const excerptMatch = content.match(/^(.+?)(?:\\n\\n|$)/);\n const excerpt =\n excerptMatch?.[1] !== undefined\n ? excerptMatch[1].replace(/^#+ /, \"\")\n : undefined;\n\n return {\n content,\n frontmatter: data,\n ...(excerpt !== undefined && { excerpt }),\n };\n } catch (error) {\n logger.error(`Failed to read MDX file: ${filePath}`, error);\n return null;\n }\n}\n\nexport async function readMDXFileSafe(\n filePath: string,\n): Promise<MDXContent | null> {\n try {\n const stats = await lstat(filePath);\n if (stats.isSymbolicLink()) {\n logger.warn(`Attempted to read symlink: ${filePath}`);\n return null;\n }\n if (stats.size > MAX_FILE_SIZE) {\n logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);\n return null;\n }\n } catch {\n return null;\n }\n return readMDXFile(filePath);\n}\n\nexport function formatMDXContent(mdxContent: MDXContent): string {\n const { content, frontmatter } = mdxContent;\n\n return matter.stringify(content, frontmatter);\n}\n"],"mappings":";;;;;AAWA,eAAsB,YACpB,UAC4B;CAC5B,IAAI;EAEF,MAAM,EAAE,SAAS,SAAS,OAAO,MADP,SAAS,UAAU,OAAO,CACR;EAE5C,MAAM,eAAe,QAAQ,MAAM,kBAAkB;EACrD,MAAM,UACJ,eAAe,OAAO,KAAA,IAClB,aAAa,EAAE,CAAC,QAAQ,QAAQ,EAAE,IAClC,KAAA;EAEN,OAAO;GACL;GACA,aAAa;GACb,GAAI,YAAY,KAAA,KAAa,EAAE,QAAQ;EACzC;CACF,SAAS,OAAO;EACd,OAAO,MAAM,4BAA4B,YAAY,KAAK;EAC1D,OAAO;CACT;AACF;AAEA,eAAsB,gBACpB,UAC4B;CAC5B,IAAI;EACF,MAAM,QAAQ,MAAM,MAAM,QAAQ;EAClC,IAAI,MAAM,eAAe,GAAG;GAC1B,OAAO,KAAK,8BAA8B,UAAU;GACpD,OAAO;EACT;EACA,IAAI,MAAM,OAAA,UAAsB;GAC9B,OAAO,KAAK,4BAA4B,SAAS,IAAI,MAAM,KAAK,QAAQ;GACxE,OAAO;EACT;CACF,QAAQ;EACN,OAAO;CACT;CACA,OAAO,YAAY,QAAQ;AAC7B;AAEA,SAAgB,iBAAiB,YAAgC;CAC/D,MAAM,EAAE,SAAS,gBAAgB;CAEjC,OAAO,OAAO,UAAU,SAAS,WAAW;AAC9C"}
1
+ {"version":3,"file":"mdx.js","names":[],"sources":["../../src/utils/mdx.ts"],"sourcesContent":["import { readFile, lstat } from \"node:fs/promises\";\nimport matter from \"gray-matter\";\nimport { MAX_FILE_SIZE } from \"../constants.js\";\nimport { logger } from \"./logger.js\";\n\ninterface MDXContent {\n content: string;\n frontmatter: Record<string, any>;\n excerpt?: string;\n}\n\nexport async function readMDXFile(\n filePath: string,\n): Promise<MDXContent | null> {\n try {\n const fileContent = await readFile(filePath, \"utf-8\");\n const { content, data } = matter(fileContent);\n\n const excerptMatch = content.match(/^(.+?)(?:\\n\\n|$)/);\n const excerpt =\n excerptMatch?.[1] !== undefined\n ? excerptMatch[1].replace(/^#+ /, \"\")\n : undefined;\n\n return {\n content,\n frontmatter: data,\n ...(excerpt !== undefined && { excerpt }),\n };\n } catch (error) {\n logger.error(`Failed to read MDX file: ${filePath}`, error);\n return null;\n }\n}\n\nexport async function readMDXFileSafe(\n filePath: string,\n): Promise<MDXContent | null> {\n try {\n const stats = await lstat(filePath);\n if (stats.isSymbolicLink()) {\n logger.warn(`Attempted to read symlink: ${filePath}`);\n return null;\n }\n if (stats.size > MAX_FILE_SIZE) {\n logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);\n return null;\n }\n } catch {\n return null;\n }\n return readMDXFile(filePath);\n}\n\nexport function formatMDXContent(mdxContent: MDXContent): string {\n const { content, frontmatter } = mdxContent;\n\n return matter.stringify(content, frontmatter);\n}\n"],"mappings":";;;;;AAWA,eAAsB,YACpB,UAC4B;CAC5B,IAAI;EACF,MAAM,cAAc,MAAM,SAAS,UAAU,OAAO;EACpD,MAAM,EAAE,SAAS,SAAS,OAAO,WAAW;EAE5C,MAAM,eAAe,QAAQ,MAAM,kBAAkB;EACrD,MAAM,UACJ,eAAe,OAAO,KAAA,IAClB,aAAa,EAAE,CAAC,QAAQ,QAAQ,EAAE,IAClC,KAAA;EAEN,OAAO;GACL;GACA,aAAa;GACb,GAAI,YAAY,KAAA,KAAa,EAAE,QAAQ;EACzC;CACF,SAAS,OAAO;EACd,OAAO,MAAM,4BAA4B,YAAY,KAAK;EAC1D,OAAO;CACT;AACF;AAEA,eAAsB,gBACpB,UAC4B;CAC5B,IAAI;EACF,MAAM,QAAQ,MAAM,MAAM,QAAQ;EAClC,IAAI,MAAM,eAAe,GAAG;GAC1B,OAAO,KAAK,8BAA8B,UAAU;GACpD,OAAO;EACT;EACA,IAAI,MAAM,OAAA,UAAsB;GAC9B,OAAO,KAAK,4BAA4B,SAAS,IAAI,MAAM,KAAK,QAAQ;GACxE,OAAO;EACT;CACF,QAAQ;EACN,OAAO;CACT;CACA,OAAO,YAAY,QAAQ;AAC7B;AAEA,SAAgB,iBAAiB,YAAgC;CAC/D,MAAM,EAAE,SAAS,gBAAgB;CAEjC,OAAO,OAAO,UAAU,SAAS,WAAW;AAC9C"}
@@ -2,7 +2,7 @@ import { logger } from "../utils/logger.js";
2
2
  import { FALLBACK_CATALOG, FALLBACK_NOTE } from "./fallback-catalog.js";
3
3
  //#region src/xulux/catalog-client.ts
4
4
  const DEFAULT_CATALOG_URL = "https://www.assistant-ui.com/api/xulux/mcp-catalog";
5
- const CATALOG_TTL_MS = 300 * 1e3;
5
+ const CATALOG_TTL_MS = 3e5;
6
6
  function getCatalogUrl() {
7
7
  return process.env.XULUX_CATALOG_URL?.trim() || "https://www.assistant-ui.com/api/xulux/mcp-catalog";
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-client.js","names":[],"sources":["../../src/xulux/catalog-client.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\nimport { FALLBACK_CATALOG, FALLBACK_NOTE } from \"./fallback-catalog.js\";\nimport type { XuluxCatalog, XuluxCatalogResult } from \"./types.js\";\n\nexport const DEFAULT_CATALOG_URL =\n \"https://www.assistant-ui.com/api/xulux/mcp-catalog\";\n\nconst CATALOG_TTL_MS = 5 * 60 * 1000;\n\nexport function getCatalogUrl(): string {\n const override = process.env.XULUX_CATALOG_URL?.trim();\n return override || DEFAULT_CATALOG_URL;\n}\n\nfunction validateCatalog(data: unknown): XuluxCatalog {\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n throw new Error(\"Catalog response is not a JSON object.\");\n }\n const catalog = data as XuluxCatalog;\n if (catalog.version !== 1) {\n throw new Error(\n `Unsupported catalog version: ${String(catalog.version)}. Expected 1.`,\n );\n }\n if (!Array.isArray(catalog.templates)) {\n throw new Error(\"Catalog response has no templates array.\");\n }\n for (const template of catalog.templates) {\n if (\n !template ||\n typeof template !== \"object\" ||\n typeof template.id !== \"string\" ||\n typeof template.templateId !== \"string\" ||\n (template.kind !== \"template\" && template.kind !== \"example\")\n ) {\n throw new Error(\n \"Catalog response contains a malformed template entry (missing id/templateId/kind).\",\n );\n }\n }\n return catalog;\n}\n\ninterface CacheEntry {\n catalog: XuluxCatalog;\n fetchedAt: number;\n url: string;\n}\n\nlet cache: CacheEntry | null = null;\n\nexport function clearCatalogCache(): void {\n cache = null;\n}\n\nasync function fetchCatalog(url: string): Promise<XuluxCatalog> {\n const res = await fetch(url, {\n headers: { Accept: \"application/json\" },\n });\n if (!res.ok) {\n throw new Error(`Catalog fetch failed: HTTP ${res.status}`);\n }\n const data: unknown = await res.json();\n return validateCatalog(data);\n}\n\n/**\n * Returns the assistant-ui template catalog. Uses an in-memory five-minute cache, and falls\n * back to a minimal bundled catalog (marked degraded) when the live fetch\n * fails and no cached copy exists.\n */\nexport async function getXuluxCatalog(): Promise<XuluxCatalogResult> {\n const url = getCatalogUrl();\n const now = Date.now();\n\n if (cache && cache.url === url && now - cache.fetchedAt < CATALOG_TTL_MS) {\n return { catalog: cache.catalog, degraded: false };\n }\n\n try {\n const catalog = await fetchCatalog(url);\n cache = { catalog, fetchedAt: now, url };\n return { catalog, degraded: false };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.warn(\n `assistant-ui template catalog fetch failed (${url}): ${message}`,\n );\n\n // Prefer a stale cached copy over the minimal fallback.\n if (cache && cache.url === url) {\n return {\n catalog: cache.catalog,\n degraded: true,\n degradedReason: `Live catalog refresh failed (${message}); using previously fetched catalog.`,\n };\n }\n\n return {\n catalog: FALLBACK_CATALOG,\n degraded: true,\n degradedReason: `${message} ${FALLBACK_NOTE}`,\n };\n }\n}\n"],"mappings":";;;AAIA,MAAa,sBACX;AAEF,MAAM,iBAAiB,MAAS;AAEhC,SAAgB,gBAAwB;CAEtC,OADiB,QAAQ,IAAI,mBAAmB,KAAK,KAAA;AAEvD;AAEA,SAAS,gBAAgB,MAA6B;CACpD,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACzD,MAAM,IAAI,MAAM,wCAAwC;CAE1D,MAAM,UAAU;CAChB,IAAI,QAAQ,YAAY,GACtB,MAAM,IAAI,MACR,gCAAgC,OAAO,QAAQ,OAAO,EAAE,cAC1D;CAEF,IAAI,CAAC,MAAM,QAAQ,QAAQ,SAAS,GAClC,MAAM,IAAI,MAAM,0CAA0C;CAE5D,KAAK,MAAM,YAAY,QAAQ,WAC7B,IACE,CAAC,YACD,OAAO,aAAa,YACpB,OAAO,SAAS,OAAO,YACvB,OAAO,SAAS,eAAe,YAC9B,SAAS,SAAS,cAAc,SAAS,SAAS,WAEnD,MAAM,IAAI,MACR,oFACF;CAGJ,OAAO;AACT;AAQA,IAAI,QAA2B;AAE/B,SAAgB,oBAA0B;CACxC,QAAQ;AACV;AAEA,eAAe,aAAa,KAAoC;CAC9D,MAAM,MAAM,MAAM,MAAM,KAAK,EAC3B,SAAS,EAAE,QAAQ,mBAAmB,EACxC,CAAC;CACD,IAAI,CAAC,IAAI,IACP,MAAM,IAAI,MAAM,8BAA8B,IAAI,QAAQ;CAG5D,OAAO,gBAAgB,MADK,IAAI,KAAK,CACV;AAC7B;;;;;;AAOA,eAAsB,kBAA+C;CACnE,MAAM,MAAM,cAAc;CAC1B,MAAM,MAAM,KAAK,IAAI;CAErB,IAAI,SAAS,MAAM,QAAQ,OAAO,MAAM,MAAM,YAAY,gBACxD,OAAO;EAAE,SAAS,MAAM;EAAS,UAAU;CAAM;CAGnD,IAAI;EACF,MAAM,UAAU,MAAM,aAAa,GAAG;EACtC,QAAQ;GAAE;GAAS,WAAW;GAAK;EAAI;EACvC,OAAO;GAAE;GAAS,UAAU;EAAM;CACpC,SAAS,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,OAAO,KACL,+CAA+C,IAAI,KAAK,SAC1D;EAGA,IAAI,SAAS,MAAM,QAAQ,KACzB,OAAO;GACL,SAAS,MAAM;GACf,UAAU;GACV,gBAAgB,gCAAgC,QAAQ;EAC1D;EAGF,OAAO;GACL,SAAS;GACT,UAAU;GACV,gBAAgB,GAAG,QAAQ,GAAG;EAChC;CACF;AACF"}
1
+ {"version":3,"file":"catalog-client.js","names":[],"sources":["../../src/xulux/catalog-client.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\nimport { FALLBACK_CATALOG, FALLBACK_NOTE } from \"./fallback-catalog.js\";\nimport type { XuluxCatalog, XuluxCatalogResult } from \"./types.js\";\n\nexport const DEFAULT_CATALOG_URL =\n \"https://www.assistant-ui.com/api/xulux/mcp-catalog\";\n\nconst CATALOG_TTL_MS = 5 * 60 * 1000;\n\nexport function getCatalogUrl(): string {\n const override = process.env.XULUX_CATALOG_URL?.trim();\n return override || DEFAULT_CATALOG_URL;\n}\n\nfunction validateCatalog(data: unknown): XuluxCatalog {\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n throw new Error(\"Catalog response is not a JSON object.\");\n }\n const catalog = data as XuluxCatalog;\n if (catalog.version !== 1) {\n throw new Error(\n `Unsupported catalog version: ${String(catalog.version)}. Expected 1.`,\n );\n }\n if (!Array.isArray(catalog.templates)) {\n throw new Error(\"Catalog response has no templates array.\");\n }\n for (const template of catalog.templates) {\n if (\n !template ||\n typeof template !== \"object\" ||\n typeof template.id !== \"string\" ||\n typeof template.templateId !== \"string\" ||\n (template.kind !== \"template\" && template.kind !== \"example\")\n ) {\n throw new Error(\n \"Catalog response contains a malformed template entry (missing id/templateId/kind).\",\n );\n }\n }\n return catalog;\n}\n\ninterface CacheEntry {\n catalog: XuluxCatalog;\n fetchedAt: number;\n url: string;\n}\n\nlet cache: CacheEntry | null = null;\n\nexport function clearCatalogCache(): void {\n cache = null;\n}\n\nasync function fetchCatalog(url: string): Promise<XuluxCatalog> {\n const res = await fetch(url, {\n headers: { Accept: \"application/json\" },\n });\n if (!res.ok) {\n throw new Error(`Catalog fetch failed: HTTP ${res.status}`);\n }\n const data: unknown = await res.json();\n return validateCatalog(data);\n}\n\n/**\n * Returns the assistant-ui template catalog. Uses an in-memory five-minute cache, and falls\n * back to a minimal bundled catalog (marked degraded) when the live fetch\n * fails and no cached copy exists.\n */\nexport async function getXuluxCatalog(): Promise<XuluxCatalogResult> {\n const url = getCatalogUrl();\n const now = Date.now();\n\n if (cache && cache.url === url && now - cache.fetchedAt < CATALOG_TTL_MS) {\n return { catalog: cache.catalog, degraded: false };\n }\n\n try {\n const catalog = await fetchCatalog(url);\n cache = { catalog, fetchedAt: now, url };\n return { catalog, degraded: false };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.warn(\n `assistant-ui template catalog fetch failed (${url}): ${message}`,\n );\n\n // Prefer a stale cached copy over the minimal fallback.\n if (cache && cache.url === url) {\n return {\n catalog: cache.catalog,\n degraded: true,\n degradedReason: `Live catalog refresh failed (${message}); using previously fetched catalog.`,\n };\n }\n\n return {\n catalog: FALLBACK_CATALOG,\n degraded: true,\n degradedReason: `${message} ${FALLBACK_NOTE}`,\n };\n }\n}\n"],"mappings":";;;AAIA,MAAa,sBACX;AAEF,MAAM,iBAAiB;AAEvB,SAAgB,gBAAwB;CAEtC,OADiB,QAAQ,IAAI,mBAAmB,KAAK,KAAA;AAEvD;AAEA,SAAS,gBAAgB,MAA6B;CACpD,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACzD,MAAM,IAAI,MAAM,wCAAwC;CAE1D,MAAM,UAAU;CAChB,IAAI,QAAQ,YAAY,GACtB,MAAM,IAAI,MACR,gCAAgC,OAAO,QAAQ,OAAO,EAAE,cAC1D;CAEF,IAAI,CAAC,MAAM,QAAQ,QAAQ,SAAS,GAClC,MAAM,IAAI,MAAM,0CAA0C;CAE5D,KAAK,MAAM,YAAY,QAAQ,WAC7B,IACE,CAAC,YACD,OAAO,aAAa,YACpB,OAAO,SAAS,OAAO,YACvB,OAAO,SAAS,eAAe,YAC9B,SAAS,SAAS,cAAc,SAAS,SAAS,WAEnD,MAAM,IAAI,MACR,oFACF;CAGJ,OAAO;AACT;AAQA,IAAI,QAA2B;AAE/B,SAAgB,oBAA0B;CACxC,QAAQ;AACV;AAEA,eAAe,aAAa,KAAoC;CAC9D,MAAM,MAAM,MAAM,MAAM,KAAK,EAC3B,SAAS,EAAE,QAAQ,mBAAmB,EACxC,CAAC;CACD,IAAI,CAAC,IAAI,IACP,MAAM,IAAI,MAAM,8BAA8B,IAAI,QAAQ;CAG5D,OAAO,gBAAgB,MADK,IAAI,KAAK,CACV;AAC7B;;;;;;AAOA,eAAsB,kBAA+C;CACnE,MAAM,MAAM,cAAc;CAC1B,MAAM,MAAM,KAAK,IAAI;CAErB,IAAI,SAAS,MAAM,QAAQ,OAAO,MAAM,MAAM,YAAY,gBACxD,OAAO;EAAE,SAAS,MAAM;EAAS,UAAU;CAAM;CAGnD,IAAI;EACF,MAAM,UAAU,MAAM,aAAa,GAAG;EACtC,QAAQ;GAAE;GAAS,WAAW;GAAK;EAAI;EACvC,OAAO;GAAE;GAAS,UAAU;EAAM;CACpC,SAAS,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,OAAO,KACL,+CAA+C,IAAI,KAAK,SAC1D;EAGA,IAAI,SAAS,MAAM,QAAQ,KACzB,OAAO;GACL,SAAS,MAAM;GACf,UAAU;GACV,gBAAgB,gCAAgC,QAAQ;EAC1D;EAGF,OAAO;GACL,SAAS;GACT,UAAU;GACV,gBAAgB,GAAG,QAAQ,GAAG;EAChC;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/mcp-docs-server",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "MCP server for assistant-ui documentation and examples",
5
5
  "keywords": [
6
6
  "mcp",
@@ -38,10 +38,10 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@modelcontextprotocol/core": "^2.0.0",
41
- "@types/node": "^26.1.1",
42
- "tsx": "^4.23.1",
41
+ "@types/node": "^26.1.2",
42
+ "tsx": "^4.23.10",
43
43
  "vitest": "^4.1.10",
44
- "@assistant-ui/x-buildutils": "0.0.20"
44
+ "@assistant-ui/x-buildutils": "0.0.22"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",
@@ -42,7 +42,7 @@ describe("assistantUIDocs", () => {
42
42
  expect(result.found).toBe(true);
43
43
  expect(result.type).toBe("file");
44
44
  expect(result.content).toBeDefined();
45
- expect(result.content).toContain("assistant-ui");
45
+ expect(result.content).toContain("title: Documentation");
46
46
  });
47
47
 
48
48
  it("should handle non-existent paths", async () => {
@@ -88,7 +88,7 @@ describe("assistantUIDocs", () => {
88
88
 
89
89
  expect(result.content).toBeDefined();
90
90
  expect(result.content).toContain("title:");
91
- expect(result.content).toContain("assistant-ui");
91
+ expect(result.content).toContain("description:");
92
92
  });
93
93
 
94
94
  it("includes title and excerpt on a file response", async () => {