@assistant-ui/mcp-docs-server 0.1.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 (109) hide show
  1. package/.docs/organized/code-examples/local-ollama.md +1135 -0
  2. package/.docs/organized/code-examples/search-agent-for-e-commerce.md +1721 -0
  3. package/.docs/organized/code-examples/with-ai-sdk.md +1081 -0
  4. package/.docs/organized/code-examples/with-cloud.md +1164 -0
  5. package/.docs/organized/code-examples/with-external-store.md +1064 -0
  6. package/.docs/organized/code-examples/with-ffmpeg.md +1305 -0
  7. package/.docs/organized/code-examples/with-langgraph.md +1819 -0
  8. package/.docs/organized/code-examples/with-openai-assistants.md +1175 -0
  9. package/.docs/organized/code-examples/with-react-hook-form.md +1727 -0
  10. package/.docs/organized/code-examples/with-vercel-ai-rsc.md +1157 -0
  11. package/.docs/raw/blog/2024-07-29-hello/index.mdx +65 -0
  12. package/.docs/raw/blog/2024-09-11/index.mdx +10 -0
  13. package/.docs/raw/blog/2024-12-15/index.mdx +10 -0
  14. package/.docs/raw/blog/2025-01-31-changelog/index.mdx +129 -0
  15. package/.docs/raw/docs/about-assistantui.mdx +44 -0
  16. package/.docs/raw/docs/api-reference/context-providers/AssistantRuntimeProvider.mdx +30 -0
  17. package/.docs/raw/docs/api-reference/context-providers/TextContentPartProvider.mdx +26 -0
  18. package/.docs/raw/docs/api-reference/integrations/react-hook-form.mdx +103 -0
  19. package/.docs/raw/docs/api-reference/integrations/vercel-ai-sdk.mdx +145 -0
  20. package/.docs/raw/docs/api-reference/overview.mdx +583 -0
  21. package/.docs/raw/docs/api-reference/primitives/ActionBar.mdx +264 -0
  22. package/.docs/raw/docs/api-reference/primitives/AssistantModal.mdx +129 -0
  23. package/.docs/raw/docs/api-reference/primitives/Attachment.mdx +96 -0
  24. package/.docs/raw/docs/api-reference/primitives/BranchPicker.mdx +87 -0
  25. package/.docs/raw/docs/api-reference/primitives/Composer.mdx +204 -0
  26. package/.docs/raw/docs/api-reference/primitives/ContentPart.mdx +173 -0
  27. package/.docs/raw/docs/api-reference/primitives/Error.mdx +70 -0
  28. package/.docs/raw/docs/api-reference/primitives/Message.mdx +181 -0
  29. package/.docs/raw/docs/api-reference/primitives/Thread.mdx +197 -0
  30. package/.docs/raw/docs/api-reference/primitives/composition.mdx +21 -0
  31. package/.docs/raw/docs/api-reference/runtimes/AssistantRuntime.mdx +33 -0
  32. package/.docs/raw/docs/api-reference/runtimes/AttachmentRuntime.mdx +46 -0
  33. package/.docs/raw/docs/api-reference/runtimes/ComposerRuntime.mdx +69 -0
  34. package/.docs/raw/docs/api-reference/runtimes/ContentPartRuntime.mdx +22 -0
  35. package/.docs/raw/docs/api-reference/runtimes/MessageRuntime.mdx +49 -0
  36. package/.docs/raw/docs/api-reference/runtimes/ThreadListItemRuntime.mdx +32 -0
  37. package/.docs/raw/docs/api-reference/runtimes/ThreadListRuntime.mdx +31 -0
  38. package/.docs/raw/docs/api-reference/runtimes/ThreadRuntime.mdx +48 -0
  39. package/.docs/raw/docs/architecture.mdx +92 -0
  40. package/.docs/raw/docs/cloud/authorization.mdx +152 -0
  41. package/.docs/raw/docs/cloud/overview.mdx +55 -0
  42. package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +54 -0
  43. package/.docs/raw/docs/cloud/persistence/langgraph.mdx +123 -0
  44. package/.docs/raw/docs/concepts/architecture.mdx +19 -0
  45. package/.docs/raw/docs/concepts/runtime-layer.mdx +163 -0
  46. package/.docs/raw/docs/concepts/why.mdx +9 -0
  47. package/.docs/raw/docs/copilots/make-assistant-readable.mdx +71 -0
  48. package/.docs/raw/docs/copilots/make-assistant-tool-ui.mdx +76 -0
  49. package/.docs/raw/docs/copilots/make-assistant-tool.mdx +117 -0
  50. package/.docs/raw/docs/copilots/model-context.mdx +135 -0
  51. package/.docs/raw/docs/copilots/motivation.mdx +191 -0
  52. package/.docs/raw/docs/copilots/use-assistant-instructions.mdx +62 -0
  53. package/.docs/raw/docs/getting-started.mdx +1133 -0
  54. package/.docs/raw/docs/guides/Attachments.mdx +640 -0
  55. package/.docs/raw/docs/guides/Branching.mdx +59 -0
  56. package/.docs/raw/docs/guides/Editing.mdx +56 -0
  57. package/.docs/raw/docs/guides/Speech.mdx +43 -0
  58. package/.docs/raw/docs/guides/ToolUI.mdx +663 -0
  59. package/.docs/raw/docs/guides/Tools.mdx +496 -0
  60. package/.docs/raw/docs/index.mdx +7 -0
  61. package/.docs/raw/docs/legacy/styled/AssistantModal.mdx +85 -0
  62. package/.docs/raw/docs/legacy/styled/Decomposition.mdx +633 -0
  63. package/.docs/raw/docs/legacy/styled/Markdown.mdx +86 -0
  64. package/.docs/raw/docs/legacy/styled/Scrollbar.mdx +71 -0
  65. package/.docs/raw/docs/legacy/styled/Thread.mdx +84 -0
  66. package/.docs/raw/docs/legacy/styled/ThreadWidth.mdx +21 -0
  67. package/.docs/raw/docs/mcp-docs-server.mdx +324 -0
  68. package/.docs/raw/docs/migrations/deprecation-policy.mdx +41 -0
  69. package/.docs/raw/docs/migrations/v0-7.mdx +188 -0
  70. package/.docs/raw/docs/migrations/v0-8.mdx +160 -0
  71. package/.docs/raw/docs/migrations/v0-9.mdx +75 -0
  72. package/.docs/raw/docs/react-compatibility.mdx +208 -0
  73. package/.docs/raw/docs/runtimes/ai-sdk/rsc.mdx +226 -0
  74. package/.docs/raw/docs/runtimes/ai-sdk/use-assistant-hook.mdx +195 -0
  75. package/.docs/raw/docs/runtimes/ai-sdk/use-chat-hook.mdx +138 -0
  76. package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +136 -0
  77. package/.docs/raw/docs/runtimes/custom/external-store.mdx +1624 -0
  78. package/.docs/raw/docs/runtimes/custom/local.mdx +1185 -0
  79. package/.docs/raw/docs/runtimes/helicone.mdx +60 -0
  80. package/.docs/raw/docs/runtimes/langgraph/index.mdx +320 -0
  81. package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +11 -0
  82. package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +28 -0
  83. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +120 -0
  84. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +336 -0
  85. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +385 -0
  86. package/.docs/raw/docs/runtimes/langserve.mdx +126 -0
  87. package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +218 -0
  88. package/.docs/raw/docs/runtimes/mastra/overview.mdx +17 -0
  89. package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +196 -0
  90. package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +222 -0
  91. package/.docs/raw/docs/ui/AssistantModal.mdx +46 -0
  92. package/.docs/raw/docs/ui/AssistantSidebar.mdx +42 -0
  93. package/.docs/raw/docs/ui/Attachment.mdx +82 -0
  94. package/.docs/raw/docs/ui/Markdown.mdx +72 -0
  95. package/.docs/raw/docs/ui/Mermaid.mdx +79 -0
  96. package/.docs/raw/docs/ui/Scrollbar.mdx +59 -0
  97. package/.docs/raw/docs/ui/SyntaxHighlighting.mdx +253 -0
  98. package/.docs/raw/docs/ui/Thread.mdx +47 -0
  99. package/.docs/raw/docs/ui/ThreadList.mdx +49 -0
  100. package/.docs/raw/docs/ui/ToolFallback.mdx +64 -0
  101. package/.docs/raw/docs/ui/primitives/Thread.mdx +197 -0
  102. package/LICENSE +21 -0
  103. package/README.md +128 -0
  104. package/dist/chunk-C7O7EFKU.js +38 -0
  105. package/dist/chunk-CZCDQ3YH.js +420 -0
  106. package/dist/index.js +1 -0
  107. package/dist/prepare-docs/prepare.js +199 -0
  108. package/dist/stdio.js +8 -0
  109. package/package.json +43 -0
@@ -0,0 +1,420 @@
1
+ import { logger, IS_PREPARE_MODE, MDX_EXTENSION, DOCS_PATH, MAX_FILE_SIZE, CODE_EXAMPLES_PATH, MD_EXTENSION } from './chunk-C7O7EFKU.js';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+ import { lstat, stat, readdir, readFile } from 'fs/promises';
6
+ import path, { dirname, join, extname, normalize, relative } from 'path';
7
+ import matter from 'gray-matter';
8
+ import { readFileSync } from 'fs';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ var SIMILARITY_THRESHOLDS = {
12
+ EXACT_MATCH: 1,
13
+ CONTAINS_MATCH: 0.8,
14
+ PARTIAL_MATCH: 0.5,
15
+ MIN_SUGGESTION: 0.3
16
+ };
17
+ async function listDirContents(dirPath) {
18
+ try {
19
+ const items = await readdir(dirPath, { withFileTypes: true });
20
+ const directories = items.filter((item) => item.isDirectory()).map((item) => item.name).filter((name) => !name.startsWith(".")).sort();
21
+ const files = items.filter(
22
+ (item) => item.isFile() && (extname(item.name) === MDX_EXTENSION || extname(item.name) === MD_EXTENSION)
23
+ ).map((item) => item.name).sort();
24
+ return { directories, files };
25
+ } catch (error) {
26
+ logger.error(`Failed to list directory contents: ${dirPath}`, error);
27
+ return { directories: [], files: [] };
28
+ }
29
+ }
30
+ async function getAvailablePaths() {
31
+ const paths = [];
32
+ async function scanDirectory(dir, prefix = "") {
33
+ const { directories, files } = await listDirContents(dir);
34
+ for (const file of files) {
35
+ const name = file.replace(MDX_EXTENSION, "").replace(MD_EXTENSION, "");
36
+ paths.push(prefix ? `${prefix}/${name}` : name);
37
+ }
38
+ for (const subdir of directories) {
39
+ const subdirPath = join(dir, subdir);
40
+ const newPrefix = prefix ? `${prefix}/${subdir}` : subdir;
41
+ paths.push(newPrefix);
42
+ await scanDirectory(subdirPath, newPrefix);
43
+ }
44
+ }
45
+ await scanDirectory(DOCS_PATH);
46
+ return paths.sort();
47
+ }
48
+ function findNearestPaths(requestedPath, availablePaths) {
49
+ const normalizedRequest = requestedPath.toLowerCase().replace(/[^a-z0-9]/g, "");
50
+ const scored = availablePaths.map((path2) => {
51
+ const normalizedPath = path2.toLowerCase().replace(/[^a-z0-9]/g, "");
52
+ if (normalizedPath.includes(normalizedRequest)) {
53
+ return { path: path2, score: SIMILARITY_THRESHOLDS.EXACT_MATCH };
54
+ }
55
+ if (normalizedRequest.includes(normalizedPath)) {
56
+ return { path: path2, score: SIMILARITY_THRESHOLDS.CONTAINS_MATCH };
57
+ }
58
+ const overlap = [...normalizedRequest].filter(
59
+ (char) => normalizedPath.includes(char)
60
+ ).length;
61
+ return {
62
+ path: path2,
63
+ score: overlap / normalizedRequest.length * SIMILARITY_THRESHOLDS.PARTIAL_MATCH
64
+ };
65
+ });
66
+ return scored.filter((item) => item.score > SIMILARITY_THRESHOLDS.MIN_SUGGESTION).sort((a, b) => b.score - a.score).slice(0, 3).map((item) => item.path);
67
+ }
68
+ async function pathExists(path2) {
69
+ try {
70
+ await stat(path2);
71
+ return true;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+ async function readMDXFile(filePath) {
77
+ try {
78
+ const fileContent = await readFile(filePath, "utf-8");
79
+ const { content, data } = matter(fileContent);
80
+ const excerptMatch = content.match(/^(.+?)(?:\n\n|$)/);
81
+ const excerpt = excerptMatch ? excerptMatch[1].replace(/^#+ /, "") : void 0;
82
+ return {
83
+ content,
84
+ frontmatter: data,
85
+ excerpt
86
+ };
87
+ } catch (error) {
88
+ logger.error(`Failed to read MDX file: ${filePath}`, error);
89
+ return null;
90
+ }
91
+ }
92
+ function formatMDXContent(mdxContent) {
93
+ const { content, frontmatter } = mdxContent;
94
+ return matter.stringify(content, frontmatter);
95
+ }
96
+
97
+ // src/utils/mcp-format.ts
98
+ function formatMCPResponse(data) {
99
+ return {
100
+ content: [
101
+ {
102
+ type: "text",
103
+ text: typeof data === "string" ? data : JSON.stringify(data, null, 2)
104
+ }
105
+ ]
106
+ };
107
+ }
108
+ function sanitizePath(userPath) {
109
+ if (!userPath || typeof userPath !== "string") {
110
+ throw new Error("Invalid path: Path must be a non-empty string");
111
+ }
112
+ const normalized = normalize(userPath);
113
+ if (path.isAbsolute(normalized)) {
114
+ throw new Error("Invalid path: Absolute paths are not allowed");
115
+ }
116
+ const relativePath = relative("", normalized);
117
+ if (relativePath.startsWith("..")) {
118
+ throw new Error("Invalid path: Directory traversal attempt detected");
119
+ }
120
+ if (relativePath.includes("..")) {
121
+ throw new Error("Invalid path: Path contains invalid traversal sequences");
122
+ }
123
+ if (relativePath.includes("\0")) {
124
+ throw new Error("Invalid path: Path contains null bytes");
125
+ }
126
+ if (process.platform !== "win32") {
127
+ if (normalized.includes("\\")) {
128
+ throw new Error("Invalid path: Backslashes not allowed");
129
+ }
130
+ } else {
131
+ if (normalized.includes(":") || normalized.startsWith("\\\\")) {
132
+ throw new Error("Invalid path: Path contains invalid Windows characters");
133
+ }
134
+ }
135
+ const segments = relativePath.split(path.sep);
136
+ for (const segment of segments) {
137
+ if (segment.startsWith(".") && segment !== ".") {
138
+ throw new Error("Invalid path: Hidden files are not allowed");
139
+ }
140
+ }
141
+ return relativePath;
142
+ }
143
+
144
+ // src/tools/docs.ts
145
+ var docsInputSchema = z.object({
146
+ paths: z.array(z.string()).min(1).describe(
147
+ 'Documentation paths to retrieve (e.g., ["getting-started", "api-reference/primitives/Thread"])'
148
+ )
149
+ });
150
+ async function readDocumentation(docPath) {
151
+ logger.debug(`Reading documentation for path: ${docPath}`);
152
+ if (docPath === "/" || docPath === "") {
153
+ const { directories, files } = await listDirContents(DOCS_PATH);
154
+ return {
155
+ path: "/",
156
+ found: true,
157
+ type: "directory",
158
+ directories,
159
+ files: files.map((f) => f.replace(MDX_EXTENSION, ""))
160
+ };
161
+ }
162
+ try {
163
+ const sanitized = sanitizePath(docPath);
164
+ const fullPath = join(DOCS_PATH, sanitized);
165
+ try {
166
+ const lstats = await lstat(fullPath);
167
+ if (lstats.isSymbolicLink()) {
168
+ logger.warn(`Symlink detected at path: ${fullPath}`);
169
+ return {
170
+ path: docPath,
171
+ found: false,
172
+ error: "Symlinks are not allowed for security reasons"
173
+ };
174
+ }
175
+ } catch {
176
+ }
177
+ if (await pathExists(fullPath)) {
178
+ const stats = await stat(fullPath);
179
+ if (stats.isFile() && stats.size > MAX_FILE_SIZE) {
180
+ logger.warn(`File too large: ${fullPath} (${stats.size} bytes)`);
181
+ return {
182
+ path: docPath,
183
+ found: false,
184
+ error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`
185
+ };
186
+ }
187
+ if (stats.isDirectory()) {
188
+ const { directories, files } = await listDirContents(fullPath);
189
+ const contents = {};
190
+ for (const file of files) {
191
+ const mdxContent = await readMDXFile(join(fullPath, file));
192
+ if (mdxContent) {
193
+ const fileName = file.replace(MDX_EXTENSION, "");
194
+ contents[fileName] = formatMDXContent(mdxContent);
195
+ }
196
+ }
197
+ return {
198
+ path: docPath,
199
+ found: true,
200
+ type: "directory",
201
+ directories,
202
+ files: files.map((f) => f.replace(MDX_EXTENSION, "")),
203
+ content: Object.keys(contents).length > 0 ? JSON.stringify(contents, null, 2) : void 0
204
+ };
205
+ }
206
+ }
207
+ const mdxPath = extname(fullPath) === MDX_EXTENSION ? fullPath : `${fullPath}${MDX_EXTENSION}`;
208
+ try {
209
+ const mdxLstats = await lstat(mdxPath);
210
+ if (mdxLstats.isSymbolicLink()) {
211
+ logger.warn(`Symlink detected at MDX path: ${mdxPath}`);
212
+ return {
213
+ path: docPath,
214
+ found: false,
215
+ error: "Symlinks are not allowed for security reasons"
216
+ };
217
+ }
218
+ if (mdxLstats.size > MAX_FILE_SIZE) {
219
+ logger.warn(`MDX file too large: ${mdxPath} (${mdxLstats.size} bytes)`);
220
+ return {
221
+ path: docPath,
222
+ found: false,
223
+ error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`
224
+ };
225
+ }
226
+ } catch {
227
+ }
228
+ if (await pathExists(mdxPath)) {
229
+ const mdxContent = await readMDXFile(mdxPath);
230
+ if (mdxContent) {
231
+ return {
232
+ path: docPath,
233
+ found: true,
234
+ type: "file",
235
+ content: formatMDXContent(mdxContent)
236
+ };
237
+ }
238
+ }
239
+ const availablePaths = await getAvailablePaths();
240
+ const suggestions = findNearestPaths(docPath, availablePaths);
241
+ return {
242
+ path: docPath,
243
+ found: false,
244
+ suggestions
245
+ };
246
+ } catch (error) {
247
+ if (error instanceof Error && error.message.includes("Invalid path")) {
248
+ return {
249
+ path: docPath,
250
+ found: false,
251
+ error: error.message
252
+ };
253
+ }
254
+ throw error;
255
+ }
256
+ }
257
+ var docsTools = {
258
+ name: "assistantUIDocs",
259
+ description: 'Retrieve assistant-ui documentation by path. Use "/" to list all sections. Supports multiple paths in a single request.',
260
+ parameters: docsInputSchema.shape,
261
+ execute: async ({ paths }) => {
262
+ logger.info(`Retrieving documentation for paths: ${paths.join(", ")}`);
263
+ try {
264
+ const results = await Promise.all(
265
+ paths.map((path2) => readDocumentation(path2))
266
+ );
267
+ if (results.length === 1) {
268
+ const result = results[0];
269
+ if (result.error) {
270
+ return formatMCPResponse({
271
+ error: result.error,
272
+ path: result.path
273
+ });
274
+ }
275
+ if (!result.found) {
276
+ return formatMCPResponse({
277
+ error: `Documentation not found for path: ${result.path}`,
278
+ suggestions: result.suggestions,
279
+ hint: 'Use "/" to list all available documentation sections'
280
+ });
281
+ }
282
+ return formatMCPResponse(result);
283
+ }
284
+ return formatMCPResponse({
285
+ results,
286
+ summary: `Retrieved ${results.filter((r) => r.found).length} of ${results.length} requested paths`
287
+ });
288
+ } catch (error) {
289
+ logger.error("Failed to retrieve documentation", error);
290
+ return formatMCPResponse({
291
+ error: "Failed to retrieve documentation",
292
+ message: error instanceof Error ? error.message : String(error)
293
+ });
294
+ }
295
+ }
296
+ };
297
+ var examplesInputSchema = z.object({
298
+ example: z.string().optional().describe(
299
+ 'Example name (e.g., "with-ai-sdk"). Leave empty to list all examples.'
300
+ )
301
+ });
302
+ async function listCodeExamples() {
303
+ try {
304
+ const files = await readdir(CODE_EXAMPLES_PATH);
305
+ return files.filter((file) => extname(file) === ".md").map((file) => file.replace(".md", "")).sort();
306
+ } catch (error) {
307
+ logger.error("Failed to list code examples", error);
308
+ return [];
309
+ }
310
+ }
311
+ async function readCodeExample(exampleName) {
312
+ try {
313
+ const sanitized = sanitizePath(exampleName);
314
+ const filePath = join(CODE_EXAMPLES_PATH, `${sanitized}.md`);
315
+ const stats = await lstat(filePath);
316
+ if (stats.isSymbolicLink()) {
317
+ logger.warn(`Attempted to read symlink: ${filePath}`);
318
+ return null;
319
+ }
320
+ if (stats.size > MAX_FILE_SIZE) {
321
+ logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);
322
+ return null;
323
+ }
324
+ const content = await readFile(filePath, "utf-8");
325
+ return content;
326
+ } catch (error) {
327
+ logger.error(`Failed to read example: ${exampleName}`, error);
328
+ return null;
329
+ }
330
+ }
331
+ var examplesTools = {
332
+ name: "assistantUIExamples",
333
+ description: "List available examples or retrieve complete code for a specific example",
334
+ parameters: examplesInputSchema.shape,
335
+ execute: async ({ example }) => {
336
+ try {
337
+ if (!example) {
338
+ logger.info("Listing all available examples");
339
+ const examples = await listCodeExamples();
340
+ if (examples.length === 0) {
341
+ return formatMCPResponse({
342
+ error: "No examples found. Please run documentation preparation first.",
343
+ hint: "Run: pnpm prepare-docs"
344
+ });
345
+ }
346
+ return formatMCPResponse({
347
+ type: "list",
348
+ examples,
349
+ total: examples.length,
350
+ hint: "Use example parameter to get complete code for any example"
351
+ });
352
+ }
353
+ logger.info(`Retrieving example: ${example}`);
354
+ const content = await readCodeExample(example);
355
+ if (!content) {
356
+ const availableExamples = await listCodeExamples();
357
+ return formatMCPResponse({
358
+ error: `Example not found: ${example}`,
359
+ availableExamples,
360
+ hint: "Use without example parameter to list all available examples"
361
+ });
362
+ }
363
+ return formatMCPResponse({
364
+ type: "example",
365
+ name: example,
366
+ content
367
+ });
368
+ } catch (error) {
369
+ logger.error("Failed to retrieve examples", error);
370
+ return formatMCPResponse({
371
+ error: "Failed to retrieve examples",
372
+ message: error instanceof Error ? error.message : String(error)
373
+ });
374
+ }
375
+ }
376
+ };
377
+ var __dirname = dirname(fileURLToPath(import.meta.url));
378
+ var packageJson = JSON.parse(
379
+ readFileSync(join(__dirname, "../package.json"), "utf-8")
380
+ );
381
+ var server = new McpServer({
382
+ name: "assistant-ui-docs",
383
+ version: packageJson.version
384
+ });
385
+ server.tool(
386
+ docsTools.name,
387
+ docsTools.description,
388
+ docsTools.parameters,
389
+ docsTools.execute
390
+ );
391
+ server.tool(
392
+ examplesTools.name,
393
+ examplesTools.description,
394
+ examplesTools.parameters,
395
+ examplesTools.execute
396
+ );
397
+ async function runServer() {
398
+ try {
399
+ if (IS_PREPARE_MODE) {
400
+ logger.info("Running in preparation mode...");
401
+ process.exit(0);
402
+ }
403
+ logger.info(
404
+ `Starting assistant-ui MCP docs server v${packageJson.version}`
405
+ );
406
+ const transport = new StdioServerTransport();
407
+ await server.connect(transport);
408
+ } catch (error) {
409
+ logger.error("Failed to start MCP server", error);
410
+ process.exit(1);
411
+ }
412
+ }
413
+ if (import.meta.url === `file://${process.argv[1]}`) {
414
+ void runServer().catch((error) => {
415
+ console.error("Failed to start server:", error);
416
+ process.exit(1);
417
+ });
418
+ }
419
+
420
+ export { runServer, server };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { runServer, server } from './chunk-CZCDQ3YH.js';
@@ -0,0 +1,199 @@
1
+ import { ROOT_DIR, logger, EXAMPLES_PATH } from '../chunk-C7O7EFKU.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
+ }
93
+ }
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}
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
+ }
172
+ }
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
+ }
192
+ if (process.env.PREPARE === "true") {
193
+ prepare().catch((error) => {
194
+ logger.error("Preparation failed", error);
195
+ process.exit(1);
196
+ });
197
+ }
198
+
199
+ export { prepare };
package/dist/stdio.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { runServer } from './chunk-CZCDQ3YH.js';
3
+
4
+ // src/stdio.ts
5
+ void runServer().catch((error) => {
6
+ console.error("Failed to start server:", error);
7
+ process.exit(1);
8
+ });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@assistant-ui/mcp-docs-server",
3
+ "version": "0.1.1",
4
+ "description": "MCP server for assistant-ui documentation and examples",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "assistant-ui-mcp": "./dist/stdio.js"
9
+ },
10
+ "dependencies": {
11
+ "@modelcontextprotocol/sdk": "^1.12.1",
12
+ "zod": "^3.25.57",
13
+ "gray-matter": "^4.0.3",
14
+ "cross-env": "^7.0.3"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^24.0.0",
18
+ "tsup": "^8.5.0",
19
+ "tsx": "^4.19.4",
20
+ "typescript": "^5.8.3",
21
+ "vitest": "^3.2.3",
22
+ "eslint": "^9.28.0"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ ".docs",
27
+ "README.md"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "clean": "rm -rf dist .docs",
34
+ "prepare-docs": "cross-env PREPARE=true node ./dist/prepare-docs/prepare.js",
35
+ "build:cli": "tsup src/stdio.ts src/prepare-docs/prepare.ts src/index.ts --format esm --treeshake=smallest --splitting",
36
+ "build": "pnpm clean && pnpm build:cli && pnpm prepare-docs",
37
+ "dev": "tsx src/stdio.ts",
38
+ "pretest": "pnpm build",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "lint": "eslint ."
42
+ }
43
+ }