docusaurus-plugin-mcp-server 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -35
- package/dist/adapters-entry.d.mts +48 -3
- package/dist/adapters-entry.d.ts +48 -3
- package/dist/adapters-entry.js +182 -188
- package/dist/adapters-entry.js.map +1 -1
- package/dist/adapters-entry.mjs +181 -189
- package/dist/adapters-entry.mjs.map +1 -1
- package/dist/cli/verify.js +45 -173
- package/dist/cli/verify.js.map +1 -1
- package/dist/cli/verify.mjs +45 -173
- package/dist/cli/verify.mjs.map +1 -1
- package/dist/{index-4g0ZZK3z.d.mts → index-j-CdaS6k.d.mts} +8 -15
- package/dist/{index-4g0ZZK3z.d.ts → index-j-CdaS6k.d.ts} +8 -15
- package/dist/index.d.mts +19 -54
- package/dist/index.d.ts +19 -54
- package/dist/index.js +54 -274
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -270
- package/dist/index.mjs.map +1 -1
- package/dist/theme/index.d.mts +1 -1
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.js +0 -4
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/index.mjs +1 -2
- package/dist/theme/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { unified } from 'unified';
|
|
|
5
5
|
import rehypeParse from 'rehype-parse';
|
|
6
6
|
import { select } from 'hast-util-select';
|
|
7
7
|
import { toString } from 'hast-util-to-string';
|
|
8
|
+
import { toHtml } from 'hast-util-to-html';
|
|
8
9
|
import rehypeRemark from 'rehype-remark';
|
|
9
10
|
import remarkStringify from 'remark-stringify';
|
|
10
11
|
import remarkGfm from 'remark-gfm';
|
|
@@ -182,7 +183,7 @@ async function extractContent(filePath, options) {
|
|
|
182
183
|
let contentHtml = "";
|
|
183
184
|
if (contentElement) {
|
|
184
185
|
const cleanedElement = cleanContentElement(contentElement, options.excludeSelectors);
|
|
185
|
-
contentHtml =
|
|
186
|
+
contentHtml = toHtml(cleanedElement);
|
|
186
187
|
}
|
|
187
188
|
return {
|
|
188
189
|
title,
|
|
@@ -190,57 +191,6 @@ async function extractContent(filePath, options) {
|
|
|
190
191
|
contentHtml
|
|
191
192
|
};
|
|
192
193
|
}
|
|
193
|
-
function serializeElement(element) {
|
|
194
|
-
const voidElements = /* @__PURE__ */ new Set([
|
|
195
|
-
"area",
|
|
196
|
-
"base",
|
|
197
|
-
"br",
|
|
198
|
-
"col",
|
|
199
|
-
"embed",
|
|
200
|
-
"hr",
|
|
201
|
-
"img",
|
|
202
|
-
"input",
|
|
203
|
-
"link",
|
|
204
|
-
"meta",
|
|
205
|
-
"param",
|
|
206
|
-
"source",
|
|
207
|
-
"track",
|
|
208
|
-
"wbr"
|
|
209
|
-
]);
|
|
210
|
-
function serialize(node) {
|
|
211
|
-
if (!node || typeof node !== "object") return "";
|
|
212
|
-
const n = node;
|
|
213
|
-
if (n.type === "text") {
|
|
214
|
-
return n.value ?? "";
|
|
215
|
-
}
|
|
216
|
-
if (n.type === "element" && n.tagName) {
|
|
217
|
-
const tagName = n.tagName;
|
|
218
|
-
const props = n.properties ?? {};
|
|
219
|
-
const attrs = [];
|
|
220
|
-
for (const [key, value] of Object.entries(props)) {
|
|
221
|
-
if (key === "className" && Array.isArray(value)) {
|
|
222
|
-
attrs.push(`class="${value.join(" ")}"`);
|
|
223
|
-
} else if (typeof value === "boolean") {
|
|
224
|
-
if (value) attrs.push(key);
|
|
225
|
-
} else if (value !== void 0 && value !== null) {
|
|
226
|
-
attrs.push(`${key}="${String(value)}"`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const attrStr = attrs.length > 0 ? " " + attrs.join(" ") : "";
|
|
230
|
-
if (voidElements.has(tagName)) {
|
|
231
|
-
return `<${tagName}${attrStr} />`;
|
|
232
|
-
}
|
|
233
|
-
const children = n.children ?? [];
|
|
234
|
-
const childrenHtml = children.map(serialize).join("");
|
|
235
|
-
return `<${tagName}${attrStr}>${childrenHtml}</${tagName}>`;
|
|
236
|
-
}
|
|
237
|
-
if (n.type === "root" && n.children) {
|
|
238
|
-
return n.children.map(serialize).join("");
|
|
239
|
-
}
|
|
240
|
-
return "";
|
|
241
|
-
}
|
|
242
|
-
return serialize(element);
|
|
243
|
-
}
|
|
244
194
|
async function htmlToMarkdown(html) {
|
|
245
195
|
if (!html || html.trim().length === 0) {
|
|
246
196
|
return "";
|
|
@@ -377,9 +327,10 @@ function createSearchIndex() {
|
|
|
377
327
|
}
|
|
378
328
|
});
|
|
379
329
|
}
|
|
380
|
-
function addDocumentToIndex(index, doc) {
|
|
330
|
+
function addDocumentToIndex(index, doc, baseUrl) {
|
|
331
|
+
const id = baseUrl ? `${baseUrl.replace(/\/$/, "")}${doc.route}` : doc.route;
|
|
381
332
|
const indexable = {
|
|
382
|
-
id
|
|
333
|
+
id,
|
|
383
334
|
title: doc.title,
|
|
384
335
|
content: doc.markdown,
|
|
385
336
|
headings: doc.headings.map((h) => h.text).join(" "),
|
|
@@ -387,10 +338,10 @@ function addDocumentToIndex(index, doc) {
|
|
|
387
338
|
};
|
|
388
339
|
index.add(indexable);
|
|
389
340
|
}
|
|
390
|
-
function buildSearchIndex(docs) {
|
|
341
|
+
function buildSearchIndex(docs, baseUrl) {
|
|
391
342
|
const index = createSearchIndex();
|
|
392
343
|
for (const doc of docs) {
|
|
393
|
-
addDocumentToIndex(index, doc);
|
|
344
|
+
addDocumentToIndex(index, doc, baseUrl);
|
|
394
345
|
}
|
|
395
346
|
return index;
|
|
396
347
|
}
|
|
@@ -421,6 +372,8 @@ function searchIndex(index, docs, query, options = {}) {
|
|
|
421
372
|
const doc = docs[docId];
|
|
422
373
|
if (!doc) continue;
|
|
423
374
|
results.push({
|
|
375
|
+
url: docId,
|
|
376
|
+
// docId is the full URL when indexed with baseUrl
|
|
424
377
|
route: doc.route,
|
|
425
378
|
title: doc.title,
|
|
426
379
|
score,
|
|
@@ -495,6 +448,7 @@ async function importSearchIndex(data) {
|
|
|
495
448
|
// src/providers/indexers/flexsearch-indexer.ts
|
|
496
449
|
var FlexSearchIndexer = class {
|
|
497
450
|
name = "flexsearch";
|
|
451
|
+
baseUrl = "";
|
|
498
452
|
docsIndex = {};
|
|
499
453
|
exportedIndex = null;
|
|
500
454
|
docCount = 0;
|
|
@@ -505,7 +459,8 @@ var FlexSearchIndexer = class {
|
|
|
505
459
|
shouldRun() {
|
|
506
460
|
return true;
|
|
507
461
|
}
|
|
508
|
-
async initialize(
|
|
462
|
+
async initialize(context) {
|
|
463
|
+
this.baseUrl = context.baseUrl.replace(/\/$/, "");
|
|
509
464
|
this.docsIndex = {};
|
|
510
465
|
this.exportedIndex = null;
|
|
511
466
|
this.docCount = 0;
|
|
@@ -513,10 +468,11 @@ var FlexSearchIndexer = class {
|
|
|
513
468
|
async indexDocuments(docs) {
|
|
514
469
|
this.docCount = docs.length;
|
|
515
470
|
for (const doc of docs) {
|
|
516
|
-
this.
|
|
471
|
+
const fullUrl = `${this.baseUrl}${doc.route}`;
|
|
472
|
+
this.docsIndex[fullUrl] = doc;
|
|
517
473
|
}
|
|
518
474
|
console.log("[FlexSearch] Building search index...");
|
|
519
|
-
const searchIndex2 = buildSearchIndex(docs);
|
|
475
|
+
const searchIndex2 = buildSearchIndex(docs, this.baseUrl);
|
|
520
476
|
this.exportedIndex = await exportSearchIndex(searchIndex2);
|
|
521
477
|
console.log(`[FlexSearch] Indexed ${this.docCount} documents`);
|
|
522
478
|
}
|
|
@@ -576,16 +532,11 @@ var FlexSearchProvider = class {
|
|
|
576
532
|
const limit = options?.limit ?? 5;
|
|
577
533
|
return searchIndex(this.searchIndex, this.docs, query, { limit });
|
|
578
534
|
}
|
|
579
|
-
async getDocument(
|
|
535
|
+
async getDocument(url) {
|
|
580
536
|
if (!this.docs) {
|
|
581
537
|
throw new Error("[FlexSearch] Provider not initialized");
|
|
582
538
|
}
|
|
583
|
-
|
|
584
|
-
return this.docs[route];
|
|
585
|
-
}
|
|
586
|
-
const normalizedRoute = route.startsWith("/") ? route : `/${route}`;
|
|
587
|
-
const withoutSlash = route.startsWith("/") ? route.slice(1) : route;
|
|
588
|
-
return this.docs[normalizedRoute] ?? this.docs[withoutSlash] ?? null;
|
|
539
|
+
return this.docs[url] ?? null;
|
|
589
540
|
}
|
|
590
541
|
async healthCheck() {
|
|
591
542
|
if (!this.isReady()) {
|
|
@@ -818,28 +769,16 @@ function mcpServerPlugin(context, options) {
|
|
|
818
769
|
}
|
|
819
770
|
};
|
|
820
771
|
}
|
|
821
|
-
|
|
822
|
-
|
|
772
|
+
var docsSearchInputSchema = {
|
|
773
|
+
query: z.string().min(1).describe("The search query string"),
|
|
774
|
+
limit: z.number().int().min(1).max(20).optional().default(5).describe("Maximum number of results to return (1-20, default: 5)")
|
|
775
|
+
};
|
|
823
776
|
var docsSearchTool = {
|
|
824
777
|
name: "docs_search",
|
|
825
|
-
description: "Search
|
|
826
|
-
inputSchema:
|
|
827
|
-
type: "object",
|
|
828
|
-
properties: {
|
|
829
|
-
query: {
|
|
830
|
-
type: "string",
|
|
831
|
-
description: "Search query string"
|
|
832
|
-
},
|
|
833
|
-
limit: {
|
|
834
|
-
type: "number",
|
|
835
|
-
description: "Maximum number of results to return (default: 5, max: 20)",
|
|
836
|
-
default: 5
|
|
837
|
-
}
|
|
838
|
-
},
|
|
839
|
-
required: ["query"]
|
|
840
|
-
}
|
|
778
|
+
description: "Search the documentation for relevant pages. Returns matching documents with URLs, snippets, and relevance scores. Use this to find information across all documentation.",
|
|
779
|
+
inputSchema: docsSearchInputSchema
|
|
841
780
|
};
|
|
842
|
-
function formatSearchResults(results
|
|
781
|
+
function formatSearchResults(results) {
|
|
843
782
|
if (results.length === 0) {
|
|
844
783
|
return "No matching documents found.";
|
|
845
784
|
}
|
|
@@ -849,38 +788,29 @@ function formatSearchResults(results, baseUrl) {
|
|
|
849
788
|
const result = results[i];
|
|
850
789
|
if (!result) continue;
|
|
851
790
|
lines.push(`${i + 1}. **${result.title}**`);
|
|
852
|
-
|
|
853
|
-
const fullUrl = `${baseUrl.replace(/\/$/, "")}${result.route}`;
|
|
854
|
-
lines.push(` URL: ${fullUrl}`);
|
|
855
|
-
}
|
|
856
|
-
lines.push(` Route: ${result.route}`);
|
|
791
|
+
lines.push(` URL: ${result.url}`);
|
|
857
792
|
if (result.matchingHeadings && result.matchingHeadings.length > 0) {
|
|
858
793
|
lines.push(` Matching sections: ${result.matchingHeadings.join(", ")}`);
|
|
859
794
|
}
|
|
860
795
|
lines.push(` ${result.snippet}`);
|
|
861
796
|
lines.push("");
|
|
862
797
|
}
|
|
798
|
+
lines.push("Use docs_fetch with the URL to retrieve the full page content.");
|
|
863
799
|
return lines.join("\n");
|
|
864
800
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
type: "string",
|
|
875
|
-
description: "The route path of the page (e.g., /docs/getting-started)"
|
|
876
|
-
}
|
|
877
|
-
},
|
|
878
|
-
required: ["route"]
|
|
879
|
-
}
|
|
801
|
+
var docsFetchInputSchema = {
|
|
802
|
+
url: z.string().url().describe(
|
|
803
|
+
'The full URL of the page to fetch (e.g., "https://docs.example.com/docs/getting-started")'
|
|
804
|
+
)
|
|
805
|
+
};
|
|
806
|
+
var docsFetchTool = {
|
|
807
|
+
name: "docs_fetch",
|
|
808
|
+
description: "Fetch the complete content of a documentation page. Use this after searching to get the full markdown content of a specific page.",
|
|
809
|
+
inputSchema: docsFetchInputSchema
|
|
880
810
|
};
|
|
881
|
-
function formatPageContent(doc
|
|
811
|
+
function formatPageContent(doc) {
|
|
882
812
|
if (!doc) {
|
|
883
|
-
return "Page not found. Please check the
|
|
813
|
+
return "Page not found. Please check the URL and try again.";
|
|
884
814
|
}
|
|
885
815
|
const lines = [];
|
|
886
816
|
lines.push(`# ${doc.title}`);
|
|
@@ -889,12 +819,6 @@ function formatPageContent(doc, baseUrl) {
|
|
|
889
819
|
lines.push(`> ${doc.description}`);
|
|
890
820
|
lines.push("");
|
|
891
821
|
}
|
|
892
|
-
if (baseUrl) {
|
|
893
|
-
const fullUrl = `${baseUrl.replace(/\/$/, "")}${doc.route}`;
|
|
894
|
-
lines.push(`**URL:** ${fullUrl}`);
|
|
895
|
-
}
|
|
896
|
-
lines.push(`**Route:** ${doc.route}`);
|
|
897
|
-
lines.push("");
|
|
898
822
|
if (doc.headings.length > 0) {
|
|
899
823
|
lines.push("## Contents");
|
|
900
824
|
lines.push("");
|
|
@@ -912,52 +836,6 @@ function formatPageContent(doc, baseUrl) {
|
|
|
912
836
|
return lines.join("\n");
|
|
913
837
|
}
|
|
914
838
|
|
|
915
|
-
// src/mcp/tools/docs-get-section.ts
|
|
916
|
-
var docsGetSectionTool = {
|
|
917
|
-
name: "docs_get_section",
|
|
918
|
-
description: "Retrieve a specific section of a documentation page by heading ID. Use this to get focused content from a larger page.",
|
|
919
|
-
inputSchema: {
|
|
920
|
-
type: "object",
|
|
921
|
-
properties: {
|
|
922
|
-
route: {
|
|
923
|
-
type: "string",
|
|
924
|
-
description: "The route path of the page (e.g., /docs/getting-started)"
|
|
925
|
-
},
|
|
926
|
-
headingId: {
|
|
927
|
-
type: "string",
|
|
928
|
-
description: "The ID of the heading to retrieve (e.g., authentication)"
|
|
929
|
-
}
|
|
930
|
-
},
|
|
931
|
-
required: ["route", "headingId"]
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
function formatSectionContent(result, headingId, baseUrl) {
|
|
935
|
-
if (!result.doc) {
|
|
936
|
-
return "Page not found. Please check the route path and try again.";
|
|
937
|
-
}
|
|
938
|
-
if (!result.content) {
|
|
939
|
-
const lines2 = [`Section "${headingId}" not found in this document.`, "", "Available sections:"];
|
|
940
|
-
for (const heading of result.availableHeadings) {
|
|
941
|
-
const indent = " ".repeat(heading.level - 1);
|
|
942
|
-
lines2.push(`${indent}- ${heading.text} (id: ${heading.id})`);
|
|
943
|
-
}
|
|
944
|
-
return lines2.join("\n");
|
|
945
|
-
}
|
|
946
|
-
const lines = [];
|
|
947
|
-
const fullUrl = baseUrl ? `${baseUrl.replace(/\/$/, "")}${result.doc.route}#${headingId}` : null;
|
|
948
|
-
lines.push(`# ${result.headingText}`);
|
|
949
|
-
if (fullUrl) {
|
|
950
|
-
lines.push(`> From: ${result.doc.title} - ${fullUrl}`);
|
|
951
|
-
} else {
|
|
952
|
-
lines.push(`> From: ${result.doc.title} (${result.doc.route})`);
|
|
953
|
-
}
|
|
954
|
-
lines.push("");
|
|
955
|
-
lines.push("---");
|
|
956
|
-
lines.push("");
|
|
957
|
-
lines.push(result.content);
|
|
958
|
-
return lines.join("\n");
|
|
959
|
-
}
|
|
960
|
-
|
|
961
839
|
// src/mcp/server.ts
|
|
962
840
|
function isFileConfig(config) {
|
|
963
841
|
return "docsPath" in config && "indexPath" in config;
|
|
@@ -986,17 +864,14 @@ var McpDocsServer = class {
|
|
|
986
864
|
this.registerTools();
|
|
987
865
|
}
|
|
988
866
|
/**
|
|
989
|
-
* Register all MCP tools using
|
|
867
|
+
* Register all MCP tools using definitions from tool files
|
|
990
868
|
*/
|
|
991
869
|
registerTools() {
|
|
992
870
|
this.mcpServer.registerTool(
|
|
993
|
-
|
|
871
|
+
docsSearchTool.name,
|
|
994
872
|
{
|
|
995
|
-
description:
|
|
996
|
-
inputSchema:
|
|
997
|
-
query: z.string().min(1).describe("The search query string"),
|
|
998
|
-
limit: z.number().int().min(1).max(20).optional().default(5).describe("Maximum number of results to return (1-20, default: 5)")
|
|
999
|
-
}
|
|
873
|
+
description: docsSearchTool.description,
|
|
874
|
+
inputSchema: docsSearchTool.inputSchema
|
|
1000
875
|
},
|
|
1001
876
|
async ({ query, limit }) => {
|
|
1002
877
|
await this.initialize();
|
|
@@ -1009,9 +884,7 @@ var McpDocsServer = class {
|
|
|
1009
884
|
try {
|
|
1010
885
|
const results = await this.searchProvider.search(query, { limit });
|
|
1011
886
|
return {
|
|
1012
|
-
content: [
|
|
1013
|
-
{ type: "text", text: formatSearchResults(results, this.config.baseUrl) }
|
|
1014
|
-
]
|
|
887
|
+
content: [{ type: "text", text: formatSearchResults(results) }]
|
|
1015
888
|
};
|
|
1016
889
|
} catch (error) {
|
|
1017
890
|
console.error("[MCP] Search error:", error);
|
|
@@ -1023,47 +896,12 @@ var McpDocsServer = class {
|
|
|
1023
896
|
}
|
|
1024
897
|
);
|
|
1025
898
|
this.mcpServer.registerTool(
|
|
1026
|
-
|
|
1027
|
-
{
|
|
1028
|
-
description: "Retrieve the complete content of a documentation page as markdown. Use this when you need the full content of a specific page.",
|
|
1029
|
-
inputSchema: {
|
|
1030
|
-
route: z.string().min(1).describe('The page route path (e.g., "/docs/getting-started" or "/api/reference")')
|
|
1031
|
-
}
|
|
1032
|
-
},
|
|
1033
|
-
async ({ route }) => {
|
|
1034
|
-
await this.initialize();
|
|
1035
|
-
if (!this.searchProvider || !this.searchProvider.isReady()) {
|
|
1036
|
-
return {
|
|
1037
|
-
content: [{ type: "text", text: "Server not initialized. Please try again." }],
|
|
1038
|
-
isError: true
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
try {
|
|
1042
|
-
const doc = await this.getDocument(route);
|
|
1043
|
-
return {
|
|
1044
|
-
content: [{ type: "text", text: formatPageContent(doc, this.config.baseUrl) }]
|
|
1045
|
-
};
|
|
1046
|
-
} catch (error) {
|
|
1047
|
-
console.error("[MCP] Get page error:", error);
|
|
1048
|
-
return {
|
|
1049
|
-
content: [{ type: "text", text: `Error getting page: ${String(error)}` }],
|
|
1050
|
-
isError: true
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
);
|
|
1055
|
-
this.mcpServer.registerTool(
|
|
1056
|
-
"docs_get_section",
|
|
899
|
+
docsFetchTool.name,
|
|
1057
900
|
{
|
|
1058
|
-
description:
|
|
1059
|
-
inputSchema:
|
|
1060
|
-
route: z.string().min(1).describe("The page route path"),
|
|
1061
|
-
headingId: z.string().min(1).describe(
|
|
1062
|
-
'The heading ID of the section to extract (e.g., "installation", "api-reference")'
|
|
1063
|
-
)
|
|
1064
|
-
}
|
|
901
|
+
description: docsFetchTool.description,
|
|
902
|
+
inputSchema: docsFetchTool.inputSchema
|
|
1065
903
|
},
|
|
1066
|
-
async ({
|
|
904
|
+
async ({ url }) => {
|
|
1067
905
|
await this.initialize();
|
|
1068
906
|
if (!this.searchProvider || !this.searchProvider.isReady()) {
|
|
1069
907
|
return {
|
|
@@ -1072,58 +910,14 @@ var McpDocsServer = class {
|
|
|
1072
910
|
};
|
|
1073
911
|
}
|
|
1074
912
|
try {
|
|
1075
|
-
const doc = await this.getDocument(
|
|
1076
|
-
if (!doc) {
|
|
1077
|
-
return {
|
|
1078
|
-
content: [
|
|
1079
|
-
{
|
|
1080
|
-
type: "text",
|
|
1081
|
-
text: formatSectionContent(
|
|
1082
|
-
{ content: null, doc: null, headingText: null, availableHeadings: [] },
|
|
1083
|
-
headingId,
|
|
1084
|
-
this.config.baseUrl
|
|
1085
|
-
)
|
|
1086
|
-
}
|
|
1087
|
-
]
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
const availableHeadings = doc.headings.map((h) => ({
|
|
1091
|
-
id: h.id,
|
|
1092
|
-
text: h.text,
|
|
1093
|
-
level: h.level
|
|
1094
|
-
}));
|
|
1095
|
-
const heading = doc.headings.find((h) => h.id === headingId.trim());
|
|
1096
|
-
if (!heading) {
|
|
1097
|
-
return {
|
|
1098
|
-
content: [
|
|
1099
|
-
{
|
|
1100
|
-
type: "text",
|
|
1101
|
-
text: formatSectionContent(
|
|
1102
|
-
{ content: null, doc, headingText: null, availableHeadings },
|
|
1103
|
-
headingId,
|
|
1104
|
-
this.config.baseUrl
|
|
1105
|
-
)
|
|
1106
|
-
}
|
|
1107
|
-
]
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
const sectionContent = extractSection(doc.markdown, headingId.trim(), doc.headings);
|
|
913
|
+
const doc = await this.getDocument(url);
|
|
1111
914
|
return {
|
|
1112
|
-
content: [
|
|
1113
|
-
{
|
|
1114
|
-
type: "text",
|
|
1115
|
-
text: formatSectionContent(
|
|
1116
|
-
{ content: sectionContent, doc, headingText: heading.text, availableHeadings },
|
|
1117
|
-
headingId,
|
|
1118
|
-
this.config.baseUrl
|
|
1119
|
-
)
|
|
1120
|
-
}
|
|
1121
|
-
]
|
|
915
|
+
content: [{ type: "text", text: formatPageContent(doc) }]
|
|
1122
916
|
};
|
|
1123
917
|
} catch (error) {
|
|
1124
|
-
console.error("[MCP]
|
|
918
|
+
console.error("[MCP] Fetch error:", error);
|
|
1125
919
|
return {
|
|
1126
|
-
content: [{ type: "text", text: `Error
|
|
920
|
+
content: [{ type: "text", text: `Error fetching page: ${String(error)}` }],
|
|
1127
921
|
isError: true
|
|
1128
922
|
};
|
|
1129
923
|
}
|
|
@@ -1131,24 +925,14 @@ var McpDocsServer = class {
|
|
|
1131
925
|
);
|
|
1132
926
|
}
|
|
1133
927
|
/**
|
|
1134
|
-
* Get a document by
|
|
928
|
+
* Get a document by URL using the search provider
|
|
1135
929
|
*/
|
|
1136
|
-
async getDocument(
|
|
930
|
+
async getDocument(url) {
|
|
1137
931
|
if (!this.searchProvider) {
|
|
1138
932
|
return null;
|
|
1139
933
|
}
|
|
1140
934
|
if (this.searchProvider.getDocument) {
|
|
1141
|
-
return this.searchProvider.getDocument(
|
|
1142
|
-
}
|
|
1143
|
-
if (this.searchProvider instanceof FlexSearchProvider) {
|
|
1144
|
-
const docs = this.searchProvider.getDocs();
|
|
1145
|
-
if (!docs) return null;
|
|
1146
|
-
if (docs[route]) {
|
|
1147
|
-
return docs[route];
|
|
1148
|
-
}
|
|
1149
|
-
const normalizedRoute = route.startsWith("/") ? route : `/${route}`;
|
|
1150
|
-
const withoutSlash = route.startsWith("/") ? route.slice(1) : route;
|
|
1151
|
-
return docs[normalizedRoute] ?? docs[withoutSlash] ?? null;
|
|
935
|
+
return this.searchProvider.getDocument(url);
|
|
1152
936
|
}
|
|
1153
937
|
return null;
|
|
1154
938
|
}
|
|
@@ -1267,6 +1051,6 @@ var McpDocsServer = class {
|
|
|
1267
1051
|
}
|
|
1268
1052
|
};
|
|
1269
1053
|
|
|
1270
|
-
export { DEFAULT_OPTIONS, FlexSearchIndexer, FlexSearchProvider, McpDocsServer, buildSearchIndex, collectRoutes,
|
|
1054
|
+
export { DEFAULT_OPTIONS, FlexSearchIndexer, FlexSearchProvider, McpDocsServer, buildSearchIndex, collectRoutes, discoverHtmlFiles, docsFetchTool, docsSearchTool, exportSearchIndex, extractContent, extractHeadingsFromMarkdown, extractSection, htmlToMarkdown, importSearchIndex, loadIndexer, loadSearchProvider, mcpServerPlugin, parseHtml, parseHtmlFile, searchIndex };
|
|
1271
1055
|
//# sourceMappingURL=index.mjs.map
|
|
1272
1056
|
//# sourceMappingURL=index.mjs.map
|