docusaurus-plugin-mcp-server 0.5.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.
@@ -0,0 +1,234 @@
1
+ import { LoadContext, Plugin } from '@docusaurus/types';
2
+ import { a as McpServerPluginOptions, M as McpServerConfig, P as ProcessedDoc, S as SearchResult, E as ExtractedContent, D as DocHeading, F as FlattenedRoute } from './index-CzA4FjeE.mjs';
3
+ export { b as DEFAULT_OPTIONS, c as DocsGetPageParams, d as DocsGetSectionParams, e as DocsIndex, f as DocsSearchParams, g as McpManifest, h as McpServerDataConfig, i as McpServerFileConfig, R as ResolvedPluginOptions } from './index-CzA4FjeE.mjs';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { IncomingMessage, ServerResponse } from 'node:http';
6
+ import { Root } from 'hast';
7
+ import FlexSearch from 'flexsearch';
8
+
9
+ /**
10
+ * Docusaurus plugin that generates MCP server artifacts during build
11
+ */
12
+ declare function mcpServerPlugin(context: LoadContext, options: McpServerPluginOptions): Plugin;
13
+
14
+ /**
15
+ * MCP Server for documentation
16
+ *
17
+ * This class provides the MCP server implementation that can be used
18
+ * with any HTTP framework (Express, Vercel, Cloudflare Workers, etc.)
19
+ *
20
+ * Supports two modes:
21
+ * - File-based: Load docs and search index from filesystem (Node.js)
22
+ * - Pre-loaded: Accept docs and search index data directly (Workers)
23
+ *
24
+ * Uses the official MCP SDK for proper protocol handling.
25
+ */
26
+ declare class McpDocsServer {
27
+ private config;
28
+ private docs;
29
+ private searchIndex;
30
+ private mcpServer;
31
+ private initialized;
32
+ constructor(config: McpServerConfig);
33
+ /**
34
+ * Register all MCP tools using the SDK's registerTool API
35
+ */
36
+ private registerTools;
37
+ /**
38
+ * Load docs and search index
39
+ *
40
+ * For file-based config: reads from disk
41
+ * For data config: uses pre-loaded data directly
42
+ */
43
+ initialize(): Promise<void>;
44
+ /**
45
+ * Handle an HTTP request using the MCP SDK's transport
46
+ *
47
+ * This method is designed for serverless environments (Vercel, Netlify).
48
+ * It creates a stateless transport instance and processes the request.
49
+ *
50
+ * @param req - Node.js IncomingMessage or compatible request object
51
+ * @param res - Node.js ServerResponse or compatible response object
52
+ * @param parsedBody - Optional pre-parsed request body
53
+ */
54
+ handleHttpRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
55
+ /**
56
+ * Handle a Web Standard Request (Cloudflare Workers, Deno, Bun)
57
+ *
58
+ * This method is designed for Web Standard environments that use
59
+ * the Fetch API Request/Response pattern.
60
+ *
61
+ * @param request - Web Standard Request object
62
+ * @returns Web Standard Response object
63
+ */
64
+ handleWebRequest(request: Request): Promise<Response>;
65
+ /**
66
+ * Get server status information
67
+ *
68
+ * Useful for health checks and debugging
69
+ */
70
+ getStatus(): Promise<{
71
+ name: string;
72
+ version: string;
73
+ initialized: boolean;
74
+ docCount: number;
75
+ baseUrl?: string;
76
+ }>;
77
+ /**
78
+ * Get the underlying McpServer instance
79
+ *
80
+ * Useful for advanced use cases like custom transports
81
+ */
82
+ getMcpServer(): McpServer;
83
+ }
84
+
85
+ /**
86
+ * Document structure for FlexSearch indexing
87
+ */
88
+ interface IndexableDocument {
89
+ /** Unique identifier (route path) */
90
+ id: string;
91
+ /** Document title */
92
+ title: string;
93
+ /** Full content for search */
94
+ content: string;
95
+ /** Concatenated heading text for search */
96
+ headings: string;
97
+ /** Meta description */
98
+ description: string;
99
+ }
100
+
101
+ type FlexSearchDocument = FlexSearch.Document<IndexableDocument, string[]>;
102
+ /**
103
+ * Build the search index from processed documents
104
+ */
105
+ declare function buildSearchIndex(docs: ProcessedDoc[]): FlexSearchDocument;
106
+ /**
107
+ * Search the index and return results with weighted ranking
108
+ *
109
+ * Ranking combines:
110
+ * - Field importance (title > headings > description > content)
111
+ * - Position in results (earlier = more relevant)
112
+ */
113
+ declare function searchIndex(index: FlexSearchDocument, docs: Record<string, ProcessedDoc>, query: string, options?: {
114
+ limit?: number;
115
+ }): SearchResult[];
116
+ /**
117
+ * Export the search index to a serializable format
118
+ */
119
+ declare function exportSearchIndex(index: FlexSearchDocument): Promise<unknown>;
120
+ /**
121
+ * Import a search index from serialized data
122
+ */
123
+ declare function importSearchIndex(data: Record<string, unknown>): Promise<FlexSearchDocument>;
124
+
125
+ /**
126
+ * Tool definition for docs_search
127
+ */
128
+ declare const docsSearchTool: {
129
+ name: string;
130
+ description: string;
131
+ inputSchema: {
132
+ type: "object";
133
+ properties: {
134
+ query: {
135
+ type: string;
136
+ description: string;
137
+ };
138
+ limit: {
139
+ type: string;
140
+ description: string;
141
+ default: number;
142
+ };
143
+ };
144
+ required: string[];
145
+ };
146
+ };
147
+
148
+ /**
149
+ * Tool definition for docs_get_page
150
+ */
151
+ declare const docsGetPageTool: {
152
+ name: string;
153
+ description: string;
154
+ inputSchema: {
155
+ type: "object";
156
+ properties: {
157
+ route: {
158
+ type: string;
159
+ description: string;
160
+ };
161
+ };
162
+ required: string[];
163
+ };
164
+ };
165
+
166
+ /**
167
+ * Tool definition for docs_get_section
168
+ */
169
+ declare const docsGetSectionTool: {
170
+ name: string;
171
+ description: string;
172
+ inputSchema: {
173
+ type: "object";
174
+ properties: {
175
+ route: {
176
+ type: string;
177
+ description: string;
178
+ };
179
+ headingId: {
180
+ type: string;
181
+ description: string;
182
+ };
183
+ };
184
+ required: string[];
185
+ };
186
+ };
187
+
188
+ /**
189
+ * Convert HTML string to Markdown
190
+ */
191
+ declare function htmlToMarkdown(html: string): Promise<string>;
192
+
193
+ /**
194
+ * Parse HTML string into HAST (HTML AST)
195
+ */
196
+ declare function parseHtml(html: string): Root;
197
+ /**
198
+ * Parse HTML file into HAST
199
+ */
200
+ declare function parseHtmlFile(filePath: string): Promise<Root>;
201
+ /**
202
+ * Options for content extraction
203
+ */
204
+ interface ExtractContentOptions {
205
+ /** CSS selectors for content containers, in priority order */
206
+ contentSelectors: string[];
207
+ /** CSS selectors for elements to exclude from content */
208
+ excludeSelectors: string[];
209
+ }
210
+ /**
211
+ * Extract content from HTML file
212
+ */
213
+ declare function extractContent(filePath: string, options: ExtractContentOptions): Promise<ExtractedContent>;
214
+
215
+ /**
216
+ * Extract headings from markdown content with their positions
217
+ */
218
+ declare function extractHeadingsFromMarkdown(markdown: string): DocHeading[];
219
+ /**
220
+ * Extract a specific section from markdown by heading ID
221
+ */
222
+ declare function extractSection(markdown: string, headingId: string, headings: DocHeading[]): string | null;
223
+
224
+ /**
225
+ * Discover all HTML files in the build directory and create routes for them.
226
+ * This is more reliable than using Docusaurus routes as it captures all built pages.
227
+ */
228
+ declare function discoverHtmlFiles(outDir: string): Promise<FlattenedRoute[]>;
229
+ /**
230
+ * Get all processable routes from the build directory
231
+ */
232
+ declare function collectRoutes(outDir: string, excludePatterns: string[]): Promise<FlattenedRoute[]>;
233
+
234
+ export { DocHeading, ExtractedContent, FlattenedRoute, type FlexSearchDocument, McpDocsServer, McpServerConfig, McpServerPluginOptions, ProcessedDoc, SearchResult, buildSearchIndex, collectRoutes, mcpServerPlugin as default, discoverHtmlFiles, docsGetPageTool, docsGetSectionTool, docsSearchTool, exportSearchIndex, extractContent, extractHeadingsFromMarkdown, extractSection, htmlToMarkdown, importSearchIndex, mcpServerPlugin, parseHtml, parseHtmlFile, searchIndex };
@@ -0,0 +1,234 @@
1
+ import { LoadContext, Plugin } from '@docusaurus/types';
2
+ import { a as McpServerPluginOptions, M as McpServerConfig, P as ProcessedDoc, S as SearchResult, E as ExtractedContent, D as DocHeading, F as FlattenedRoute } from './index-CzA4FjeE.js';
3
+ export { b as DEFAULT_OPTIONS, c as DocsGetPageParams, d as DocsGetSectionParams, e as DocsIndex, f as DocsSearchParams, g as McpManifest, h as McpServerDataConfig, i as McpServerFileConfig, R as ResolvedPluginOptions } from './index-CzA4FjeE.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { IncomingMessage, ServerResponse } from 'node:http';
6
+ import { Root } from 'hast';
7
+ import FlexSearch from 'flexsearch';
8
+
9
+ /**
10
+ * Docusaurus plugin that generates MCP server artifacts during build
11
+ */
12
+ declare function mcpServerPlugin(context: LoadContext, options: McpServerPluginOptions): Plugin;
13
+
14
+ /**
15
+ * MCP Server for documentation
16
+ *
17
+ * This class provides the MCP server implementation that can be used
18
+ * with any HTTP framework (Express, Vercel, Cloudflare Workers, etc.)
19
+ *
20
+ * Supports two modes:
21
+ * - File-based: Load docs and search index from filesystem (Node.js)
22
+ * - Pre-loaded: Accept docs and search index data directly (Workers)
23
+ *
24
+ * Uses the official MCP SDK for proper protocol handling.
25
+ */
26
+ declare class McpDocsServer {
27
+ private config;
28
+ private docs;
29
+ private searchIndex;
30
+ private mcpServer;
31
+ private initialized;
32
+ constructor(config: McpServerConfig);
33
+ /**
34
+ * Register all MCP tools using the SDK's registerTool API
35
+ */
36
+ private registerTools;
37
+ /**
38
+ * Load docs and search index
39
+ *
40
+ * For file-based config: reads from disk
41
+ * For data config: uses pre-loaded data directly
42
+ */
43
+ initialize(): Promise<void>;
44
+ /**
45
+ * Handle an HTTP request using the MCP SDK's transport
46
+ *
47
+ * This method is designed for serverless environments (Vercel, Netlify).
48
+ * It creates a stateless transport instance and processes the request.
49
+ *
50
+ * @param req - Node.js IncomingMessage or compatible request object
51
+ * @param res - Node.js ServerResponse or compatible response object
52
+ * @param parsedBody - Optional pre-parsed request body
53
+ */
54
+ handleHttpRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
55
+ /**
56
+ * Handle a Web Standard Request (Cloudflare Workers, Deno, Bun)
57
+ *
58
+ * This method is designed for Web Standard environments that use
59
+ * the Fetch API Request/Response pattern.
60
+ *
61
+ * @param request - Web Standard Request object
62
+ * @returns Web Standard Response object
63
+ */
64
+ handleWebRequest(request: Request): Promise<Response>;
65
+ /**
66
+ * Get server status information
67
+ *
68
+ * Useful for health checks and debugging
69
+ */
70
+ getStatus(): Promise<{
71
+ name: string;
72
+ version: string;
73
+ initialized: boolean;
74
+ docCount: number;
75
+ baseUrl?: string;
76
+ }>;
77
+ /**
78
+ * Get the underlying McpServer instance
79
+ *
80
+ * Useful for advanced use cases like custom transports
81
+ */
82
+ getMcpServer(): McpServer;
83
+ }
84
+
85
+ /**
86
+ * Document structure for FlexSearch indexing
87
+ */
88
+ interface IndexableDocument {
89
+ /** Unique identifier (route path) */
90
+ id: string;
91
+ /** Document title */
92
+ title: string;
93
+ /** Full content for search */
94
+ content: string;
95
+ /** Concatenated heading text for search */
96
+ headings: string;
97
+ /** Meta description */
98
+ description: string;
99
+ }
100
+
101
+ type FlexSearchDocument = FlexSearch.Document<IndexableDocument, string[]>;
102
+ /**
103
+ * Build the search index from processed documents
104
+ */
105
+ declare function buildSearchIndex(docs: ProcessedDoc[]): FlexSearchDocument;
106
+ /**
107
+ * Search the index and return results with weighted ranking
108
+ *
109
+ * Ranking combines:
110
+ * - Field importance (title > headings > description > content)
111
+ * - Position in results (earlier = more relevant)
112
+ */
113
+ declare function searchIndex(index: FlexSearchDocument, docs: Record<string, ProcessedDoc>, query: string, options?: {
114
+ limit?: number;
115
+ }): SearchResult[];
116
+ /**
117
+ * Export the search index to a serializable format
118
+ */
119
+ declare function exportSearchIndex(index: FlexSearchDocument): Promise<unknown>;
120
+ /**
121
+ * Import a search index from serialized data
122
+ */
123
+ declare function importSearchIndex(data: Record<string, unknown>): Promise<FlexSearchDocument>;
124
+
125
+ /**
126
+ * Tool definition for docs_search
127
+ */
128
+ declare const docsSearchTool: {
129
+ name: string;
130
+ description: string;
131
+ inputSchema: {
132
+ type: "object";
133
+ properties: {
134
+ query: {
135
+ type: string;
136
+ description: string;
137
+ };
138
+ limit: {
139
+ type: string;
140
+ description: string;
141
+ default: number;
142
+ };
143
+ };
144
+ required: string[];
145
+ };
146
+ };
147
+
148
+ /**
149
+ * Tool definition for docs_get_page
150
+ */
151
+ declare const docsGetPageTool: {
152
+ name: string;
153
+ description: string;
154
+ inputSchema: {
155
+ type: "object";
156
+ properties: {
157
+ route: {
158
+ type: string;
159
+ description: string;
160
+ };
161
+ };
162
+ required: string[];
163
+ };
164
+ };
165
+
166
+ /**
167
+ * Tool definition for docs_get_section
168
+ */
169
+ declare const docsGetSectionTool: {
170
+ name: string;
171
+ description: string;
172
+ inputSchema: {
173
+ type: "object";
174
+ properties: {
175
+ route: {
176
+ type: string;
177
+ description: string;
178
+ };
179
+ headingId: {
180
+ type: string;
181
+ description: string;
182
+ };
183
+ };
184
+ required: string[];
185
+ };
186
+ };
187
+
188
+ /**
189
+ * Convert HTML string to Markdown
190
+ */
191
+ declare function htmlToMarkdown(html: string): Promise<string>;
192
+
193
+ /**
194
+ * Parse HTML string into HAST (HTML AST)
195
+ */
196
+ declare function parseHtml(html: string): Root;
197
+ /**
198
+ * Parse HTML file into HAST
199
+ */
200
+ declare function parseHtmlFile(filePath: string): Promise<Root>;
201
+ /**
202
+ * Options for content extraction
203
+ */
204
+ interface ExtractContentOptions {
205
+ /** CSS selectors for content containers, in priority order */
206
+ contentSelectors: string[];
207
+ /** CSS selectors for elements to exclude from content */
208
+ excludeSelectors: string[];
209
+ }
210
+ /**
211
+ * Extract content from HTML file
212
+ */
213
+ declare function extractContent(filePath: string, options: ExtractContentOptions): Promise<ExtractedContent>;
214
+
215
+ /**
216
+ * Extract headings from markdown content with their positions
217
+ */
218
+ declare function extractHeadingsFromMarkdown(markdown: string): DocHeading[];
219
+ /**
220
+ * Extract a specific section from markdown by heading ID
221
+ */
222
+ declare function extractSection(markdown: string, headingId: string, headings: DocHeading[]): string | null;
223
+
224
+ /**
225
+ * Discover all HTML files in the build directory and create routes for them.
226
+ * This is more reliable than using Docusaurus routes as it captures all built pages.
227
+ */
228
+ declare function discoverHtmlFiles(outDir: string): Promise<FlattenedRoute[]>;
229
+ /**
230
+ * Get all processable routes from the build directory
231
+ */
232
+ declare function collectRoutes(outDir: string, excludePatterns: string[]): Promise<FlattenedRoute[]>;
233
+
234
+ export { DocHeading, ExtractedContent, FlattenedRoute, type FlexSearchDocument, McpDocsServer, McpServerConfig, McpServerPluginOptions, ProcessedDoc, SearchResult, buildSearchIndex, collectRoutes, mcpServerPlugin as default, discoverHtmlFiles, docsGetPageTool, docsGetSectionTool, docsSearchTool, exportSearchIndex, extractContent, extractHeadingsFromMarkdown, extractSection, htmlToMarkdown, importSearchIndex, mcpServerPlugin, parseHtml, parseHtmlFile, searchIndex };