docusaurus-plugin-mcp-server 0.9.0 → 0.10.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.
package/dist/index.d.mts DELETED
@@ -1,479 +0,0 @@
1
- import { LoadContext, Plugin } from '@docusaurus/types';
2
- import { b as McpServerPluginOptions, M as McpServerConfig, P as ProcessedDoc, S as SearchResult, E as ExtractedContent, D as DocHeading, F as FlattenedRoute } from './index-j-CdaS6k.mjs';
3
- export { c as DEFAULT_OPTIONS, d as DocsFetchParams, e as DocsIndex, f as DocsSearchParams, g as McpManifest, h as McpServerDataConfig, a as McpServerFileConfig, R as ResolvedPluginOptions } from './index-j-CdaS6k.mjs';
4
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
- import { IncomingMessage, ServerResponse } from 'node:http';
6
- import FlexSearch from 'flexsearch';
7
- import { z } from 'zod';
8
- import { Root } from 'hast';
9
-
10
- /**
11
- * Docusaurus plugin that generates MCP server artifacts during build
12
- */
13
- declare function mcpServerPlugin(context: LoadContext, options: McpServerPluginOptions): Plugin;
14
-
15
- /**
16
- * MCP Server for documentation
17
- *
18
- * This class provides the MCP server implementation that can be used
19
- * with any HTTP framework (Express, Vercel, Cloudflare Workers, etc.)
20
- *
21
- * Supports two modes:
22
- * - File-based: Load docs and search index from filesystem (Node.js)
23
- * - Pre-loaded: Accept docs and search index data directly (Workers)
24
- *
25
- * Uses the official MCP SDK for proper protocol handling.
26
- */
27
- declare class McpDocsServer {
28
- private config;
29
- private searchProvider;
30
- private mcpServer;
31
- private initialized;
32
- constructor(config: McpServerConfig);
33
- /**
34
- * Register all MCP tools using definitions from tool files
35
- */
36
- private registerTools;
37
- /**
38
- * Get a document by URL using the search provider
39
- */
40
- private getDocument;
41
- /**
42
- * Load docs and search index using the configured search provider
43
- *
44
- * For file-based config: reads from disk
45
- * For data config: uses pre-loaded data directly
46
- */
47
- initialize(): Promise<void>;
48
- /**
49
- * Handle an HTTP request using the MCP SDK's transport
50
- *
51
- * This method is designed for serverless environments (Vercel, Netlify).
52
- * It creates a stateless transport instance and processes the request.
53
- *
54
- * @param req - Node.js IncomingMessage or compatible request object
55
- * @param res - Node.js ServerResponse or compatible response object
56
- * @param parsedBody - Optional pre-parsed request body
57
- */
58
- handleHttpRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
59
- /**
60
- * Handle a Web Standard Request (Cloudflare Workers, Deno, Bun)
61
- *
62
- * This method is designed for Web Standard environments that use
63
- * the Fetch API Request/Response pattern.
64
- *
65
- * @param request - Web Standard Request object
66
- * @returns Web Standard Response object
67
- */
68
- handleWebRequest(request: Request): Promise<Response>;
69
- /**
70
- * Get server status information
71
- *
72
- * Useful for health checks and debugging
73
- */
74
- getStatus(): Promise<{
75
- name: string;
76
- version: string;
77
- initialized: boolean;
78
- docCount: number;
79
- baseUrl?: string;
80
- searchProvider?: string;
81
- }>;
82
- /**
83
- * Get the underlying McpServer instance
84
- *
85
- * Useful for advanced use cases like custom transports
86
- */
87
- getMcpServer(): McpServer;
88
- }
89
-
90
- /**
91
- * Context passed to providers during initialization
92
- */
93
- interface ProviderContext {
94
- /** Site base URL (e.g., https://docs.example.com) */
95
- baseUrl: string;
96
- /** MCP server name */
97
- serverName: string;
98
- /** MCP server version */
99
- serverVersion: string;
100
- /** Output directory for artifacts */
101
- outputDir: string;
102
- }
103
- /**
104
- * Build-time provider that indexes extracted documents.
105
- *
106
- * Consumers implement this to push docs to external systems (Glean, Algolia, etc.)
107
- * or to transform the extraction output for their own pipelines.
108
- *
109
- * @example
110
- * ```typescript
111
- * import type { ContentIndexer, ProviderContext } from 'docusaurus-plugin-mcp-server';
112
- * import type { ProcessedDoc } from 'docusaurus-plugin-mcp-server';
113
- *
114
- * export default class AlgoliaIndexer implements ContentIndexer {
115
- * readonly name = 'algolia';
116
- *
117
- * shouldRun(): boolean {
118
- * // Only run when ALGOLIA_SYNC=true is set
119
- * return process.env.ALGOLIA_SYNC === 'true';
120
- * }
121
- *
122
- * async initialize(context: ProviderContext): Promise<void> {
123
- * console.log(`[Algolia] Initializing for ${context.baseUrl}`);
124
- * }
125
- *
126
- * async indexDocuments(docs: ProcessedDoc[]): Promise<void> {
127
- * // Push docs to Algolia
128
- * }
129
- *
130
- * async finalize(): Promise<Map<string, unknown>> {
131
- * // No local artifacts needed
132
- * return new Map();
133
- * }
134
- * }
135
- * ```
136
- */
137
- interface ContentIndexer {
138
- /** Unique name for this indexer */
139
- readonly name: string;
140
- /**
141
- * Check if this indexer should run.
142
- * Use this to gate execution on environment variables.
143
- * Default: true if not implemented.
144
- *
145
- * @example
146
- * shouldRun() {
147
- * if (process.env.GLEAN_SYNC !== 'true') {
148
- * console.log('[Glean] Skipping sync (set GLEAN_SYNC=true to enable)');
149
- * return false;
150
- * }
151
- * return true;
152
- * }
153
- */
154
- shouldRun?(): boolean;
155
- /**
156
- * Initialize the indexer with context about the build.
157
- * Called once before indexDocuments.
158
- */
159
- initialize(context: ProviderContext): Promise<void>;
160
- /**
161
- * Index the extracted documents.
162
- * Called once with all processed documents.
163
- */
164
- indexDocuments(docs: ProcessedDoc[]): Promise<void>;
165
- /**
166
- * Return artifacts to write to outputDir.
167
- * Map of filename -> JSON-serializable content.
168
- * Return empty map to skip local artifact generation.
169
- */
170
- finalize(): Promise<Map<string, unknown>>;
171
- /**
172
- * Optional metadata to include in manifest.json
173
- */
174
- getManifestData?(): Promise<Record<string, unknown>>;
175
- }
176
- /**
177
- * Data passed to search provider during initialization.
178
- * Supports both file-based and pre-loaded data modes.
179
- */
180
- interface SearchProviderInitData {
181
- /** Path to docs.json (file mode) */
182
- docsPath?: string;
183
- /** Path to search-index.json (file mode) */
184
- indexPath?: string;
185
- /** Pre-loaded docs (data mode) */
186
- docs?: Record<string, ProcessedDoc>;
187
- /** Pre-loaded index data (data mode) */
188
- indexData?: Record<string, unknown>;
189
- }
190
- /**
191
- * Options for search queries
192
- */
193
- interface SearchOptions {
194
- /** Maximum number of results to return */
195
- limit?: number;
196
- }
197
- /**
198
- * Runtime provider that handles search queries from MCP tools.
199
- *
200
- * Consumers implement this to delegate search to external systems (Glean, Algolia, etc.).
201
- *
202
- * @example
203
- * ```typescript
204
- * import type { SearchProvider, ProviderContext, SearchOptions } from 'docusaurus-plugin-mcp-server';
205
- * import type { SearchResult, ProcessedDoc } from 'docusaurus-plugin-mcp-server';
206
- *
207
- * export default class GleanSearchProvider implements SearchProvider {
208
- * readonly name = 'glean';
209
- *
210
- * private apiEndpoint = process.env.GLEAN_API_ENDPOINT!;
211
- * private apiToken = process.env.GLEAN_API_TOKEN!;
212
- *
213
- * async initialize(context: ProviderContext): Promise<void> {
214
- * if (!this.apiEndpoint || !this.apiToken) {
215
- * throw new Error('GLEAN_API_ENDPOINT and GLEAN_API_TOKEN required');
216
- * }
217
- * }
218
- *
219
- * isReady(): boolean {
220
- * return !!this.apiEndpoint && !!this.apiToken;
221
- * }
222
- *
223
- * async search(query: string, options?: SearchOptions): Promise<SearchResult[]> {
224
- * // Call Glean Search API and transform results
225
- * return [];
226
- * }
227
- * }
228
- * ```
229
- */
230
- interface SearchProvider {
231
- /** Unique name for this provider */
232
- readonly name: string;
233
- /**
234
- * Initialize the search provider.
235
- * Called once before any search queries.
236
- */
237
- initialize(context: ProviderContext, initData?: SearchProviderInitData): Promise<void>;
238
- /**
239
- * Check if the provider is ready to handle search queries.
240
- */
241
- isReady(): boolean;
242
- /**
243
- * Search for documents matching the query.
244
- */
245
- search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
246
- /**
247
- * Get a document by its route.
248
- * Used by docs_get_page and docs_get_section tools.
249
- */
250
- getDocument?(route: string): Promise<ProcessedDoc | null>;
251
- /**
252
- * Check if the provider is healthy.
253
- * Used for health checks and debugging.
254
- */
255
- healthCheck?(): Promise<{
256
- healthy: boolean;
257
- message?: string;
258
- }>;
259
- }
260
- /**
261
- * Type for module that exports a ContentIndexer
262
- */
263
- type ContentIndexerModule = {
264
- default: new () => ContentIndexer;
265
- };
266
- /**
267
- * Type for module that exports a SearchProvider
268
- */
269
- type SearchProviderModule = {
270
- default: new () => SearchProvider;
271
- };
272
-
273
- /**
274
- * Load an indexer by name or module path.
275
- *
276
- * @param specifier - Either 'flexsearch' for the built-in indexer, or a module path
277
- * (relative path like './my-indexer.js' or npm package like '@myorg/indexer')
278
- * @returns Instantiated ContentIndexer
279
- *
280
- * @example
281
- * ```typescript
282
- * // Built-in
283
- * const indexer = await loadIndexer('flexsearch');
284
- *
285
- * // Custom relative path
286
- * const indexer = await loadIndexer('./src/providers/algolia-indexer.js');
287
- *
288
- * // Custom npm package
289
- * const indexer = await loadIndexer('@myorg/custom-indexer');
290
- * ```
291
- */
292
- declare function loadIndexer(specifier: string): Promise<ContentIndexer>;
293
- /**
294
- * Load a search provider by name or module path.
295
- *
296
- * @param specifier - Either 'flexsearch' for the built-in provider, or a module path
297
- * (relative path like './my-search.js' or npm package like '@myorg/search')
298
- * @returns Instantiated SearchProvider
299
- *
300
- * @example
301
- * ```typescript
302
- * // Built-in
303
- * const provider = await loadSearchProvider('flexsearch');
304
- *
305
- * // Custom relative path
306
- * const provider = await loadSearchProvider('./src/providers/glean-search.js');
307
- *
308
- * // Custom npm package
309
- * const provider = await loadSearchProvider('@myorg/glean-search');
310
- * ```
311
- */
312
- declare function loadSearchProvider(specifier: string): Promise<SearchProvider>;
313
-
314
- /**
315
- * Built-in FlexSearch content indexer.
316
- *
317
- * This indexer builds a local FlexSearch index and produces:
318
- * - docs.json: All processed documents keyed by full URL
319
- * - search-index.json: Exported FlexSearch index for runtime search
320
- */
321
- declare class FlexSearchIndexer implements ContentIndexer {
322
- readonly name = "flexsearch";
323
- private baseUrl;
324
- private docsIndex;
325
- private exportedIndex;
326
- private docCount;
327
- /**
328
- * FlexSearch indexer always runs by default.
329
- * It respects the indexers configuration - if not included, it won't run.
330
- */
331
- shouldRun(): boolean;
332
- initialize(context: ProviderContext): Promise<void>;
333
- indexDocuments(docs: ProcessedDoc[]): Promise<void>;
334
- finalize(): Promise<Map<string, unknown>>;
335
- getManifestData(): Promise<Record<string, unknown>>;
336
- }
337
-
338
- /**
339
- * Document structure for FlexSearch indexing
340
- */
341
- interface IndexableDocument {
342
- /** Unique identifier (route path) */
343
- id: string;
344
- /** Document title */
345
- title: string;
346
- /** Full content for search */
347
- content: string;
348
- /** Concatenated heading text for search */
349
- headings: string;
350
- /** Meta description */
351
- description: string;
352
- }
353
-
354
- type FlexSearchDocument = FlexSearch.Document<IndexableDocument, string[]>;
355
- /**
356
- * Build the search index from processed documents
357
- *
358
- * @param docs - Documents to index
359
- * @param baseUrl - Optional base URL to construct full URLs as document IDs
360
- */
361
- declare function buildSearchIndex(docs: ProcessedDoc[], baseUrl?: string): FlexSearchDocument;
362
- /**
363
- * Search the index and return results with weighted ranking
364
- *
365
- * Ranking combines:
366
- * - Field importance (title > headings > description > content)
367
- * - Position in results (earlier = more relevant)
368
- */
369
- declare function searchIndex(index: FlexSearchDocument, docs: Record<string, ProcessedDoc>, query: string, options?: {
370
- limit?: number;
371
- }): SearchResult[];
372
- /**
373
- * Export the search index to a serializable format
374
- */
375
- declare function exportSearchIndex(index: FlexSearchDocument): Promise<unknown>;
376
- /**
377
- * Import a search index from serialized data
378
- */
379
- declare function importSearchIndex(data: Record<string, unknown>): Promise<FlexSearchDocument>;
380
-
381
- /**
382
- * Built-in FlexSearch search provider.
383
- *
384
- * This provider uses the local FlexSearch index for search queries.
385
- * Supports both file-based loading (Node.js) and pre-loaded data (Workers).
386
- */
387
- declare class FlexSearchProvider implements SearchProvider {
388
- readonly name = "flexsearch";
389
- private docs;
390
- private searchIndex;
391
- private ready;
392
- initialize(_context: ProviderContext, initData?: SearchProviderInitData): Promise<void>;
393
- isReady(): boolean;
394
- search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
395
- getDocument(url: string): Promise<ProcessedDoc | null>;
396
- healthCheck(): Promise<{
397
- healthy: boolean;
398
- message?: string;
399
- }>;
400
- /**
401
- * Get all loaded documents (for compatibility with existing server code)
402
- */
403
- getDocs(): Record<string, ProcessedDoc> | null;
404
- /**
405
- * Get the FlexSearch index (for compatibility with existing server code)
406
- */
407
- getSearchIndex(): FlexSearchDocument | null;
408
- }
409
-
410
- /**
411
- * Tool definition for docs_search
412
- */
413
- declare const docsSearchTool: {
414
- name: string;
415
- description: string;
416
- inputSchema: {
417
- query: z.ZodString;
418
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
419
- };
420
- };
421
-
422
- /**
423
- * Tool definition for docs_fetch
424
- */
425
- declare const docsFetchTool: {
426
- name: string;
427
- description: string;
428
- inputSchema: {
429
- url: z.ZodString;
430
- };
431
- };
432
-
433
- /**
434
- * Convert HTML string to Markdown
435
- */
436
- declare function htmlToMarkdown(html: string): Promise<string>;
437
-
438
- /**
439
- * Parse HTML string into HAST (HTML AST)
440
- */
441
- declare function parseHtml(html: string): Root;
442
- /**
443
- * Parse HTML file into HAST
444
- */
445
- declare function parseHtmlFile(filePath: string): Promise<Root>;
446
- /**
447
- * Options for content extraction
448
- */
449
- interface ExtractContentOptions {
450
- /** CSS selectors for content containers, in priority order */
451
- contentSelectors: string[];
452
- /** CSS selectors for elements to exclude from content */
453
- excludeSelectors: string[];
454
- }
455
- /**
456
- * Extract content from HTML file
457
- */
458
- declare function extractContent(filePath: string, options: ExtractContentOptions): Promise<ExtractedContent>;
459
-
460
- /**
461
- * Extract headings from markdown content with their positions
462
- */
463
- declare function extractHeadingsFromMarkdown(markdown: string): DocHeading[];
464
- /**
465
- * Extract a specific section from markdown by heading ID
466
- */
467
- declare function extractSection(markdown: string, headingId: string, headings: DocHeading[]): string | null;
468
-
469
- /**
470
- * Discover all HTML files in the build directory and create routes for them.
471
- * This is more reliable than using Docusaurus routes as it captures all built pages.
472
- */
473
- declare function discoverHtmlFiles(outDir: string): Promise<FlattenedRoute[]>;
474
- /**
475
- * Get all processable routes from the build directory
476
- */
477
- declare function collectRoutes(outDir: string, excludePatterns: string[]): Promise<FlattenedRoute[]>;
478
-
479
- export { type ContentIndexer, type ContentIndexerModule, DocHeading, ExtractedContent, FlattenedRoute, type FlexSearchDocument, FlexSearchIndexer, FlexSearchProvider, McpDocsServer, McpServerConfig, McpServerPluginOptions, ProcessedDoc, type ProviderContext, type SearchOptions, type SearchProvider, type SearchProviderInitData, type SearchProviderModule, SearchResult, buildSearchIndex, collectRoutes, discoverHtmlFiles, docsFetchTool, docsSearchTool, exportSearchIndex, extractContent, extractHeadingsFromMarkdown, extractSection, htmlToMarkdown, importSearchIndex, loadIndexer, loadSearchProvider, mcpServerPlugin, parseHtml, parseHtmlFile, searchIndex };