@assistant-ui/mcp-docs-server 0.1.17 → 0.1.19
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.
- package/.docs/organized/code-examples/with-ag-ui.md +518 -234
- package/.docs/organized/code-examples/{with-ai-sdk-v5.md → with-ai-sdk-v6.md} +476 -189
- package/.docs/organized/code-examples/with-assistant-transport.md +503 -301
- package/.docs/organized/code-examples/with-cloud.md +524 -226
- package/.docs/organized/code-examples/with-custom-thread-list.md +433 -146
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +2241 -0
- package/.docs/organized/code-examples/with-external-store.md +517 -231
- package/.docs/organized/code-examples/with-ffmpeg.md +500 -220
- package/.docs/organized/code-examples/with-langgraph.md +630 -319
- package/.docs/organized/code-examples/with-parent-id-grouping.md +517 -231
- package/.docs/organized/code-examples/with-react-hook-form.md +517 -233
- package/.docs/organized/code-examples/with-react-router.md +2167 -0
- package/.docs/organized/code-examples/{store-example.md → with-store.md} +18 -22
- package/.docs/organized/code-examples/with-tanstack.md +23 -41
- package/.docs/raw/blog/2025-01-31-changelog/index.mdx +0 -2
- package/.docs/raw/docs/{about-assistantui.mdx → (docs)/about-assistantui.mdx} +2 -1
- package/.docs/raw/docs/{architecture.mdx → (docs)/architecture.mdx} +3 -2
- package/.docs/raw/docs/{cli.mdx → (docs)/cli.mdx} +1 -19
- package/.docs/raw/docs/{copilots → (docs)/copilots}/make-assistant-readable.mdx +1 -0
- package/.docs/raw/docs/{copilots → (docs)/copilots}/make-assistant-tool-ui.mdx +2 -1
- package/.docs/raw/docs/{copilots → (docs)/copilots}/make-assistant-tool.mdx +2 -1
- package/.docs/raw/docs/{copilots → (docs)/copilots}/model-context.mdx +1 -0
- package/.docs/raw/docs/{copilots → (docs)/copilots}/motivation.mdx +1 -0
- package/.docs/raw/docs/{copilots → (docs)/copilots}/use-assistant-instructions.mdx +1 -0
- package/.docs/raw/docs/{devtools.mdx → (docs)/devtools.mdx} +4 -4
- package/.docs/raw/docs/{guides/Attachments.mdx → (docs)/guides/attachments.mdx} +4 -5
- package/.docs/raw/docs/{guides/Branching.mdx → (docs)/guides/branching.mdx} +2 -1
- package/.docs/raw/docs/{guides → (docs)/guides}/context-api.mdx +1 -0
- package/.docs/raw/docs/(docs)/guides/dictation.mdx +370 -0
- package/.docs/raw/docs/{guides/Editing.mdx → (docs)/guides/editing.mdx} +1 -0
- package/.docs/raw/docs/{guides/Latex.mdx → (docs)/guides/latex.mdx} +1 -2
- package/.docs/raw/docs/{guides/Speech.mdx → (docs)/guides/speech.mdx} +9 -10
- package/.docs/raw/docs/{guides/ToolUI.mdx → (docs)/guides/tool-ui.mdx} +15 -14
- package/.docs/raw/docs/{guides/Tools.mdx → (docs)/guides/tools.mdx} +10 -7
- package/.docs/raw/docs/{getting-started.mdx → (docs)/index.mdx} +17 -22
- package/.docs/raw/docs/{mcp-docs-server.mdx → (docs)/mcp-docs-server.mdx} +1 -2
- package/.docs/raw/docs/{api-reference/context-providers/AssistantRuntimeProvider.mdx → (reference)/api-reference/context-providers/assistant-runtime-provider.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/context-providers/TextMessagePartProvider.mdx → (reference)/api-reference/context-providers/text-message-part-provider.mdx} +2 -1
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/integrations/react-data-stream.mdx +2 -1
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/integrations/react-hook-form.mdx +2 -1
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/integrations/vercel-ai-sdk.mdx +2 -2
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/overview.mdx +1 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +327 -0
- package/.docs/raw/docs/{api-reference/primitives/ActionBar.mdx → (reference)/api-reference/primitives/action-bar.mdx} +3 -1
- package/.docs/raw/docs/{api-reference/primitives/AssistantIf.mdx → (reference)/api-reference/primitives/assistant-if.mdx} +2 -2
- package/.docs/raw/docs/{api-reference/primitives/AssistantModal.mdx → (reference)/api-reference/primitives/assistant-modal.mdx} +3 -1
- package/.docs/raw/docs/{api-reference/primitives/Attachment.mdx → (reference)/api-reference/primitives/attachment.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/primitives/BranchPicker.mdx → (reference)/api-reference/primitives/branch-picker.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/Composer.mdx → (reference)/api-reference/primitives/composer.mdx} +101 -2
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/primitives/composition.mdx +1 -0
- package/.docs/raw/docs/{api-reference/primitives/Error.mdx → (reference)/api-reference/primitives/error.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/MessagePart.mdx → (reference)/api-reference/primitives/message-part.mdx} +2 -2
- package/.docs/raw/docs/{api-reference/primitives/Message.mdx → (reference)/api-reference/primitives/message.mdx} +2 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +221 -0
- package/.docs/raw/docs/{api-reference/primitives/ThreadListItem.mdx → (reference)/api-reference/primitives/thread-list-item.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/ThreadList.mdx → (reference)/api-reference/primitives/thread-list.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/Thread.mdx → (reference)/api-reference/primitives/thread.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/AssistantRuntime.mdx → (reference)/api-reference/runtimes/assistant-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/AttachmentRuntime.mdx → (reference)/api-reference/runtimes/attachment-runtime.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/runtimes/ComposerRuntime.mdx → (reference)/api-reference/runtimes/composer-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/MessagePartRuntime.mdx → (reference)/api-reference/runtimes/message-part-runtime.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/runtimes/MessageRuntime.mdx → (reference)/api-reference/runtimes/message-runtime.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/runtimes/ThreadListItemRuntime.mdx → (reference)/api-reference/runtimes/thread-list-item-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/ThreadListRuntime.mdx → (reference)/api-reference/runtimes/thread-list-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/ThreadRuntime.mdx → (reference)/api-reference/runtimes/thread-runtime.mdx} +3 -5
- package/.docs/raw/docs/{legacy/styled/AssistantModal.mdx → (reference)/legacy/styled/assistant-modal.mdx} +2 -3
- package/.docs/raw/docs/{legacy/styled/Decomposition.mdx → (reference)/legacy/styled/decomposition.mdx} +1 -0
- package/.docs/raw/docs/{legacy/styled/Markdown.mdx → (reference)/legacy/styled/markdown.mdx} +2 -4
- package/.docs/raw/docs/{legacy/styled/Scrollbar.mdx → (reference)/legacy/styled/scrollbar.mdx} +2 -1
- package/.docs/raw/docs/{legacy/styled/ThreadWidth.mdx → (reference)/legacy/styled/thread-width.mdx} +1 -0
- package/.docs/raw/docs/{legacy/styled/Thread.mdx → (reference)/legacy/styled/thread.mdx} +2 -3
- package/.docs/raw/docs/{migrations → (reference)/migrations}/deprecation-policy.mdx +1 -0
- package/.docs/raw/docs/{migrations → (reference)/migrations}/react-langgraph-v0-7.mdx +1 -2
- package/.docs/raw/docs/{migrations → (reference)/migrations}/v0-11.mdx +1 -0
- package/.docs/raw/docs/{migrations → (reference)/migrations}/v0-12.mdx +1 -0
- package/.docs/raw/docs/{react-compatibility.mdx → (reference)/react-compatibility.mdx} +2 -3
- package/.docs/raw/docs/cloud/authorization.mdx +1 -0
- package/.docs/raw/docs/cloud/overview.mdx +1 -0
- package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +2 -3
- package/.docs/raw/docs/cloud/persistence/langgraph.mdx +5 -7
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +9 -8
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +2 -3
- package/.docs/raw/docs/runtimes/assistant-transport.mdx +7 -6
- package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +38 -3
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +6 -8
- package/.docs/raw/docs/runtimes/custom/local.mdx +43 -16
- package/.docs/raw/docs/runtimes/data-stream.mdx +32 -4
- package/.docs/raw/docs/runtimes/helicone.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/index.mdx +3 -3
- package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +2 -1
- package/.docs/raw/docs/runtimes/langserve.mdx +2 -2
- package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +4 -5
- package/.docs/raw/docs/runtimes/mastra/overview.mdx +1 -0
- package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +3 -4
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +2 -4
- package/.docs/raw/docs/ui/assistant-modal.mdx +163 -0
- package/.docs/raw/docs/ui/assistant-sidebar.mdx +90 -0
- package/.docs/raw/docs/ui/attachment.mdx +227 -0
- package/.docs/raw/docs/ui/{Markdown.mdx → markdown.mdx} +11 -6
- package/.docs/raw/docs/ui/{Mermaid.mdx → mermaid.mdx} +12 -5
- package/.docs/raw/docs/ui/{PartGrouping.mdx → part-grouping.mdx} +4 -6
- package/.docs/raw/docs/ui/reasoning.mdx +148 -0
- package/.docs/raw/docs/ui/{Scrollbar.mdx → scrollbar.mdx} +9 -7
- package/.docs/raw/docs/ui/sources.mdx +87 -0
- package/.docs/raw/docs/ui/{SyntaxHighlighting.mdx → syntax-highlighting.mdx} +9 -5
- package/.docs/raw/docs/ui/thread-list.mdx +275 -0
- package/.docs/raw/docs/ui/{Thread.mdx → thread.mdx} +5 -6
- package/.docs/raw/docs/ui/tool-fallback.mdx +112 -0
- package/.docs/raw/docs/ui/tool-group.mdx +214 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -0
- package/dist/prepare-docs/code-examples.d.ts +2 -0
- package/dist/prepare-docs/code-examples.d.ts.map +1 -0
- package/dist/prepare-docs/code-examples.js +129 -0
- package/dist/prepare-docs/code-examples.js.map +1 -0
- package/dist/prepare-docs/copy-raw.d.ts +2 -0
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -0
- package/dist/prepare-docs/copy-raw.js +50 -0
- package/dist/prepare-docs/copy-raw.js.map +1 -0
- package/dist/prepare-docs/prepare.d.ts +2 -0
- package/dist/prepare-docs/prepare.d.ts.map +1 -0
- package/dist/prepare-docs/prepare.js +18 -195
- package/dist/prepare-docs/prepare.js.map +1 -0
- package/dist/stdio.d.ts +3 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +4 -5
- package/dist/stdio.js.map +1 -0
- package/dist/tools/docs.d.ts +23 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +168 -0
- package/dist/tools/docs.js.map +1 -0
- package/dist/tools/examples.d.ts +23 -0
- package/dist/tools/examples.d.ts.map +1 -0
- package/dist/tools/examples.js +95 -0
- package/dist/tools/examples.js.map +1 -0
- package/dist/tools/tests/test-setup.d.ts +4 -0
- package/dist/tools/tests/test-setup.d.ts.map +1 -0
- package/dist/tools/tests/test-setup.js +36 -0
- package/dist/tools/tests/test-setup.js.map +1 -0
- package/dist/utils/logger.d.ts +7 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +20 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mcp-format.d.ts +7 -0
- package/dist/utils/mcp-format.d.ts.map +1 -0
- package/dist/utils/mcp-format.js +11 -0
- package/dist/utils/mcp-format.js.map +1 -0
- package/dist/utils/mdx.d.ts +9 -0
- package/dist/utils/mdx.d.ts.map +1 -0
- package/dist/utils/mdx.js +27 -0
- package/dist/utils/mdx.js.map +1 -0
- package/dist/utils/paths.d.ts +8 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +84 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/security.d.ts +2 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +43 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +37 -19
- package/src/constants.ts +22 -0
- package/src/index.ts +51 -0
- package/src/prepare-docs/code-examples.ts +158 -0
- package/src/prepare-docs/copy-raw.ts +55 -0
- package/src/prepare-docs/prepare.ts +24 -0
- package/src/stdio.ts +7 -0
- package/src/tools/docs.ts +207 -0
- package/src/tools/examples.ts +107 -0
- package/src/tools/tests/docs.test.ts +124 -0
- package/src/tools/tests/examples.test.ts +94 -0
- package/src/tools/tests/integration.test.ts +46 -0
- package/src/tools/tests/json-parsing.test.ts +23 -0
- package/src/tools/tests/mcp-protocol.test.ts +133 -0
- package/src/tools/tests/path-traversal.test.ts +81 -0
- package/src/tools/tests/test-setup.ts +40 -0
- package/src/utils/logger.ts +20 -0
- package/src/utils/mcp-format.ts +12 -0
- package/src/utils/mdx.ts +39 -0
- package/src/utils/paths.ts +114 -0
- package/src/utils/security.ts +52 -0
- package/src/utils/tests/security.test.ts +119 -0
- package/.docs/raw/docs/index.mdx +0 -7
- package/.docs/raw/docs/ui/AssistantModal.mdx +0 -45
- package/.docs/raw/docs/ui/AssistantSidebar.mdx +0 -41
- package/.docs/raw/docs/ui/Attachment.mdx +0 -84
- package/.docs/raw/docs/ui/Reasoning.mdx +0 -152
- package/.docs/raw/docs/ui/ThreadList.mdx +0 -90
- package/.docs/raw/docs/ui/ToolFallback.mdx +0 -63
- package/.docs/raw/docs/ui/ToolGroup.mdx +0 -96
- package/dist/chunk-M2RKUM66.js +0 -38
- package/dist/chunk-NVNFQ5ZO.js +0 -423
- /package/.docs/raw/docs/{copilots → (docs)/copilots}/assistant-frame.mdx +0 -0
package/dist/chunk-NVNFQ5ZO.js
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import { logger, IS_PREPARE_MODE, MDX_EXTENSION, DOCS_PATH, MAX_FILE_SIZE, CODE_EXAMPLES_PATH, MD_EXTENSION } from './chunk-M2RKUM66.js';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import { z } from 'zod/v3';
|
|
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
|
-
if (userPath.includes("../") || userPath.includes("..\\")) {
|
|
113
|
-
throw new Error("Invalid path: Directory traversal attempt detected");
|
|
114
|
-
}
|
|
115
|
-
const normalized = normalize(userPath);
|
|
116
|
-
if (path.isAbsolute(normalized)) {
|
|
117
|
-
throw new Error("Invalid path: Absolute paths are not allowed");
|
|
118
|
-
}
|
|
119
|
-
const relativePath = relative("", normalized);
|
|
120
|
-
if (relativePath.startsWith("..")) {
|
|
121
|
-
throw new Error("Invalid path: Directory traversal attempt detected");
|
|
122
|
-
}
|
|
123
|
-
if (relativePath.includes("..")) {
|
|
124
|
-
throw new Error("Invalid path: Path contains invalid traversal sequences");
|
|
125
|
-
}
|
|
126
|
-
if (relativePath.includes("\0")) {
|
|
127
|
-
throw new Error("Invalid path: Path contains null bytes");
|
|
128
|
-
}
|
|
129
|
-
if (process.platform !== "win32") {
|
|
130
|
-
if (normalized.includes("\\")) {
|
|
131
|
-
throw new Error("Invalid path: Backslashes not allowed");
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
if (normalized.includes(":") || normalized.startsWith("\\\\")) {
|
|
135
|
-
throw new Error("Invalid path: Path contains invalid Windows characters");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const segments = relativePath.split(path.sep);
|
|
139
|
-
for (const segment of segments) {
|
|
140
|
-
if (segment.startsWith(".") && segment !== ".") {
|
|
141
|
-
throw new Error("Invalid path: Hidden files are not allowed");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return relativePath.replace(/\\/g, "/");
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// src/tools/docs.ts
|
|
148
|
-
var docsInputSchema = z.object({
|
|
149
|
-
paths: z.array(z.string()).min(1).describe(
|
|
150
|
-
'Documentation paths to retrieve (e.g., ["getting-started", "api-reference/primitives/Thread"])'
|
|
151
|
-
)
|
|
152
|
-
});
|
|
153
|
-
async function readDocumentation(docPath) {
|
|
154
|
-
logger.debug(`Reading documentation for path: ${docPath}`);
|
|
155
|
-
if (docPath === "/" || docPath === "") {
|
|
156
|
-
const { directories, files } = await listDirContents(DOCS_PATH);
|
|
157
|
-
return {
|
|
158
|
-
path: "/",
|
|
159
|
-
found: true,
|
|
160
|
-
type: "directory",
|
|
161
|
-
directories,
|
|
162
|
-
files: files.map((f) => f.replace(MDX_EXTENSION, ""))
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
const sanitized = sanitizePath(docPath);
|
|
167
|
-
const fullPath = join(DOCS_PATH, sanitized);
|
|
168
|
-
try {
|
|
169
|
-
const lstats = await lstat(fullPath);
|
|
170
|
-
if (lstats.isSymbolicLink()) {
|
|
171
|
-
logger.warn(`Symlink detected at path: ${fullPath}`);
|
|
172
|
-
return {
|
|
173
|
-
path: docPath,
|
|
174
|
-
found: false,
|
|
175
|
-
error: "Symlinks are not allowed for security reasons"
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
} catch {
|
|
179
|
-
}
|
|
180
|
-
if (await pathExists(fullPath)) {
|
|
181
|
-
const stats = await stat(fullPath);
|
|
182
|
-
if (stats.isFile() && stats.size > MAX_FILE_SIZE) {
|
|
183
|
-
logger.warn(`File too large: ${fullPath} (${stats.size} bytes)`);
|
|
184
|
-
return {
|
|
185
|
-
path: docPath,
|
|
186
|
-
found: false,
|
|
187
|
-
error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
if (stats.isDirectory()) {
|
|
191
|
-
const { directories, files } = await listDirContents(fullPath);
|
|
192
|
-
const contents = {};
|
|
193
|
-
for (const file of files) {
|
|
194
|
-
const mdxContent = await readMDXFile(join(fullPath, file));
|
|
195
|
-
if (mdxContent) {
|
|
196
|
-
const fileName = file.replace(MDX_EXTENSION, "");
|
|
197
|
-
contents[fileName] = formatMDXContent(mdxContent);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return {
|
|
201
|
-
path: docPath,
|
|
202
|
-
found: true,
|
|
203
|
-
type: "directory",
|
|
204
|
-
directories,
|
|
205
|
-
files: files.map((f) => f.replace(MDX_EXTENSION, "")),
|
|
206
|
-
content: Object.keys(contents).length > 0 ? JSON.stringify(contents, null, 2) : void 0
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const mdxPath = extname(fullPath) === MDX_EXTENSION ? fullPath : `${fullPath}${MDX_EXTENSION}`;
|
|
211
|
-
try {
|
|
212
|
-
const mdxLstats = await lstat(mdxPath);
|
|
213
|
-
if (mdxLstats.isSymbolicLink()) {
|
|
214
|
-
logger.warn(`Symlink detected at MDX path: ${mdxPath}`);
|
|
215
|
-
return {
|
|
216
|
-
path: docPath,
|
|
217
|
-
found: false,
|
|
218
|
-
error: "Symlinks are not allowed for security reasons"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
if (mdxLstats.size > MAX_FILE_SIZE) {
|
|
222
|
-
logger.warn(`MDX file too large: ${mdxPath} (${mdxLstats.size} bytes)`);
|
|
223
|
-
return {
|
|
224
|
-
path: docPath,
|
|
225
|
-
found: false,
|
|
226
|
-
error: `File size exceeds maximum allowed size of ${MAX_FILE_SIZE} bytes`
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
} catch {
|
|
230
|
-
}
|
|
231
|
-
if (await pathExists(mdxPath)) {
|
|
232
|
-
const mdxContent = await readMDXFile(mdxPath);
|
|
233
|
-
if (mdxContent) {
|
|
234
|
-
return {
|
|
235
|
-
path: docPath,
|
|
236
|
-
found: true,
|
|
237
|
-
type: "file",
|
|
238
|
-
content: formatMDXContent(mdxContent)
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const availablePaths = await getAvailablePaths();
|
|
243
|
-
const suggestions = findNearestPaths(docPath, availablePaths);
|
|
244
|
-
return {
|
|
245
|
-
path: docPath,
|
|
246
|
-
found: false,
|
|
247
|
-
suggestions
|
|
248
|
-
};
|
|
249
|
-
} catch (error) {
|
|
250
|
-
if (error instanceof Error && error.message.includes("Invalid path")) {
|
|
251
|
-
return {
|
|
252
|
-
path: docPath,
|
|
253
|
-
found: false,
|
|
254
|
-
error: error.message
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
var docsTools = {
|
|
261
|
-
name: "assistantUIDocs",
|
|
262
|
-
description: 'Retrieve assistant-ui documentation by path. Use "/" to list all sections. Supports multiple paths in a single request.',
|
|
263
|
-
parameters: docsInputSchema.shape,
|
|
264
|
-
execute: async ({ paths }) => {
|
|
265
|
-
logger.info(`Retrieving documentation for paths: ${paths.join(", ")}`);
|
|
266
|
-
try {
|
|
267
|
-
const results = await Promise.all(
|
|
268
|
-
paths.map((path2) => readDocumentation(path2))
|
|
269
|
-
);
|
|
270
|
-
if (results.length === 1) {
|
|
271
|
-
const result = results[0];
|
|
272
|
-
if (result.error) {
|
|
273
|
-
return formatMCPResponse({
|
|
274
|
-
error: result.error,
|
|
275
|
-
path: result.path
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
if (!result.found) {
|
|
279
|
-
return formatMCPResponse({
|
|
280
|
-
error: `Documentation not found for path: ${result.path}`,
|
|
281
|
-
suggestions: result.suggestions,
|
|
282
|
-
hint: 'Use "/" to list all available documentation sections'
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return formatMCPResponse(result);
|
|
286
|
-
}
|
|
287
|
-
return formatMCPResponse({
|
|
288
|
-
results,
|
|
289
|
-
summary: `Retrieved ${results.filter((r) => r.found).length} of ${results.length} requested paths`
|
|
290
|
-
});
|
|
291
|
-
} catch (error) {
|
|
292
|
-
logger.error("Failed to retrieve documentation", error);
|
|
293
|
-
return formatMCPResponse({
|
|
294
|
-
error: "Failed to retrieve documentation",
|
|
295
|
-
message: error instanceof Error ? error.message : String(error)
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
var examplesInputSchema = z.object({
|
|
301
|
-
example: z.string().optional().describe(
|
|
302
|
-
'Example name (e.g., "with-ai-sdk"). Leave empty to list all examples.'
|
|
303
|
-
)
|
|
304
|
-
});
|
|
305
|
-
async function listCodeExamples() {
|
|
306
|
-
try {
|
|
307
|
-
const files = await readdir(CODE_EXAMPLES_PATH);
|
|
308
|
-
return files.filter((file) => extname(file) === ".md").map((file) => file.replace(".md", "")).sort();
|
|
309
|
-
} catch (error) {
|
|
310
|
-
logger.error("Failed to list code examples", error);
|
|
311
|
-
return [];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
async function readCodeExample(exampleName) {
|
|
315
|
-
try {
|
|
316
|
-
const sanitized = sanitizePath(exampleName);
|
|
317
|
-
const filePath = join(CODE_EXAMPLES_PATH, `${sanitized}.md`);
|
|
318
|
-
const stats = await lstat(filePath);
|
|
319
|
-
if (stats.isSymbolicLink()) {
|
|
320
|
-
logger.warn(`Attempted to read symlink: ${filePath}`);
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
if (stats.size > MAX_FILE_SIZE) {
|
|
324
|
-
logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
const content = await readFile(filePath, "utf-8");
|
|
328
|
-
return content;
|
|
329
|
-
} catch (error) {
|
|
330
|
-
logger.error(`Failed to read example: ${exampleName}`, error);
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
var examplesTools = {
|
|
335
|
-
name: "assistantUIExamples",
|
|
336
|
-
description: "List available examples or retrieve complete code for a specific example",
|
|
337
|
-
parameters: examplesInputSchema.shape,
|
|
338
|
-
execute: async ({ example }) => {
|
|
339
|
-
try {
|
|
340
|
-
if (!example) {
|
|
341
|
-
logger.info("Listing all available examples");
|
|
342
|
-
const examples = await listCodeExamples();
|
|
343
|
-
if (examples.length === 0) {
|
|
344
|
-
return formatMCPResponse({
|
|
345
|
-
error: "No examples found. Please run documentation preparation first.",
|
|
346
|
-
hint: "Run: pnpm prepare-docs"
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
return formatMCPResponse({
|
|
350
|
-
type: "list",
|
|
351
|
-
examples,
|
|
352
|
-
total: examples.length,
|
|
353
|
-
hint: "Use example parameter to get complete code for any example"
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
logger.info(`Retrieving example: ${example}`);
|
|
357
|
-
const content = await readCodeExample(example);
|
|
358
|
-
if (!content) {
|
|
359
|
-
const availableExamples = await listCodeExamples();
|
|
360
|
-
return formatMCPResponse({
|
|
361
|
-
error: `Example not found: ${example}`,
|
|
362
|
-
availableExamples,
|
|
363
|
-
hint: "Use without example parameter to list all available examples"
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
return formatMCPResponse({
|
|
367
|
-
type: "example",
|
|
368
|
-
name: example,
|
|
369
|
-
content
|
|
370
|
-
});
|
|
371
|
-
} catch (error) {
|
|
372
|
-
logger.error("Failed to retrieve examples", error);
|
|
373
|
-
return formatMCPResponse({
|
|
374
|
-
error: "Failed to retrieve examples",
|
|
375
|
-
message: error instanceof Error ? error.message : String(error)
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
var __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
381
|
-
var packageJson = JSON.parse(
|
|
382
|
-
readFileSync(join(__dirname$1, "../package.json"), "utf-8")
|
|
383
|
-
);
|
|
384
|
-
var server = new McpServer({
|
|
385
|
-
name: "assistant-ui-docs",
|
|
386
|
-
version: packageJson.version
|
|
387
|
-
});
|
|
388
|
-
server.tool(
|
|
389
|
-
docsTools.name,
|
|
390
|
-
docsTools.description,
|
|
391
|
-
docsTools.parameters,
|
|
392
|
-
docsTools.execute
|
|
393
|
-
);
|
|
394
|
-
server.tool(
|
|
395
|
-
examplesTools.name,
|
|
396
|
-
examplesTools.description,
|
|
397
|
-
examplesTools.parameters,
|
|
398
|
-
examplesTools.execute
|
|
399
|
-
);
|
|
400
|
-
async function runServer() {
|
|
401
|
-
try {
|
|
402
|
-
if (IS_PREPARE_MODE) {
|
|
403
|
-
logger.info("Running in preparation mode...");
|
|
404
|
-
process.exit(0);
|
|
405
|
-
}
|
|
406
|
-
logger.info(
|
|
407
|
-
`Starting assistant-ui MCP docs server v${packageJson.version}`
|
|
408
|
-
);
|
|
409
|
-
const transport = new StdioServerTransport();
|
|
410
|
-
await server.connect(transport);
|
|
411
|
-
} catch (error) {
|
|
412
|
-
logger.error("Failed to start MCP server", error);
|
|
413
|
-
process.exit(1);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
417
|
-
void runServer().catch((error) => {
|
|
418
|
-
console.error("Failed to start server:", error);
|
|
419
|
-
process.exit(1);
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export { runServer, server };
|
|
File without changes
|