@assistant-ui/mcp-docs-server 0.1.16 → 0.1.18

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 (95) hide show
  1. package/.docs/organized/code-examples/with-ag-ui.md +149 -155
  2. package/.docs/organized/code-examples/with-ai-sdk-v5.md +98 -103
  3. package/.docs/organized/code-examples/with-assistant-transport.md +134 -222
  4. package/.docs/organized/code-examples/with-cloud.md +127 -134
  5. package/.docs/organized/code-examples/with-custom-thread-list.md +28 -48
  6. package/.docs/organized/code-examples/with-external-store.md +149 -154
  7. package/.docs/organized/code-examples/with-ffmpeg.md +132 -142
  8. package/.docs/organized/code-examples/with-langgraph.md +234 -228
  9. package/.docs/organized/code-examples/with-parent-id-grouping.md +149 -154
  10. package/.docs/organized/code-examples/with-react-hook-form.md +149 -155
  11. package/.docs/organized/code-examples/{store-example.md → with-store.md} +181 -157
  12. package/.docs/organized/code-examples/with-tanstack.md +31 -45
  13. package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +36 -0
  14. package/.docs/raw/docs/runtimes/custom/local.mdx +31 -8
  15. package/.docs/raw/docs/ui/Scrollbar.mdx +0 -6
  16. package/dist/constants.d.ts +10 -0
  17. package/dist/constants.d.ts.map +1 -0
  18. package/dist/constants.js +14 -0
  19. package/dist/constants.js.map +1 -0
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +33 -1
  23. package/dist/index.js.map +1 -0
  24. package/dist/prepare-docs/code-examples.d.ts +2 -0
  25. package/dist/prepare-docs/code-examples.d.ts.map +1 -0
  26. package/dist/prepare-docs/code-examples.js +129 -0
  27. package/dist/prepare-docs/code-examples.js.map +1 -0
  28. package/dist/prepare-docs/copy-raw.d.ts +2 -0
  29. package/dist/prepare-docs/copy-raw.d.ts.map +1 -0
  30. package/dist/prepare-docs/copy-raw.js +50 -0
  31. package/dist/prepare-docs/copy-raw.js.map +1 -0
  32. package/dist/prepare-docs/prepare.d.ts +2 -0
  33. package/dist/prepare-docs/prepare.d.ts.map +1 -0
  34. package/dist/prepare-docs/prepare.js +18 -195
  35. package/dist/prepare-docs/prepare.js.map +1 -0
  36. package/dist/stdio.d.ts +3 -0
  37. package/dist/stdio.d.ts.map +1 -0
  38. package/dist/stdio.js +4 -5
  39. package/dist/stdio.js.map +1 -0
  40. package/dist/tools/docs.d.ts +23 -0
  41. package/dist/tools/docs.d.ts.map +1 -0
  42. package/dist/tools/docs.js +168 -0
  43. package/dist/tools/docs.js.map +1 -0
  44. package/dist/tools/examples.d.ts +23 -0
  45. package/dist/tools/examples.d.ts.map +1 -0
  46. package/dist/tools/examples.js +95 -0
  47. package/dist/tools/examples.js.map +1 -0
  48. package/dist/tools/tests/test-setup.d.ts +4 -0
  49. package/dist/tools/tests/test-setup.d.ts.map +1 -0
  50. package/dist/tools/tests/test-setup.js +36 -0
  51. package/dist/tools/tests/test-setup.js.map +1 -0
  52. package/dist/utils/logger.d.ts +7 -0
  53. package/dist/utils/logger.d.ts.map +1 -0
  54. package/dist/utils/logger.js +20 -0
  55. package/dist/utils/logger.js.map +1 -0
  56. package/dist/utils/mcp-format.d.ts +7 -0
  57. package/dist/utils/mcp-format.d.ts.map +1 -0
  58. package/dist/utils/mcp-format.js +11 -0
  59. package/dist/utils/mcp-format.js.map +1 -0
  60. package/dist/utils/mdx.d.ts +9 -0
  61. package/dist/utils/mdx.d.ts.map +1 -0
  62. package/dist/utils/mdx.js +27 -0
  63. package/dist/utils/mdx.js.map +1 -0
  64. package/dist/utils/paths.d.ts +8 -0
  65. package/dist/utils/paths.d.ts.map +1 -0
  66. package/dist/utils/paths.js +84 -0
  67. package/dist/utils/paths.js.map +1 -0
  68. package/dist/utils/security.d.ts +2 -0
  69. package/dist/utils/security.d.ts.map +1 -0
  70. package/dist/utils/security.js +43 -0
  71. package/dist/utils/security.js.map +1 -0
  72. package/package.json +37 -19
  73. package/src/constants.ts +22 -0
  74. package/src/index.ts +51 -0
  75. package/src/prepare-docs/code-examples.ts +158 -0
  76. package/src/prepare-docs/copy-raw.ts +55 -0
  77. package/src/prepare-docs/prepare.ts +24 -0
  78. package/src/stdio.ts +7 -0
  79. package/src/tools/docs.ts +207 -0
  80. package/src/tools/examples.ts +107 -0
  81. package/src/tools/tests/docs.test.ts +122 -0
  82. package/src/tools/tests/examples.test.ts +94 -0
  83. package/src/tools/tests/integration.test.ts +46 -0
  84. package/src/tools/tests/json-parsing.test.ts +23 -0
  85. package/src/tools/tests/mcp-protocol.test.ts +133 -0
  86. package/src/tools/tests/path-traversal.test.ts +81 -0
  87. package/src/tools/tests/test-setup.ts +40 -0
  88. package/src/utils/logger.ts +20 -0
  89. package/src/utils/mcp-format.ts +12 -0
  90. package/src/utils/mdx.ts +39 -0
  91. package/src/utils/paths.ts +114 -0
  92. package/src/utils/security.ts +52 -0
  93. package/src/utils/tests/security.test.ts +119 -0
  94. package/dist/chunk-M2RKUM66.js +0 -38
  95. package/dist/chunk-NVNFQ5ZO.js +0 -423
@@ -217,6 +217,42 @@ When the hook mounts it calls `list()` on your adapter, hydrates existing thread
217
217
  - `generateTitle()` powers the automatic title button and expects an `AssistantStream`.
218
218
  - Provide a `runtimeHook` that always returns a fresh runtime instance per active thread.
219
219
 
220
+ ## Avoiding Race Conditions in History Adapters
221
+
222
+ <Callout type="warn">
223
+ When implementing a custom history adapter, you must await thread initialization before saving messages. Failing to do so can cause the first message to be lost due to a race condition.
224
+ </Callout>
225
+
226
+ If you're building a history adapter that persists messages to your own database, use `api.threadListItem().initialize()` to ensure the thread is fully initialized before saving:
227
+
228
+ ```tsx
229
+ import { useAssistantApi } from "@assistant-ui/react";
230
+
231
+ // Inside your unstable_Provider component
232
+ const api = useAssistantApi();
233
+
234
+ const history = useMemo<ThreadHistoryAdapter>(
235
+ () => ({
236
+ async append(message) {
237
+ // Wait for initialization to complete and get the remoteId
238
+ const { remoteId } = await api.threadListItem().initialize();
239
+
240
+ // Now safe to save the message using the remoteId
241
+ await saveMessageToDatabase(remoteId, message);
242
+ },
243
+ // ...
244
+ }),
245
+ [api],
246
+ );
247
+ ```
248
+
249
+ The `initialize()` method:
250
+ - Can be called multiple times safely
251
+ - Always waits for the initial `initialize()` call to complete
252
+ - Returns the same `remoteId` on subsequent calls
253
+
254
+ See `AssistantCloudThreadHistoryAdapter` in the source code for a production-ready reference implementation.
255
+
220
256
  ## Optional Adapters
221
257
 
222
258
  If you need history or attachment support, expose them via `unstable_Provider`. The cloud implementation wraps each thread runtime with `RuntimeAdapterProvider` to inject:
@@ -415,7 +415,7 @@ For custom thread storage, use `useRemoteThreadListRuntime` with your own adapte
415
415
  ```tsx
416
416
  import {
417
417
  unstable_useRemoteThreadListRuntime as useRemoteThreadListRuntime,
418
- useThreadListItem,
418
+ useAssistantApi,
419
419
  RuntimeAdapterProvider,
420
420
  AssistantRuntimeProvider,
421
421
  type unstable_RemoteThreadListAdapter as RemoteThreadListAdapter,
@@ -487,13 +487,13 @@ export function MyRuntimeProvider({ children }) {
487
487
  // The Provider component adds thread-specific adapters
488
488
  unstable_Provider: ({ children }) => {
489
489
  // This runs in the context of each thread
490
- const threadListItem = useThreadListItem();
491
- const remoteId = threadListItem.remoteId;
490
+ const api = useAssistantApi();
492
491
 
493
492
  // Create thread-specific history adapter
494
493
  const history = useMemo<ThreadHistoryAdapter>(
495
494
  () => ({
496
495
  async load() {
496
+ const { remoteId } = api.threadListItem().getState();
497
497
  if (!remoteId) return { messages: [] };
498
498
 
499
499
  const messages = await db.messages.findByThreadId(remoteId);
@@ -508,10 +508,8 @@ export function MyRuntimeProvider({ children }) {
508
508
  },
509
509
 
510
510
  async append(message) {
511
- if (!remoteId) {
512
- console.warn("Cannot save message - thread not initialized");
513
- return;
514
- }
511
+ // Wait for initialization to get remoteId (safe to call multiple times)
512
+ const { remoteId } = await api.threadListItem().initialize();
515
513
 
516
514
  await db.messages.create({
517
515
  threadId: remoteId,
@@ -522,7 +520,7 @@ export function MyRuntimeProvider({ children }) {
522
520
  });
523
521
  },
524
522
  }),
525
- [remoteId],
523
+ [api],
526
524
  );
527
525
 
528
526
  const adapters = useMemo(() => ({ history }), [history]);
@@ -570,6 +568,31 @@ The complete multi-thread implementation requires:
570
568
 
571
569
  Without the history adapter, threads would have no message persistence, making them effectively useless. The Provider pattern allows you to add thread-specific functionality while keeping the runtime creation simple.
572
570
 
571
+ <Callout type="warn" title="Avoiding Race Conditions">
572
+ When implementing a history adapter, `append()` may be called before the thread is fully initialized, causing the first message to be lost. Instead of checking `if (!remoteId)`, await initialization to ensure the `remoteId` is available:
573
+
574
+ ```tsx
575
+ import { useAssistantApi } from "@assistant-ui/react";
576
+
577
+ // Inside your unstable_Provider component
578
+ const api = useAssistantApi();
579
+
580
+ const history = useMemo<ThreadHistoryAdapter>(
581
+ () => ({
582
+ async append(message) {
583
+ // Wait for initialization - safe to call multiple times
584
+ const { remoteId } = await api.threadListItem().initialize();
585
+ await db.messages.create({ threadId: remoteId, ...message });
586
+ },
587
+ // ...
588
+ }),
589
+ [api],
590
+ );
591
+ ```
592
+
593
+ See `AssistantCloudThreadHistoryAdapter` in the source for a production reference.
594
+ </Callout>
595
+
573
596
  #### Database Schema Example
574
597
 
575
598
  ```typescript
@@ -11,12 +11,6 @@ An example implementation of this is [shadcn/ui's Scroll Area](https://ui.shadcn
11
11
 
12
12
  <InstallCommand shadcn={["scroll-area"]} />
13
13
 
14
- ### @radix-ui/react-scroll-area v1.2.0 release candidate required
15
-
16
- The v1.2.0-rc.x release candidate can be installed via
17
-
18
- <InstallCommand npm={["@radix-ui/react-scroll-area@next"]} />
19
-
20
14
  ## Additional Styles
21
15
 
22
16
  The Radix UI Viewport component adds an intermediate `<div data-radix-scroll-area-content>` element.
@@ -0,0 +1,10 @@
1
+ export declare const ROOT_DIR: string;
2
+ export declare const PACKAGE_DIR: string;
3
+ export declare const EXAMPLES_PATH: string;
4
+ export declare const DOCS_PATH: string;
5
+ export declare const CODE_EXAMPLES_PATH: string;
6
+ export declare const MDX_EXTENSION = ".mdx";
7
+ export declare const MD_EXTENSION = ".md";
8
+ export declare const MAX_FILE_SIZE: number;
9
+ export declare const IS_PREPARE_MODE: boolean | undefined;
10
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,QAA+B,CAAC;AACrD,eAAO,MAAM,WAAW,QAAyB,CAAC;AAElD,eAAO,MAAM,aAAa,QAA6B,CAAC;AAGxD,eAAO,MAAM,SAAS,QAA8B,CAAC;AACrD,eAAO,MAAM,kBAAkB,QAA6C,CAAC;AAE7E,eAAO,MAAM,aAAa,SAAS,CAAC;AACpC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,aAAa,QAAmB,CAAC;AAE9C,eAAO,MAAM,eAAe,qBAE3B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { dirname, join } from "node:path";
3
+ const __dirname = dirname(fileURLToPath(import.meta.url));
4
+ export const ROOT_DIR = join(__dirname, "../../../");
5
+ export const PACKAGE_DIR = join(__dirname, "../");
6
+ export const EXAMPLES_PATH = join(ROOT_DIR, "examples");
7
+ const DOCS_BASE = join(PACKAGE_DIR, ".docs");
8
+ export const DOCS_PATH = join(DOCS_BASE, "raw/docs");
9
+ export const CODE_EXAMPLES_PATH = join(DOCS_BASE, "organized/code-examples");
10
+ export const MDX_EXTENSION = ".mdx";
11
+ export const MD_EXTENSION = ".md";
12
+ export const MAX_FILE_SIZE = 10 * 1024 * 1024;
13
+ export const IS_PREPARE_MODE = process.argv[1]?.includes("prepare-docs/prepare");
14
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAExD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AACpC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAElC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CACtD,sBAAsB,CACvB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare const server: McpServer;
3
+ export declare function runServer(): Promise<void>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAcpE,eAAO,MAAM,MAAM,WAGjB,CAAC;AAeH,wBAAsB,SAAS,kBAW9B"}
package/dist/index.js CHANGED
@@ -1 +1,33 @@
1
- export { runServer, server } from './chunk-NVNFQ5ZO.js';
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { docsTools } from "./tools/docs.js";
4
+ import { examplesTools } from "./tools/examples.js";
5
+ import { logger } from "./utils/logger.js";
6
+ import { PACKAGE_DIR } from "./constants.js";
7
+ import { readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ const packageJson = JSON.parse(readFileSync(join(PACKAGE_DIR, "package.json"), "utf-8"));
10
+ export const server = new McpServer({
11
+ name: "assistant-ui-docs",
12
+ version: packageJson.version,
13
+ });
14
+ server.tool(docsTools.name, docsTools.description, docsTools.parameters, docsTools.execute);
15
+ server.tool(examplesTools.name, examplesTools.description, examplesTools.parameters, examplesTools.execute);
16
+ export async function runServer() {
17
+ try {
18
+ logger.info(`Starting assistant-ui MCP docs server v${packageJson.version}`);
19
+ const transport = new StdioServerTransport();
20
+ await server.connect(transport);
21
+ }
22
+ catch (error) {
23
+ logger.error("Failed to start MCP server", error);
24
+ process.exit(1);
25
+ }
26
+ }
27
+ if (import.meta.url === `file://${process.argv[1]}`) {
28
+ void runServer().catch((error) => {
29
+ console.error("Failed to start server:", error);
30
+ process.exit(1);
31
+ });
32
+ }
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB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K,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function prepareCodeExamples(): Promise<void>;
2
+ //# sourceMappingURL=code-examples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-examples.d.ts","sourceRoot":"","sources":["../../src/prepare-docs/code-examples.ts"],"names":[],"mappings":"AA2FA,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkEzD"}
@@ -0,0 +1,129 @@
1
+ import { rm, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
2
+ import { join, relative, extname } from "node:path";
3
+ import { logger } from "../utils/logger.js";
4
+ import { ROOT_DIR, EXAMPLES_PATH } from "../constants.js";
5
+ const OUTPUT_DIR = join(ROOT_DIR, "packages/mcp-docs-server/.docs/organized/code-examples");
6
+ const MAX_LINES = 10000;
7
+ async function scanDirectory(dir, baseDir) {
8
+ const files = [];
9
+ try {
10
+ const entries = await readdir(dir, { withFileTypes: true });
11
+ for (const entry of entries) {
12
+ const fullPath = join(dir, entry.name);
13
+ if (entry.isDirectory()) {
14
+ const skipDirs = [
15
+ "node_modules",
16
+ "dist",
17
+ "build",
18
+ ".next",
19
+ ".git",
20
+ ".turbo",
21
+ ];
22
+ if (!skipDirs.includes(entry.name)) {
23
+ const subFiles = await scanDirectory(fullPath, baseDir);
24
+ files.push(...subFiles);
25
+ }
26
+ }
27
+ else if (entry.isFile()) {
28
+ const includeExts = [
29
+ ".ts",
30
+ ".tsx",
31
+ ".js",
32
+ ".jsx",
33
+ ".json",
34
+ ".css",
35
+ ".md",
36
+ ".mdx",
37
+ ];
38
+ const ext = extname(entry.name).toLowerCase();
39
+ if (includeExts.includes(ext) ||
40
+ entry.name === "package.json" ||
41
+ entry.name === "tsconfig.json") {
42
+ try {
43
+ const content = await readFile(fullPath, "utf-8");
44
+ const relativePath = relative(baseDir, fullPath);
45
+ files.push({ path: relativePath, content });
46
+ }
47
+ catch (error) {
48
+ logger.warn(`Failed to read file: ${fullPath}`, error);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ catch (error) {
55
+ logger.error(`Failed to scan directory: ${dir}`, error);
56
+ }
57
+ return files;
58
+ }
59
+ function getFileType(filename) {
60
+ const ext = extname(filename).toLowerCase();
61
+ const extMap = {
62
+ ".ts": "typescript",
63
+ ".tsx": "tsx",
64
+ ".js": "javascript",
65
+ ".jsx": "jsx",
66
+ ".json": "json",
67
+ ".css": "css",
68
+ ".md": "markdown",
69
+ ".mdx": "mdx",
70
+ };
71
+ return extMap[ext] || "text";
72
+ }
73
+ export async function prepareCodeExamples() {
74
+ logger.info("Preparing code examples...");
75
+ try {
76
+ await rm(OUTPUT_DIR, { recursive: true, force: true });
77
+ await mkdir(OUTPUT_DIR, { recursive: true });
78
+ const exampleDirs = await readdir(EXAMPLES_PATH, { withFileTypes: true });
79
+ for (const dir of exampleDirs) {
80
+ if (dir.isDirectory() && !dir.name.startsWith(".")) {
81
+ const examplePath = join(EXAMPLES_PATH, dir.name);
82
+ logger.info(`Processing example: ${dir.name}`);
83
+ let description = "";
84
+ try {
85
+ const packageJsonPath = join(examplePath, "package.json");
86
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8"));
87
+ description = packageJson.description || "";
88
+ }
89
+ catch (error) {
90
+ if (error?.code !== "ENOENT") {
91
+ logger.warn(`Failed to read package.json for ${dir.name}:`, error);
92
+ }
93
+ else {
94
+ logger.debug(`No package.json found for example: ${dir.name}`);
95
+ }
96
+ }
97
+ const files = await scanDirectory(examplePath, examplePath);
98
+ files.sort((a, b) => a.path.localeCompare(b.path));
99
+ let markdown = `# Example: ${dir.name}\n\n`;
100
+ if (description) {
101
+ markdown += `${description}\n\n`;
102
+ }
103
+ let totalLines = 0;
104
+ for (const file of files) {
105
+ const lines = file.content.split("\n").length;
106
+ if (totalLines + lines > MAX_LINES) {
107
+ markdown += `\n_Note: Additional files truncated due to size limits_\n`;
108
+ break;
109
+ }
110
+ // Normalize Windows backslashes to forward slashes for consistent markdown output
111
+ markdown += `## ${file.path.replace(/\\/g, "/")}\n\n`;
112
+ markdown += `\`\`\`${getFileType(file.path)}\n`;
113
+ markdown += file.content;
114
+ markdown += `\n\`\`\`\n\n`;
115
+ totalLines += lines;
116
+ }
117
+ const outputPath = join(OUTPUT_DIR, `${dir.name}.md`);
118
+ await writeFile(outputPath, markdown, "utf-8");
119
+ logger.debug(`Created example: ${outputPath}`);
120
+ }
121
+ }
122
+ logger.info("Code examples preparation complete");
123
+ }
124
+ catch (error) {
125
+ logger.error("Failed to prepare code examples", error);
126
+ throw error;
127
+ }
128
+ }
129
+ //# sourceMappingURL=code-examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-examples.js","sourceRoot":"","sources":["../../src/prepare-docs/code-examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,UAAU,GAAG,IAAI,CACrB,QAAQ,EACR,wDAAwD,CACzD,CAAC;AACF,MAAM,SAAS,GAAG,KAAK,CAAC;AAOxB,KAAK,UAAU,aAAa,CAC1B,GAAW,EACX,OAAe;IAEf,MAAM,KAAK,GAAkB,EAAE,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;Y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C,MAAM,CAAC;oBAC9C,IAAI,UAAU,GAAG,KAAK,GAAG,SAAS,EAAE,CAAC;wBACnC,QAAQ,IAAI,2DAA2D,CAAC;wBACxE,MAAM;oBACR,CAAC;oBAED,kFAAkF;oBAClF,QAAQ,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;oBACtD,QAAQ,IAAI,SAAS,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;oBAChD,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC;oBACzB,QAAQ,IAAI,cAAc,CAAC;oBAE3B,UAAU,IAAI,KAAK,CAAC;gBACtB,CAAC;gBAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC;gBACtD,MAAM,SAAS,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAC/C,MAAM,CAAC,KAAK,CAAC,oBAAoB,UAAU,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACvD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function copyRaw(): Promise<void>;
2
+ //# sourceMappingURL=copy-raw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-raw.d.ts","sourceRoot":"","sources":["../../src/prepare-docs/copy-raw.ts"],"names":[],"mappings":"AAkCA,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAoB7C"}
@@ -0,0 +1,50 @@
1
+ import { rm, mkdir, readdir, copyFile } from "node:fs/promises";
2
+ import { join, extname } from "node:path";
3
+ import { logger } from "../utils/logger.js";
4
+ import { ROOT_DIR } from "../constants.js";
5
+ const DOCS_SOURCE = join(ROOT_DIR, "apps/docs/content/docs");
6
+ const BLOG_SOURCE = join(ROOT_DIR, "apps/docs/content/blog");
7
+ const DOCS_DEST = join(ROOT_DIR, "packages/mcp-docs-server/.docs/raw");
8
+ async function copyDir(src, dest) {
9
+ try {
10
+ await mkdir(dest, { recursive: true });
11
+ const entries = await readdir(src, { withFileTypes: true });
12
+ for (const entry of entries) {
13
+ const srcPath = join(src, entry.name);
14
+ const destPath = join(dest, entry.name);
15
+ if (entry.isDirectory()) {
16
+ await copyDir(srcPath, destPath);
17
+ }
18
+ else if (entry.isFile()) {
19
+ const ext = extname(entry.name).toLowerCase();
20
+ if (ext === ".mdx" || ext === ".md") {
21
+ await copyFile(srcPath, destPath);
22
+ logger.debug(`Copied: ${srcPath} -> ${destPath}`);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ catch (error) {
28
+ logger.error(`Failed to copy directory: ${src}`, error);
29
+ throw error;
30
+ }
31
+ }
32
+ export async function copyRaw() {
33
+ logger.info("Copying raw documentation files...");
34
+ try {
35
+ await rm(DOCS_DEST, { recursive: true, force: true });
36
+ await mkdir(DOCS_DEST, { recursive: true });
37
+ const docsPath = join(DOCS_DEST, "docs");
38
+ await copyDir(DOCS_SOURCE, docsPath);
39
+ logger.info(`Copied documentation to ${docsPath}`);
40
+ const blogPath = join(DOCS_DEST, "blog");
41
+ await copyDir(BLOG_SOURCE, blogPath);
42
+ logger.info(`Copied blog posts to ${blogPath}`);
43
+ logger.info("Raw documentation copy complete");
44
+ }
45
+ catch (error) {
46
+ logger.error("Failed to copy raw documentation", error);
47
+ throw error;
48
+ }
49
+ }
50
+ //# sourceMappingURL=copy-raw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-raw.js","sourceRoot":"","sources":["../../src/prepare-docs/copy-raw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE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file":"prepare.d.ts","sourceRoot":"","sources":["../../src/prepare-docs/prepare.ts"],"names":[],"mappings":""}
@@ -1,199 +1,22 @@
1
- import { ROOT_DIR, logger, EXAMPLES_PATH } from '../chunk-M2RKUM66.js';
2
- import { rm, mkdir, readdir, readFile, writeFile, copyFile } from 'fs/promises';
3
- import { join, extname, relative } from 'path';
4
-
5
- var DOCS_SOURCE = join(ROOT_DIR, "apps/docs/content/docs");
6
- var BLOG_SOURCE = join(ROOT_DIR, "apps/docs/content/blog");
7
- var DOCS_DEST = join(ROOT_DIR, "packages/mcp-docs-server/.docs/raw");
8
- async function copyDir(src, dest) {
9
- try {
10
- await mkdir(dest, { recursive: true });
11
- const entries = await readdir(src, { withFileTypes: true });
12
- for (const entry of entries) {
13
- const srcPath = join(src, entry.name);
14
- const destPath = join(dest, entry.name);
15
- if (entry.isDirectory()) {
16
- await copyDir(srcPath, destPath);
17
- } else if (entry.isFile()) {
18
- const ext = extname(entry.name).toLowerCase();
19
- if (ext === ".mdx" || ext === ".md") {
20
- await copyFile(srcPath, destPath);
21
- logger.debug(`Copied: ${srcPath} -> ${destPath}`);
22
- }
23
- }
24
- }
25
- } catch (error) {
26
- logger.error(`Failed to copy directory: ${src}`, error);
27
- throw error;
28
- }
29
- }
30
- async function copyRaw() {
31
- logger.info("Copying raw documentation files...");
32
- try {
33
- await rm(DOCS_DEST, { recursive: true, force: true });
34
- await mkdir(DOCS_DEST, { recursive: true });
35
- const docsPath = join(DOCS_DEST, "docs");
36
- await copyDir(DOCS_SOURCE, docsPath);
37
- logger.info(`Copied documentation to ${docsPath}`);
38
- const blogPath = join(DOCS_DEST, "blog");
39
- await copyDir(BLOG_SOURCE, blogPath);
40
- logger.info(`Copied blog posts to ${blogPath}`);
41
- logger.info("Raw documentation copy complete");
42
- } catch (error) {
43
- logger.error("Failed to copy raw documentation", error);
44
- throw error;
45
- }
46
- }
47
- var OUTPUT_DIR = join(
48
- ROOT_DIR,
49
- "packages/mcp-docs-server/.docs/organized/code-examples"
50
- );
51
- var MAX_LINES = 1e4;
52
- async function scanDirectory(dir, baseDir) {
53
- const files = [];
54
- try {
55
- const entries = await readdir(dir, { withFileTypes: true });
56
- for (const entry of entries) {
57
- const fullPath = join(dir, entry.name);
58
- if (entry.isDirectory()) {
59
- const skipDirs = [
60
- "node_modules",
61
- "dist",
62
- "build",
63
- ".next",
64
- ".git",
65
- ".turbo"
66
- ];
67
- if (!skipDirs.includes(entry.name)) {
68
- const subFiles = await scanDirectory(fullPath, baseDir);
69
- files.push(...subFiles);
70
- }
71
- } else if (entry.isFile()) {
72
- const includeExts = [
73
- ".ts",
74
- ".tsx",
75
- ".js",
76
- ".jsx",
77
- ".json",
78
- ".css",
79
- ".md",
80
- ".mdx"
81
- ];
82
- const ext = extname(entry.name).toLowerCase();
83
- if (includeExts.includes(ext) || entry.name === "package.json" || entry.name === "tsconfig.json") {
84
- try {
85
- const content = await readFile(fullPath, "utf-8");
86
- const relativePath = relative(baseDir, fullPath);
87
- files.push({ path: relativePath, content });
88
- } catch (error) {
89
- logger.warn(`Failed to read file: ${fullPath}`, error);
90
- }
91
- }
92
- }
1
+ import { logger } from "../utils/logger.js";
2
+ import { copyRaw } from "./copy-raw.js";
3
+ import { prepareCodeExamples } from "./code-examples.js";
4
+ async function prepare() {
5
+ logger.info("Starting documentation preparation...");
6
+ try {
7
+ await copyRaw();
8
+ await prepareCodeExamples();
9
+ logger.info("Documentation preparation complete");
93
10
  }
94
- } catch (error) {
95
- logger.error(`Failed to scan directory: ${dir}`, error);
96
- }
97
- return files;
98
- }
99
- function getFileType(filename) {
100
- const ext = extname(filename).toLowerCase();
101
- const extMap = {
102
- ".ts": "typescript",
103
- ".tsx": "tsx",
104
- ".js": "javascript",
105
- ".jsx": "jsx",
106
- ".json": "json",
107
- ".css": "css",
108
- ".md": "markdown",
109
- ".mdx": "mdx"
110
- };
111
- return extMap[ext] || "text";
112
- }
113
- async function prepareCodeExamples() {
114
- logger.info("Preparing code examples...");
115
- try {
116
- await rm(OUTPUT_DIR, { recursive: true, force: true });
117
- await mkdir(OUTPUT_DIR, { recursive: true });
118
- const exampleDirs = await readdir(EXAMPLES_PATH, { withFileTypes: true });
119
- for (const dir of exampleDirs) {
120
- if (dir.isDirectory() && !dir.name.startsWith(".")) {
121
- const examplePath = join(EXAMPLES_PATH, dir.name);
122
- logger.info(`Processing example: ${dir.name}`);
123
- let description = "";
124
- try {
125
- const packageJsonPath = join(examplePath, "package.json");
126
- const packageJson = JSON.parse(
127
- await readFile(packageJsonPath, "utf-8")
128
- );
129
- description = packageJson.description || "";
130
- } catch (error) {
131
- if (error?.code !== "ENOENT") {
132
- logger.warn(`Failed to read package.json for ${dir.name}:`, error);
133
- } else {
134
- logger.debug(`No package.json found for example: ${dir.name}`);
135
- }
136
- }
137
- const files = await scanDirectory(examplePath, examplePath);
138
- files.sort((a, b) => a.path.localeCompare(b.path));
139
- let markdown = `# Example: ${dir.name}
140
-
141
- `;
142
- if (description) {
143
- markdown += `${description}
144
-
145
- `;
146
- }
147
- let totalLines = 0;
148
- for (const file of files) {
149
- const lines = file.content.split("\n").length;
150
- if (totalLines + lines > MAX_LINES) {
151
- markdown += `
152
- _Note: Additional files truncated due to size limits_
153
- `;
154
- break;
155
- }
156
- markdown += `## ${file.path.replace(/\\/g, "/")}
157
-
158
- `;
159
- markdown += `\`\`\`${getFileType(file.path)}
160
- `;
161
- markdown += file.content;
162
- markdown += `
163
- \`\`\`
164
-
165
- `;
166
- totalLines += lines;
167
- }
168
- const outputPath = join(OUTPUT_DIR, `${dir.name}.md`);
169
- await writeFile(outputPath, markdown, "utf-8");
170
- logger.debug(`Created example: ${outputPath}`);
171
- }
11
+ catch (error) {
12
+ logger.error("Documentation preparation failed", error);
13
+ throw error;
172
14
  }
173
- logger.info("Code examples preparation complete");
174
- } catch (error) {
175
- logger.error("Failed to prepare code examples", error);
176
- throw error;
177
- }
178
- }
179
-
180
- // src/prepare-docs/prepare.ts
181
- async function prepare() {
182
- logger.info("Starting documentation preparation...");
183
- try {
184
- await copyRaw();
185
- await prepareCodeExamples();
186
- logger.info("Documentation preparation complete");
187
- } catch (error) {
188
- logger.error("Documentation preparation failed", error);
189
- throw error;
190
- }
191
15
  }
192
- if (process.env.PREPARE === "true") {
193
- prepare().catch((error) => {
194
- logger.error("Preparation failed", error);
195
- process.exit(1);
196
- });
16
+ if (import.meta.url === `file://${process.argv[1]}`) {
17
+ prepare().catch((error) => {
18
+ logger.error("Preparation failed", error);
19
+ process.exit(1);
20
+ });
197
21
  }
198
-
199
- export { prepare };
22
+ //# sourceMappingURL=prepare.js.map