docusaurus-plugin-mcp-server 0.5.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/search/flexsearch-indexer.ts","../src/mcp/tools/docs-search.ts","../src/mcp/tools/docs-get-page.ts","../src/processing/heading-extractor.ts","../src/mcp/tools/docs-get-section.ts","../src/mcp/server.ts","../src/adapters/vercel.ts","../src/adapters/netlify.ts","../src/adapters/cloudflare.ts","../src/adapters/generator.ts"],"names":["results","lines"],"mappings":";;;;;;;;AAUA,IAAM,aAAA,GAAgB;AAAA,EACpB,KAAA,EAAO,CAAA;AAAA,EACP,QAAA,EAAU,CAAA;AAAA,EACV,WAAA,EAAa,GAAA;AAAA,EACb,OAAA,EAAS;AACX,CAAA;AAMA,SAAS,eAAe,IAAA,EAAsB;AAE5C,EAAA,IAAI,IAAA,CAAK,MAAA,IAAU,CAAA,EAAG,OAAO,IAAA;AAE7B,EAAA,OACE,KAEG,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,CAElB,QAAQ,OAAA,EAAS,GAAG,CAAA,CACpB,OAAA,CAAQ,SAAS,GAAG,CAAA,CAEpB,QAAQ,eAAA,EAAiB,IAAI,EAE7B,OAAA,CAAQ,eAAA,EAAiB,IAAI,CAAA,CAE7B,QAAQ,KAAA,EAAO,EAAE,EAEjB,OAAA,CAAQ,OAAA,EAAS,EAAE,CAAA,CAEnB,OAAA,CAAQ,OAAA,EAAS,EAAE,EAEnB,OAAA,CAAQ,MAAA,EAAQ,GAAG,CAAA,CAEnB,OAAA,CAAQ,YAAY,IAAI,CAAA;AAE/B;AAWO,SAAS,iBAAA,GAAwC;AACtD,EAAA,OAAO,IAAI,WAAW,QAAA,CAAsC;AAAA;AAAA;AAAA,IAG1D,QAAA,EAAU,MAAA;AAAA;AAAA,IAGV,KAAA,EAAO,GAAA;AAAA;AAAA,IAGP,UAAA,EAAY,CAAA;AAAA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AQnB;AAAA,IACA;AAAA,MACE,IAAA,EAAM,eAAA;AAAA,MACN,WAAA,EAAa,mCAAA;AAAA,MACb,OAAA,EAAS,WAAW,IAAI,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAa1B,GACF;AACF","file":"adapters-entry.mjs","sourcesContent":["import FlexSearch from 'flexsearch';\nimport type { ProcessedDoc, SearchResult } from '../types/index.js';\nimport type { IndexableDocument } from './types.js';\n\nexport type FlexSearchDocument = FlexSearch.Document<IndexableDocument, string[]>;\n\n/**\n * Field weights for search ranking\n * Higher values = more importance\n */\nconst FIELD_WEIGHTS = {\n title: 3.0,\n headings: 2.0,\n description: 1.5,\n content: 1.0,\n} as const;\n\n/**\n * Simple English stemmer\n * Handles common suffixes for better matching\n */\nfunction englishStemmer(word: string): string {\n // Only process words longer than 3 characters\n if (word.length <= 3) return word;\n\n return (\n word\n // -ing endings\n .replace(/ing$/, '')\n // -tion, -sion endings -> t, s\n .replace(/tion$/, 't')\n .replace(/sion$/, 's')\n // -ed endings (careful with short words)\n .replace(/([^aeiou])ed$/, '$1')\n // -es endings\n .replace(/([^aeiou])es$/, '$1')\n // -ly endings\n .replace(/ly$/, '')\n // -ment endings\n .replace(/ment$/, '')\n // -ness endings\n .replace(/ness$/, '')\n // -ies -> y\n .replace(/ies$/, 'y')\n // -s endings (simple plural)\n .replace(/([^s])s$/, '$1')\n );\n}\n\n/**\n * Create a FlexSearch document index with enhanced configuration\n *\n * Features:\n * - Full substring matching (finds \"auth\" in \"authentication\")\n * - English stemming (finds \"authenticate\" when searching \"authentication\")\n * - Context-aware scoring for phrase matching\n * - Optimized resolution for relevance ranking\n */\nexport function createSearchIndex(): FlexSearchDocument {\n return new FlexSearch.Document<IndexableDocument, string[]>({\n // Use 'full' tokenization for substring matching\n // This allows \"auth\" to match \"authentication\"\n tokenize: 'full',\n\n // Enable caching for faster repeated queries\n cache: 100,\n\n // Higher resolution = more granular ranking (1-9)\n resolution: 9,\n\n // Enable context for phrase/proximity matching\n context: {\n resolution: 2,\n depth: 2,\n bidirectional: true,\n },\n\n // Apply stemming to normalize word forms\n encode: (str: string) => {\n // Normalize to lowercase and split into words\n const words = str.toLowerCase().split(/[\\s\\-_.,;:!?'\"()[\\]{}]+/);\n // Apply stemmer to each word\n return words.filter(Boolean).map(englishStemmer);\n },\n\n // Document schema\n document: {\n id: 'id',\n // Index these fields for searching\n index: ['title', 'content', 'headings', 'description'],\n // Store these fields in results (for enriched queries)\n store: ['title', 'description'],\n },\n });\n}\n\n/**\n * Add a document to the search index\n */\nexport function addDocumentToIndex(index: FlexSearchDocument, doc: ProcessedDoc): void {\n const indexable: IndexableDocument = {\n id: doc.route,\n title: doc.title,\n content: doc.markdown,\n headings: doc.headings.map((h) => h.text).join(' '),\n description: doc.description,\n };\n\n index.add(indexable);\n}\n\n/**\n * Build the search index from processed documents\n */\nexport function buildSearchIndex(docs: ProcessedDoc[]): FlexSearchDocument {\n const index = createSearchIndex();\n\n for (const doc of docs) {\n addDocumentToIndex(index, doc);\n }\n\n return index;\n}\n\n/**\n * Search the index and return results with weighted ranking\n *\n * Ranking combines:\n * - Field importance (title > headings > description > content)\n * - Position in results (earlier = more relevant)\n */\nexport function searchIndex(\n index: FlexSearchDocument,\n docs: Record<string, ProcessedDoc>,\n query: string,\n options: { limit?: number } = {}\n): SearchResult[] {\n const { limit = 5 } = options;\n\n // Search across all fields\n const rawResults = index.search(query, {\n limit: limit * 3, // Get extra results for better ranking after weighting\n enrich: true,\n });\n\n // Aggregate scores across fields with weighting\n const docScores = new Map<string, number>();\n\n for (const fieldResult of rawResults) {\n // Determine which field this result is from\n const field = fieldResult.field as keyof typeof FIELD_WEIGHTS;\n const fieldWeight = FIELD_WEIGHTS[field] ?? 1.0;\n\n // With enrich: true, results are objects with id property\n const results = fieldResult.result as unknown as Array<{ id: string } | string>;\n\n for (let i = 0; i < results.length; i++) {\n const item = results[i];\n if (!item) continue;\n\n const docId = typeof item === 'string' ? item : item.id;\n\n // Position-based score (earlier = higher)\n const positionScore = (results.length - i) / results.length;\n\n // Apply field weight to position score\n const weightedScore = positionScore * fieldWeight;\n\n // Combine with existing score (additive for multi-field matches)\n const existingScore = docScores.get(docId) ?? 0;\n docScores.set(docId, existingScore + weightedScore);\n }\n }\n\n // Build results array\n const results: SearchResult[] = [];\n\n for (const [docId, score] of docScores) {\n const doc = docs[docId];\n if (!doc) continue;\n\n results.push({\n route: doc.route,\n title: doc.title,\n score,\n snippet: generateSnippet(doc.markdown, query),\n matchingHeadings: findMatchingHeadings(doc, query),\n });\n }\n\n // Sort by score (highest first) and limit\n results.sort((a, b) => b.score - a.score);\n return results.slice(0, limit);\n}\n\n/**\n * Generate a snippet from the markdown content around the query terms\n */\nexport function generateSnippet(markdown: string, query: string): string {\n const maxLength = 200;\n const queryTerms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n\n if (queryTerms.length === 0) {\n return markdown.slice(0, maxLength) + (markdown.length > maxLength ? '...' : '');\n }\n\n const lowerMarkdown = markdown.toLowerCase();\n let bestIndex = -1;\n let bestTerm = '';\n\n // Also try stemmed versions of query terms\n const allTerms = [...queryTerms, ...queryTerms.map(englishStemmer)];\n\n for (const term of allTerms) {\n const index = lowerMarkdown.indexOf(term);\n if (index !== -1 && (bestIndex === -1 || index < bestIndex)) {\n bestIndex = index;\n bestTerm = term;\n }\n }\n\n if (bestIndex === -1) {\n // No term found, return beginning of document\n return markdown.slice(0, maxLength) + (markdown.length > maxLength ? '...' : '');\n }\n\n const snippetStart = Math.max(0, bestIndex - 50);\n const snippetEnd = Math.min(markdown.length, bestIndex + bestTerm.length + 150);\n\n let snippet = markdown.slice(snippetStart, snippetEnd);\n\n snippet = snippet\n // Remove markdown headings\n .replace(/^#{1,6}\\s+/gm, '')\n // Remove markdown links but keep text\n .replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, '$1')\n // Remove markdown images\n .replace(/!\\[([^\\]]*)\\]\\([^)]+\\)/g, '')\n // Remove code block markers\n .replace(/```[a-z]*\\n?/g, '')\n // Remove inline code backticks\n .replace(/`([^`]+)`/g, '$1')\n // Clean up whitespace\n .replace(/\\s+/g, ' ')\n .trim();\n\n const prefix = snippetStart > 0 ? '...' : '';\n const suffix = snippetEnd < markdown.length ? '...' : '';\n\n return prefix + snippet + suffix;\n}\n\n/**\n * Find headings that match the query (including stemmed forms)\n */\nfunction findMatchingHeadings(doc: ProcessedDoc, query: string): string[] {\n const queryTerms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n // Include stemmed versions for better matching\n const allTerms = [...queryTerms, ...queryTerms.map(englishStemmer)];\n const matching: string[] = [];\n\n for (const heading of doc.headings) {\n const headingLower = heading.text.toLowerCase();\n const headingStemmed = headingLower.split(/\\s+/).map(englishStemmer).join(' ');\n\n // Check if any query term matches the heading or its stemmed form\n if (\n allTerms.some(\n (term) => headingLower.includes(term) || headingStemmed.includes(englishStemmer(term))\n )\n ) {\n matching.push(heading.text);\n }\n }\n\n return matching.slice(0, 3); // Limit to 3 matching headings\n}\n\n/**\n * Export the search index to a serializable format\n */\nexport async function exportSearchIndex(index: FlexSearchDocument): Promise<unknown> {\n const exportData: Record<string, unknown> = {};\n\n await index.export((key, data) => {\n exportData[key as string] = data;\n });\n\n return exportData;\n}\n\n/**\n * Import a search index from serialized data\n */\nexport async function importSearchIndex(\n data: Record<string, unknown>\n): Promise<FlexSearchDocument> {\n const index = createSearchIndex();\n\n for (const [key, value] of Object.entries(data)) {\n // FlexSearch's import expects the data in a specific format\n await (index as unknown as { import: (key: string, data: unknown) => Promise<void> }).import(\n key,\n value\n );\n }\n\n return index;\n}\n","import type { ProcessedDoc, SearchResult, DocsSearchParams } from '../../types/index.js';\nimport { searchIndex, type FlexSearchDocument } from '../../search/flexsearch-indexer.js';\n\n/**\n * Tool definition for docs_search\n */\nexport const docsSearchTool = {\n name: 'docs_search',\n description:\n 'Search across developer documentation. Returns ranked results with snippets and matching headings.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n query: {\n type: 'string',\n description: 'Search query string',\n },\n limit: {\n type: 'number',\n description: 'Maximum number of results to return (default: 5, max: 20)',\n default: 5,\n },\n },\n required: ['query'],\n },\n};\n\n/**\n * Execute the docs_search tool\n */\nexport function executeDocsSearch(\n params: DocsSearchParams,\n index: FlexSearchDocument,\n docs: Record<string, ProcessedDoc>\n): SearchResult[] {\n const { query, limit = 5 } = params;\n\n // Validate parameters\n if (!query || typeof query !== 'string' || query.trim().length === 0) {\n throw new Error('Query parameter is required and must be a non-empty string');\n }\n\n const effectiveLimit = Math.min(Math.max(1, limit), 20);\n\n // Search the index\n const results = searchIndex(index, docs, query.trim(), {\n limit: effectiveLimit,\n });\n\n return results;\n}\n\n/**\n * Format search results for MCP response\n */\nexport function formatSearchResults(results: SearchResult[], baseUrl?: string): string {\n if (results.length === 0) {\n return 'No matching documents found.';\n }\n\n const lines: string[] = [`Found ${results.length} result(s):\\n`];\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n if (!result) continue;\n\n lines.push(`${i + 1}. **${result.title}**`);\n\n // Include full URL if baseUrl is provided\n if (baseUrl) {\n const fullUrl = `${baseUrl.replace(/\\/$/, '')}${result.route}`;\n lines.push(` URL: ${fullUrl}`);\n }\n\n lines.push(` Route: ${result.route}`);\n\n if (result.matchingHeadings && result.matchingHeadings.length > 0) {\n lines.push(` Matching sections: ${result.matchingHeadings.join(', ')}`);\n }\n\n lines.push(` ${result.snippet}`);\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n","import type { ProcessedDoc, DocsGetPageParams } from '../../types/index.js';\n\n/**\n * Tool definition for docs_get_page\n */\nexport const docsGetPageTool = {\n name: 'docs_get_page',\n description:\n 'Retrieve the full content of a documentation page as markdown. Use this after searching to get complete page content.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n route: {\n type: 'string',\n description: 'The route path of the page (e.g., /docs/getting-started)',\n },\n },\n required: ['route'],\n },\n};\n\n/**\n * Execute the docs_get_page tool\n */\nexport function executeDocsGetPage(\n params: DocsGetPageParams,\n docs: Record<string, ProcessedDoc>\n): ProcessedDoc | null {\n const { route } = params;\n\n // Validate parameters\n if (!route || typeof route !== 'string') {\n throw new Error('Route parameter is required and must be a string');\n }\n\n // Normalize route (ensure leading slash, remove trailing slash)\n let normalizedRoute = route.trim();\n if (!normalizedRoute.startsWith('/')) {\n normalizedRoute = '/' + normalizedRoute;\n }\n if (normalizedRoute.length > 1 && normalizedRoute.endsWith('/')) {\n normalizedRoute = normalizedRoute.slice(0, -1);\n }\n\n // Look up the document\n const doc = docs[normalizedRoute];\n\n if (!doc) {\n // Try without leading slash\n const altRoute = normalizedRoute.slice(1);\n if (docs[altRoute]) {\n return docs[altRoute] ?? null;\n }\n return null;\n }\n\n return doc;\n}\n\n/**\n * Format page content for MCP response\n */\nexport function formatPageContent(doc: ProcessedDoc | null, baseUrl?: string): string {\n if (!doc) {\n return 'Page not found. Please check the route path and try again.';\n }\n\n const lines: string[] = [];\n\n // Header\n lines.push(`# ${doc.title}`);\n lines.push('');\n\n // Metadata\n if (doc.description) {\n lines.push(`> ${doc.description}`);\n lines.push('');\n }\n\n // Include full URL if baseUrl is provided\n if (baseUrl) {\n const fullUrl = `${baseUrl.replace(/\\/$/, '')}${doc.route}`;\n lines.push(`**URL:** ${fullUrl}`);\n }\n\n lines.push(`**Route:** ${doc.route}`);\n lines.push('');\n\n // Table of contents (if there are headings)\n if (doc.headings.length > 0) {\n lines.push('## Contents');\n lines.push('');\n for (const heading of doc.headings) {\n if (heading.level <= 3) {\n const indent = ' '.repeat(heading.level - 1);\n lines.push(`${indent}- [${heading.text}](#${heading.id})`);\n }\n }\n lines.push('');\n lines.push('---');\n lines.push('');\n }\n\n // Main content\n lines.push(doc.markdown);\n\n return lines.join('\\n');\n}\n","import type { DocHeading } from '../types/index.js';\n\n/**\n * Extract headings from markdown content with their positions\n */\nexport function extractHeadingsFromMarkdown(markdown: string): DocHeading[] {\n const headings: DocHeading[] = [];\n const lines = markdown.split('\\n');\n let currentOffset = 0;\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? '';\n const headingMatch = line.match(/^(#{1,6})\\s+(.+?)(?:\\s+\\{#([^}]+)\\})?$/);\n\n if (headingMatch) {\n const hashes = headingMatch[1] ?? '';\n const level = hashes.length;\n let text = headingMatch[2] ?? '';\n let id = headingMatch[3] ?? '';\n\n // If no explicit ID, generate one from text (Docusaurus style)\n if (!id) {\n id = generateHeadingId(text);\n }\n\n // Clean up text (remove any remaining markdown formatting)\n text = text.replace(/\\*\\*([^*]+)\\*\\*/g, '$1'); // Remove bold\n text = text.replace(/_([^_]+)_/g, '$1'); // Remove italic\n text = text.replace(/`([^`]+)`/g, '$1'); // Remove code\n\n headings.push({\n level,\n text: text.trim(),\n id,\n startOffset: currentOffset,\n endOffset: -1, // Will be calculated below\n });\n }\n\n currentOffset += line.length + 1; // +1 for newline\n }\n\n // Calculate end offsets (each heading ends where the next same-or-higher level heading starts)\n for (let i = 0; i < headings.length; i++) {\n const current = headings[i];\n if (!current) continue;\n\n let endOffset = markdown.length;\n\n // Find the next heading at the same or higher level\n for (let j = i + 1; j < headings.length; j++) {\n const next = headings[j];\n if (next && next.level <= current.level) {\n endOffset = next.startOffset;\n break;\n }\n }\n\n current.endOffset = endOffset;\n }\n\n return headings;\n}\n\n/**\n * Generate a URL-safe heading ID (Docusaurus style)\n */\nexport function generateHeadingId(text: string): string {\n return (\n text\n .toLowerCase()\n // Remove any non-alphanumeric characters except spaces and hyphens\n .replace(/[^\\w\\s-]/g, '')\n // Replace spaces with hyphens\n .replace(/\\s+/g, '-')\n // Remove consecutive hyphens\n .replace(/-+/g, '-')\n // Remove leading/trailing hyphens\n .replace(/^-|-$/g, '')\n );\n}\n\n/**\n * Extract a specific section from markdown by heading ID\n */\nexport function extractSection(\n markdown: string,\n headingId: string,\n headings: DocHeading[]\n): string | null {\n const heading = headings.find((h) => h.id === headingId);\n\n if (!heading) {\n return null;\n }\n\n return markdown.slice(heading.startOffset, heading.endOffset).trim();\n}\n","import type { ProcessedDoc, DocsGetSectionParams } from '../../types/index.js';\nimport { extractSection } from '../../processing/heading-extractor.js';\n\n/**\n * Tool definition for docs_get_section\n */\nexport const docsGetSectionTool = {\n name: 'docs_get_section',\n description:\n 'Retrieve a specific section of a documentation page by heading ID. Use this to get focused content from a larger page.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n route: {\n type: 'string',\n description: 'The route path of the page (e.g., /docs/getting-started)',\n },\n headingId: {\n type: 'string',\n description: 'The ID of the heading to retrieve (e.g., authentication)',\n },\n },\n required: ['route', 'headingId'],\n },\n};\n\n/**\n * Result of executing docs_get_section\n */\nexport interface SectionResult {\n /** The section content as markdown */\n content: string | null;\n /** The document the section belongs to */\n doc: ProcessedDoc | null;\n /** The heading text */\n headingText: string | null;\n /** Available headings in the document */\n availableHeadings: Array<{ id: string; text: string; level: number }>;\n}\n\n/**\n * Execute the docs_get_section tool\n */\nexport function executeDocsGetSection(\n params: DocsGetSectionParams,\n docs: Record<string, ProcessedDoc>\n): SectionResult {\n const { route, headingId } = params;\n\n // Validate parameters\n if (!route || typeof route !== 'string') {\n throw new Error('Route parameter is required and must be a string');\n }\n if (!headingId || typeof headingId !== 'string') {\n throw new Error('HeadingId parameter is required and must be a string');\n }\n\n // Normalize route\n let normalizedRoute = route.trim();\n if (!normalizedRoute.startsWith('/')) {\n normalizedRoute = '/' + normalizedRoute;\n }\n if (normalizedRoute.length > 1 && normalizedRoute.endsWith('/')) {\n normalizedRoute = normalizedRoute.slice(0, -1);\n }\n\n // Look up the document\n const doc = docs[normalizedRoute];\n\n if (!doc) {\n return {\n content: null,\n doc: null,\n headingText: null,\n availableHeadings: [],\n };\n }\n\n // Get available headings\n const availableHeadings = doc.headings.map((h) => ({\n id: h.id,\n text: h.text,\n level: h.level,\n }));\n\n // Find the heading\n const heading = doc.headings.find((h) => h.id === headingId.trim());\n\n if (!heading) {\n return {\n content: null,\n doc,\n headingText: null,\n availableHeadings,\n };\n }\n\n // Extract the section content\n const content = extractSection(doc.markdown, headingId.trim(), doc.headings);\n\n return {\n content,\n doc,\n headingText: heading.text,\n availableHeadings,\n };\n}\n\n/**\n * Format section content for MCP response\n */\nexport function formatSectionContent(\n result: SectionResult,\n headingId: string,\n baseUrl?: string\n): string {\n if (!result.doc) {\n return 'Page not found. Please check the route path and try again.';\n }\n\n if (!result.content) {\n const lines = [`Section \"${headingId}\" not found in this document.`, '', 'Available sections:'];\n\n for (const heading of result.availableHeadings) {\n const indent = ' '.repeat(heading.level - 1);\n lines.push(`${indent}- ${heading.text} (id: ${heading.id})`);\n }\n\n return lines.join('\\n');\n }\n\n const lines: string[] = [];\n\n // Build URL with anchor if baseUrl is provided\n const fullUrl = baseUrl ? `${baseUrl.replace(/\\/$/, '')}${result.doc.route}#${headingId}` : null;\n\n // Header\n lines.push(`# ${result.headingText}`);\n if (fullUrl) {\n lines.push(`> From: ${result.doc.title} - ${fullUrl}`);\n } else {\n lines.push(`> From: ${result.doc.title} (${result.doc.route})`);\n }\n lines.push('');\n lines.push('---');\n lines.push('');\n\n // Section content\n lines.push(result.content);\n\n return lines.join('\\n');\n}\n","import fs from 'fs-extra';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';\nimport { z } from 'zod';\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport type {\n ProcessedDoc,\n McpServerConfig,\n McpServerFileConfig,\n McpServerDataConfig,\n} from '../types/index.js';\nimport { importSearchIndex, type FlexSearchDocument } from '../search/flexsearch-indexer.js';\nimport { executeDocsSearch, formatSearchResults } from './tools/docs-search.js';\nimport { executeDocsGetPage, formatPageContent } from './tools/docs-get-page.js';\nimport { executeDocsGetSection, formatSectionContent } from './tools/docs-get-section.js';\n\n/**\n * Type guard to check if config uses file-based loading\n */\nfunction isFileConfig(config: McpServerConfig): config is McpServerFileConfig {\n return 'docsPath' in config && 'indexPath' in config;\n}\n\n/**\n * Type guard to check if config uses pre-loaded data\n */\nfunction isDataConfig(config: McpServerConfig): config is McpServerDataConfig {\n return 'docs' in config && 'searchIndexData' in config;\n}\n\n/**\n * MCP Server for documentation\n *\n * This class provides the MCP server implementation that can be used\n * with any HTTP framework (Express, Vercel, Cloudflare Workers, etc.)\n *\n * Supports two modes:\n * - File-based: Load docs and search index from filesystem (Node.js)\n * - Pre-loaded: Accept docs and search index data directly (Workers)\n *\n * Uses the official MCP SDK for proper protocol handling.\n */\nexport class McpDocsServer {\n private config: McpServerConfig;\n private docs: Record<string, ProcessedDoc> | null = null;\n private searchIndex: FlexSearchDocument | null = null;\n private mcpServer: McpServer;\n private initialized = false;\n\n constructor(config: McpServerConfig) {\n this.config = config;\n\n // Create MCP server using the high-level API\n this.mcpServer = new McpServer(\n {\n name: config.name,\n version: config.version ?? '1.0.0',\n },\n {\n capabilities: {\n tools: {},\n },\n }\n );\n\n this.registerTools();\n }\n\n /**\n * Register all MCP tools using the SDK's registerTool API\n */\n private registerTools(): void {\n // docs_search - Search across documentation\n this.mcpServer.registerTool(\n 'docs_search',\n {\n description:\n 'Search the documentation for relevant pages. Returns matching documents with snippets and relevance scores. Use this to find information across all documentation.',\n inputSchema: {\n query: z.string().min(1).describe('The search query string'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(20)\n .optional()\n .default(5)\n .describe('Maximum number of results to return (1-20, default: 5)'),\n },\n },\n async ({ query, limit }) => {\n await this.initialize();\n\n if (!this.docs || !this.searchIndex) {\n return {\n content: [{ type: 'text' as const, text: 'Server not initialized. Please try again.' }],\n isError: true,\n };\n }\n\n const results = executeDocsSearch({ query, limit }, this.searchIndex, this.docs);\n return {\n content: [\n { type: 'text' as const, text: formatSearchResults(results, this.config.baseUrl) },\n ],\n };\n }\n );\n\n // docs_get_page - Retrieve full page content\n this.mcpServer.registerTool(\n 'docs_get_page',\n {\n description:\n 'Retrieve the complete content of a documentation page as markdown. Use this when you need the full content of a specific page.',\n inputSchema: {\n route: z\n .string()\n .min(1)\n .describe('The page route path (e.g., \"/docs/getting-started\" or \"/api/reference\")'),\n },\n },\n async ({ route }) => {\n await this.initialize();\n\n if (!this.docs) {\n return {\n content: [{ type: 'text' as const, text: 'Server not initialized. Please try again.' }],\n isError: true,\n };\n }\n\n const doc = executeDocsGetPage({ route }, this.docs);\n return {\n content: [{ type: 'text' as const, text: formatPageContent(doc, this.config.baseUrl) }],\n };\n }\n );\n\n // docs_get_section - Retrieve a specific section\n this.mcpServer.registerTool(\n 'docs_get_section',\n {\n description:\n 'Retrieve a specific section from a documentation page by its heading ID. Use this when you need only a portion of a page rather than the entire content.',\n inputSchema: {\n route: z.string().min(1).describe('The page route path'),\n headingId: z\n .string()\n .min(1)\n .describe(\n 'The heading ID of the section to extract (e.g., \"installation\", \"api-reference\")'\n ),\n },\n },\n async ({ route, headingId }) => {\n await this.initialize();\n\n if (!this.docs) {\n return {\n content: [{ type: 'text' as const, text: 'Server not initialized. Please try again.' }],\n isError: true,\n };\n }\n\n const result = executeDocsGetSection({ route, headingId }, this.docs);\n return {\n content: [\n {\n type: 'text' as const,\n text: formatSectionContent(result, headingId, this.config.baseUrl),\n },\n ],\n };\n }\n );\n }\n\n /**\n * Load docs and search index\n *\n * For file-based config: reads from disk\n * For data config: uses pre-loaded data directly\n */\n async initialize(): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n try {\n if (isDataConfig(this.config)) {\n // Pre-loaded data mode (Cloudflare Workers, etc.)\n this.docs = this.config.docs;\n this.searchIndex = await importSearchIndex(this.config.searchIndexData);\n } else if (isFileConfig(this.config)) {\n // File-based mode (Node.js)\n if (await fs.pathExists(this.config.docsPath)) {\n this.docs = await fs.readJson(this.config.docsPath);\n } else {\n throw new Error(`Docs file not found: ${this.config.docsPath}`);\n }\n\n if (await fs.pathExists(this.config.indexPath)) {\n const indexData = await fs.readJson(this.config.indexPath);\n this.searchIndex = await importSearchIndex(indexData);\n } else {\n throw new Error(`Search index not found: ${this.config.indexPath}`);\n }\n } else {\n throw new Error('Invalid server config: must provide either file paths or pre-loaded data');\n }\n\n this.initialized = true;\n } catch (error) {\n console.error('[MCP] Failed to initialize:', error);\n throw error;\n }\n }\n\n /**\n * Handle an HTTP request using the MCP SDK's transport\n *\n * This method is designed for serverless environments (Vercel, Netlify).\n * It creates a stateless transport instance and processes the request.\n *\n * @param req - Node.js IncomingMessage or compatible request object\n * @param res - Node.js ServerResponse or compatible response object\n * @param parsedBody - Optional pre-parsed request body\n */\n async handleHttpRequest(\n req: IncomingMessage,\n res: ServerResponse,\n parsedBody?: unknown\n ): Promise<void> {\n await this.initialize();\n\n // Create a stateless transport for this request\n // enableJsonResponse: true means we get simple JSON responses instead of SSE\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined, // Stateless mode - no session tracking\n enableJsonResponse: true, // Return JSON instead of SSE streams\n });\n\n // Connect the server to this transport\n await this.mcpServer.connect(transport);\n\n try {\n // Let the transport handle the request\n await transport.handleRequest(req, res, parsedBody);\n } finally {\n // Clean up the transport after request\n await transport.close();\n }\n }\n\n /**\n * Handle a Web Standard Request (Cloudflare Workers, Deno, Bun)\n *\n * This method is designed for Web Standard environments that use\n * the Fetch API Request/Response pattern.\n *\n * @param request - Web Standard Request object\n * @returns Web Standard Response object\n */\n async handleWebRequest(request: Request): Promise<Response> {\n await this.initialize();\n\n // Create a stateless transport for Web Standards\n const transport = new WebStandardStreamableHTTPServerTransport({\n sessionIdGenerator: undefined, // Stateless mode\n enableJsonResponse: true,\n });\n\n // Connect the server to this transport\n await this.mcpServer.connect(transport);\n\n try {\n // Let the transport handle the request and return the response\n return await transport.handleRequest(request);\n } finally {\n // Clean up the transport after request\n await transport.close();\n }\n }\n\n /**\n * Get server status information\n *\n * Useful for health checks and debugging\n */\n async getStatus(): Promise<{\n name: string;\n version: string;\n initialized: boolean;\n docCount: number;\n baseUrl?: string;\n }> {\n return {\n name: this.config.name,\n version: this.config.version ?? '1.0.0',\n initialized: this.initialized,\n docCount: this.docs ? Object.keys(this.docs).length : 0,\n baseUrl: this.config.baseUrl,\n };\n }\n\n /**\n * Get the underlying McpServer instance\n *\n * Useful for advanced use cases like custom transports\n */\n getMcpServer(): McpServer {\n return this.mcpServer;\n }\n}\n","/**\n * Vercel adapter for MCP server\n *\n * Creates a Vercel serverless function handler for the MCP server.\n *\n * @example\n * // api/mcp.js\n * const { createVercelHandler } = require('docusaurus-plugin-mcp-server/adapters');\n * const path = require('path');\n *\n * module.exports = createVercelHandler({\n * docsPath: path.join(__dirname, '../build/mcp/docs.json'),\n * indexPath: path.join(__dirname, '../build/mcp/search-index.json'),\n * name: 'my-docs',\n * baseUrl: 'https://docs.example.com',\n * });\n */\n\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport { McpDocsServer } from '../mcp/server.js';\nimport type { McpServerConfig } from '../types/index.js';\n\n/**\n * Vercel request object (extends Node.js IncomingMessage)\n */\nexport interface VercelRequest extends IncomingMessage {\n body?: unknown;\n}\n\n/**\n * Vercel response object (extends Node.js ServerResponse)\n */\nexport interface VercelResponse extends ServerResponse {\n status(code: number): VercelResponse;\n json(data: unknown): void;\n}\n\n/**\n * Create a Vercel serverless function handler for the MCP server\n *\n * Uses the MCP SDK's StreamableHTTPServerTransport for proper protocol handling.\n */\nexport function createVercelHandler(config: McpServerConfig) {\n let server: McpDocsServer | null = null;\n\n function getServer(): McpDocsServer {\n if (!server) {\n server = new McpDocsServer(config);\n }\n return server;\n }\n\n return async function handler(req: VercelRequest, res: VercelResponse) {\n // Handle GET requests for health check\n if (req.method === 'GET') {\n const mcpServer = getServer();\n const status = await mcpServer.getStatus();\n return res.status(200).json(status);\n }\n\n // Only allow POST requests for MCP\n if (req.method !== 'POST') {\n return res.status(405).json({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32600,\n message: 'Method not allowed. Use POST for MCP requests, GET for status.',\n },\n });\n }\n\n try {\n const mcpServer = getServer();\n // Use the SDK transport to handle the request\n await mcpServer.handleHttpRequest(req, res, req.body);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error('MCP Server Error:', error);\n return res.status(500).json({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32603,\n message: `Internal server error: ${errorMessage}`,\n },\n });\n }\n };\n}\n","/**\n * Netlify adapter for MCP server\n *\n * Creates a Netlify serverless function handler for the MCP server.\n * Converts Netlify's AWS Lambda-style events to Web Standard Request\n * and uses the MCP SDK's transport for proper protocol handling.\n *\n * @example\n * // netlify/functions/mcp.js\n * const { createNetlifyHandler } = require('docusaurus-plugin-mcp-server/adapters');\n * const path = require('path');\n *\n * exports.handler = createNetlifyHandler({\n * docsPath: path.join(__dirname, '../../build/mcp/docs.json'),\n * indexPath: path.join(__dirname, '../../build/mcp/search-index.json'),\n * name: 'my-docs',\n * baseUrl: 'https://docs.example.com',\n * });\n */\n\nimport { McpDocsServer } from '../mcp/server.js';\nimport type { McpServerConfig } from '../types/index.js';\n\n/**\n * Netlify event object (simplified interface)\n */\nexport interface NetlifyEvent {\n httpMethod: string;\n headers: Record<string, string | undefined>;\n body: string | null;\n isBase64Encoded?: boolean;\n path?: string;\n rawUrl?: string;\n}\n\n/**\n * Netlify context object (simplified interface)\n */\nexport interface NetlifyContext {\n functionName: string;\n functionVersion?: string;\n invokedFunctionArn?: string;\n memoryLimitInMB?: string;\n awsRequestId?: string;\n logGroupName?: string;\n logStreamName?: string;\n getRemainingTimeInMillis?: () => number;\n}\n\n/**\n * Netlify function response\n */\ninterface NetlifyResponse {\n statusCode: number;\n headers?: Record<string, string>;\n body?: string;\n}\n\n/**\n * Convert a Netlify event to a Web Standard Request\n */\nfunction eventToRequest(event: NetlifyEvent): Request {\n const url = event.rawUrl || `https://localhost${event.path || '/'}`;\n\n const headers = new Headers();\n for (const [key, value] of Object.entries(event.headers)) {\n if (value) {\n headers.set(key, value);\n }\n }\n\n // Decode body if base64 encoded\n let body: string | null = event.body;\n if (body && event.isBase64Encoded) {\n body = Buffer.from(body, 'base64').toString('utf-8');\n }\n\n return new Request(url, {\n method: event.httpMethod,\n headers,\n body: event.httpMethod !== 'GET' && event.httpMethod !== 'HEAD' ? body : undefined,\n });\n}\n\n/**\n * Convert a Web Standard Response to a Netlify response\n */\nasync function responseToNetlify(response: Response): Promise<NetlifyResponse> {\n const headers: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const body = await response.text();\n\n return {\n statusCode: response.status,\n headers,\n body: body || undefined,\n };\n}\n\n/**\n * Create a Netlify serverless function handler for the MCP server\n *\n * Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for\n * proper protocol handling.\n */\nexport function createNetlifyHandler(config: McpServerConfig) {\n let server: McpDocsServer | null = null;\n\n function getServer(): McpDocsServer {\n if (!server) {\n server = new McpDocsServer(config);\n }\n return server;\n }\n\n return async function handler(\n event: NetlifyEvent,\n _context: NetlifyContext\n ): Promise<NetlifyResponse> {\n const headers = {\n 'Content-Type': 'application/json',\n };\n\n // Handle GET requests for health check\n if (event.httpMethod === 'GET') {\n const mcpServer = getServer();\n const status = await mcpServer.getStatus();\n return {\n statusCode: 200,\n headers,\n body: JSON.stringify(status),\n };\n }\n\n // Only allow POST requests for MCP\n if (event.httpMethod !== 'POST') {\n return {\n statusCode: 405,\n headers,\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32600,\n message: 'Method not allowed. Use POST for MCP requests, GET for status.',\n },\n }),\n };\n }\n\n try {\n const mcpServer = getServer();\n\n // Convert Netlify event to Web Standard Request\n const request = eventToRequest(event);\n\n // Use the SDK's Web Standard transport to handle the request\n const response = await mcpServer.handleWebRequest(request);\n\n // Convert back to Netlify response format\n return await responseToNetlify(response);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error('MCP Server Error:', error);\n return {\n statusCode: 500,\n headers,\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32603,\n message: `Internal server error: ${errorMessage}`,\n },\n }),\n };\n }\n };\n}\n","/**\n * Cloudflare Workers adapter for MCP server\n *\n * Creates a Cloudflare Workers fetch handler for the MCP server.\n * Since Workers can't access the filesystem, this adapter requires\n * pre-loaded docs and search index data.\n *\n * Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for proper\n * protocol handling with Web Standard Request/Response.\n *\n * @example\n * // src/worker.js\n * import { createCloudflareHandler } from 'docusaurus-plugin-mcp-server/adapters';\n * import docs from '../build/mcp/docs.json';\n * import searchIndex from '../build/mcp/search-index.json';\n *\n * export default {\n * fetch: createCloudflareHandler({\n * docs,\n * searchIndexData: searchIndex,\n * name: 'my-docs',\n * baseUrl: 'https://docs.example.com',\n * }),\n * };\n */\n\nimport { McpDocsServer } from '../mcp/server.js';\nimport type { ProcessedDoc, McpServerDataConfig } from '../types/index.js';\n\n/**\n * Config for Cloudflare Workers adapter\n */\nexport interface CloudflareAdapterConfig {\n /** Pre-loaded docs data (imported from docs.json) */\n docs: Record<string, ProcessedDoc>;\n /** Pre-loaded search index data (imported from search-index.json) */\n searchIndexData: Record<string, unknown>;\n /** Server name */\n name: string;\n /** Server version */\n version?: string;\n /** Base URL for constructing full page URLs */\n baseUrl?: string;\n}\n\n/**\n * Create a Cloudflare Workers fetch handler for the MCP server\n *\n * Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for\n * proper protocol handling.\n */\nexport function createCloudflareHandler(config: CloudflareAdapterConfig) {\n let server: McpDocsServer | null = null;\n\n const serverConfig: McpServerDataConfig = {\n docs: config.docs,\n searchIndexData: config.searchIndexData,\n name: config.name,\n version: config.version,\n baseUrl: config.baseUrl,\n };\n\n function getServer(): McpDocsServer {\n if (!server) {\n server = new McpDocsServer(serverConfig);\n }\n return server;\n }\n\n return async function fetch(request: Request): Promise<Response> {\n const headers = {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type',\n };\n\n // Handle CORS preflight\n if (request.method === 'OPTIONS') {\n return new Response(null, { status: 204, headers });\n }\n\n // Handle GET requests for health check\n if (request.method === 'GET') {\n const mcpServer = getServer();\n const status = await mcpServer.getStatus();\n return new Response(JSON.stringify(status), {\n status: 200,\n headers: { ...headers, 'Content-Type': 'application/json' },\n });\n }\n\n // Only allow POST requests for MCP\n if (request.method !== 'POST') {\n return new Response(\n JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32600,\n message: 'Method not allowed. Use POST for MCP requests, GET for status.',\n },\n }),\n {\n status: 405,\n headers: { ...headers, 'Content-Type': 'application/json' },\n }\n );\n }\n\n try {\n const mcpServer = getServer();\n // Use the SDK's Web Standard transport to handle the request\n const response = await mcpServer.handleWebRequest(request);\n\n // Add CORS headers to the response\n const newHeaders = new Headers(response.headers);\n Object.entries(headers).forEach(([key, value]) => {\n newHeaders.set(key, value);\n });\n\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers: newHeaders,\n });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error('MCP Server Error:', error);\n return new Response(\n JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32603,\n message: `Internal server error: ${errorMessage}`,\n },\n }),\n {\n status: 500,\n headers: { ...headers, 'Content-Type': 'application/json' },\n }\n );\n }\n };\n}\n","/**\n * Adapter file generator\n *\n * Generates platform-specific adapter files for deploying the MCP server.\n */\n\nexport type Platform = 'vercel' | 'netlify' | 'cloudflare';\n\nexport interface GeneratorOptions {\n /** Target platform */\n platform: Platform;\n /** Server name */\n name: string;\n /** Base URL for the documentation site */\n baseUrl: string;\n /** Output path for the generated files (defaults to current directory) */\n outputPath?: string;\n}\n\nexport interface GeneratedFile {\n /** Relative path for the file */\n path: string;\n /** File contents */\n content: string;\n /** Description of the file */\n description: string;\n}\n\n/**\n * Generate adapter files for a specific platform\n */\nexport function generateAdapterFiles(options: GeneratorOptions): GeneratedFile[] {\n const { platform, name, baseUrl } = options;\n\n switch (platform) {\n case 'vercel':\n return generateVercelFiles(name, baseUrl);\n case 'netlify':\n return generateNetlifyFiles(name, baseUrl);\n case 'cloudflare':\n return generateCloudflareFiles(name, baseUrl);\n default:\n throw new Error(`Unknown platform: ${platform}`);\n }\n}\n\nfunction generateVercelFiles(name: string, baseUrl: string): GeneratedFile[] {\n return [\n {\n path: 'api/mcp.js',\n description: 'Vercel serverless function for MCP server',\n content: `/**\n * Vercel API route for MCP server\n * Deploy to Vercel and this will be available at /api/mcp\n */\n\nconst { createVercelHandler } = require('docusaurus-plugin-mcp-server/adapters');\nconst path = require('path');\n\nconst projectRoot = path.join(__dirname, '..');\n\nmodule.exports = createVercelHandler({\n docsPath: path.join(projectRoot, 'build/mcp/docs.json'),\n indexPath: path.join(projectRoot, 'build/mcp/search-index.json'),\n name: '${name}',\n version: '1.0.0',\n baseUrl: '${baseUrl}',\n});\n`,\n },\n {\n path: 'vercel.json',\n description: 'Vercel configuration (merge with existing if present)',\n content: `{\n \"functions\": {\n \"api/mcp.js\": {\n \"includeFiles\": \"build/mcp/**\"\n }\n },\n \"rewrites\": [\n {\n \"source\": \"/mcp\",\n \"destination\": \"/api/mcp\"\n }\n ]\n}\n`,\n },\n ];\n}\n\nfunction generateNetlifyFiles(name: string, baseUrl: string): GeneratedFile[] {\n return [\n {\n path: 'netlify/functions/mcp.js',\n description: 'Netlify serverless function for MCP server',\n content: `/**\n * Netlify function for MCP server\n * Deploy to Netlify and this will be available at /.netlify/functions/mcp\n */\n\nconst { createNetlifyHandler } = require('docusaurus-plugin-mcp-server/adapters');\nconst path = require('path');\n\nconst projectRoot = path.join(__dirname, '../..');\n\nexports.handler = createNetlifyHandler({\n docsPath: path.join(projectRoot, 'build/mcp/docs.json'),\n indexPath: path.join(projectRoot, 'build/mcp/search-index.json'),\n name: '${name}',\n version: '1.0.0',\n baseUrl: '${baseUrl}',\n});\n`,\n },\n {\n path: 'netlify.toml',\n description: 'Netlify configuration (merge with existing if present)',\n content: `[build]\n publish = \"build\"\n command = \"npm run build\"\n\n[functions]\n directory = \"netlify/functions\"\n included_files = [\"build/mcp/**\"]\n\n[[redirects]]\n from = \"/mcp\"\n to = \"/.netlify/functions/mcp\"\n status = 200\n`,\n },\n ];\n}\n\nfunction generateCloudflareFiles(name: string, baseUrl: string): GeneratedFile[] {\n return [\n {\n path: 'workers/mcp.js',\n description: 'Cloudflare Worker for MCP server',\n content: `/**\n * Cloudflare Worker for MCP server\n *\n * Note: This requires bundling docs.json and search-index.json with the worker,\n * or using Cloudflare KV/R2 for storage.\n *\n * For bundling, use wrangler with custom build configuration.\n */\n\nimport { createCloudflareHandler } from 'docusaurus-plugin-mcp-server/adapters';\n\n// Option 1: Import bundled data (requires bundler configuration)\n// import docs from '../build/mcp/docs.json';\n// import searchIndex from '../build/mcp/search-index.json';\n\n// Option 2: Use KV bindings (requires KV namespace configuration)\n// const docs = await env.MCP_KV.get('docs', { type: 'json' });\n// const searchIndex = await env.MCP_KV.get('search-index', { type: 'json' });\n\nexport default {\n fetch: createCloudflareHandler({\n name: '${name}',\n version: '1.0.0',\n baseUrl: '${baseUrl}',\n // docsPath and indexPath are used for file-based loading\n // For Workers, you'll need to configure data loading differently\n docsPath: './mcp/docs.json',\n indexPath: './mcp/search-index.json',\n }),\n};\n`,\n },\n {\n path: 'wrangler.toml',\n description: 'Cloudflare Wrangler configuration',\n content: `name = \"${name}-mcp\"\nmain = \"workers/mcp.js\"\ncompatibility_date = \"2024-01-01\"\n\n# Uncomment to use KV for storing docs\n# [[kv_namespaces]]\n# binding = \"MCP_KV\"\n# id = \"your-kv-namespace-id\"\n\n# Static assets (the Docusaurus build)\n# [site]\n# bucket = \"./build\"\n`,\n },\n ];\n}\n"]}
1
+ {"version":3,"sources":["../src/search/flexsearch-indexer.ts","../src/providers/search/flexsearch-provider.ts","../src/providers/loader.ts","../src/mcp/tools/docs-search.ts","../src/mcp/tools/docs-get-page.ts","../src/processing/heading-extractor.ts","../src/mcp/tools/docs-get-section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,EAAM,cAAA;AAAA,MACN,WAAA,EAAa,wDAAA;AAAA,MACb,OAAA,EAAS,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaX,GACF;AACF;AAEA,SAAS,uBAAA,CAAwB,MAAc,OAAA,EAAkC;AAC/E,EAAA,OAAO;AAAA,IACL;AAAA,MACE,IAAA,EAAM,gBAAA;AAAA,MACN,WAAA,EAAa,kCAAA;AAAA,MACb,OAAA,EAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,WAAA,EAqBF,IAAI,CAAA;AAAA;AAAA,cAAA,EAED,OAAO,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAQnB;AAAA,IACA;AAAA,MACE,IAAA,EAAM,eAAA;AAAA,MACN,WAAA,EAAa,mCAAA;AAAA,MACb,OAAA,EAAS,WAAW,IAAI,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAa1B,GACF;AACF","file":"adapters-entry.mjs","sourcesContent":["import FlexSearch from 'flexsearch';\nimport type { ProcessedDoc, SearchResult } from '../types/index.js';\nimport type { IndexableDocument } from './types.js';\n\nexport type FlexSearchDocument = FlexSearch.Document<IndexableDocument, string[]>;\n\n/**\n * Field weights for search ranking\n * Higher values = more importance\n */\nconst FIELD_WEIGHTS = {\n title: 3.0,\n headings: 2.0,\n description: 1.5,\n content: 1.0,\n} as const;\n\n/**\n * Simple English stemmer\n * Handles common suffixes for better matching\n */\nfunction englishStemmer(word: string): string {\n // Only process words longer than 3 characters\n if (word.length <= 3) return word;\n\n return (\n word\n // -ing endings\n .replace(/ing$/, '')\n // -tion, -sion endings -> t, s\n .replace(/tion$/, 't')\n .replace(/sion$/, 's')\n // -ed endings (careful with short words)\n .replace(/([^aeiou])ed$/, '$1')\n // -es endings\n .replace(/([^aeiou])es$/, '$1')\n // -ly endings\n .replace(/ly$/, '')\n // -ment endings\n .replace(/ment$/, '')\n // -ness endings\n .replace(/ness$/, '')\n // -ies -> y\n .replace(/ies$/, 'y')\n // -s endings (simple plural)\n .replace(/([^s])s$/, '$1')\n );\n}\n\n/**\n * Create a FlexSearch document index with enhanced configuration\n *\n * Features:\n * - Full substring matching (finds \"auth\" in \"authentication\")\n * - English stemming (finds \"authenticate\" when searching \"authentication\")\n * - Context-aware scoring for phrase matching\n * - Optimized resolution for relevance ranking\n */\nexport function createSearchIndex(): FlexSearchDocument {\n return new FlexSearch.Document<IndexableDocument, string[]>({\n // Use 'full' tokenization for substring matching\n // This allows \"auth\" to match \"authentication\"\n tokenize: 'full',\n\n // Enable caching for faster repeated queries\n cache: 100,\n\n // Higher resolution = more granular ranking (1-9)\n resolution: 9,\n\n // Enable context for phrase/proximity matching\n context: {\n resolution: 2,\n depth: 2,\n bidirectional: true,\n },\n\n // Apply stemming to normalize word forms\n encode: (str: string) => {\n // Normalize to lowercase and split into words\n const words = str.toLowerCase().split(/[\\s\\-_.,;:!?'\"()[\\]{}]+/);\n // Apply stemmer to each word\n return words.filter(Boolean).map(englishStemmer);\n },\n\n // Document schema\n document: {\n id: 'id',\n // Index these fields for searching\n index: ['title', 'content', 'headings', 'description'],\n // Store these fields in results (for enriched queries)\n store: ['title', 'description'],\n },\n });\n}\n\n/**\n * Add a document to the search index\n */\nexport function addDocumentToIndex(index: FlexSearchDocument, doc: ProcessedDoc): void {\n const indexable: IndexableDocument = {\n id: doc.route,\n title: doc.title,\n content: doc.markdown,\n headings: doc.headings.map((h) => h.text).join(' '),\n description: doc.description,\n };\n\n index.add(indexable);\n}\n\n/**\n * Build the search index from processed documents\n */\nexport function buildSearchIndex(docs: ProcessedDoc[]): FlexSearchDocument {\n const index = createSearchIndex();\n\n for (const doc of docs) {\n addDocumentToIndex(index, doc);\n }\n\n return index;\n}\n\n/**\n * Search the index and return results with weighted ranking\n *\n * Ranking combines:\n * - Field importance (title > headings > description > content)\n * - Position in results (earlier = more relevant)\n */\nexport function searchIndex(\n index: FlexSearchDocument,\n docs: Record<string, ProcessedDoc>,\n query: string,\n options: { limit?: number } = {}\n): SearchResult[] {\n const { limit = 5 } = options;\n\n // Search across all fields\n const rawResults = index.search(query, {\n limit: limit * 3, // Get extra results for better ranking after weighting\n enrich: true,\n });\n\n // Aggregate scores across fields with weighting\n const docScores = new Map<string, number>();\n\n for (const fieldResult of rawResults) {\n // Determine which field this result is from\n const field = fieldResult.field as keyof typeof FIELD_WEIGHTS;\n const fieldWeight = FIELD_WEIGHTS[field] ?? 1.0;\n\n // With enrich: true, results are objects with id property\n const results = fieldResult.result as unknown as Array<{ id: string } | string>;\n\n for (let i = 0; i < results.length; i++) {\n const item = results[i];\n if (!item) continue;\n\n const docId = typeof item === 'string' ? item : item.id;\n\n // Position-based score (earlier = higher)\n const positionScore = (results.length - i) / results.length;\n\n // Apply field weight to position score\n const weightedScore = positionScore * fieldWeight;\n\n // Combine with existing score (additive for multi-field matches)\n const existingScore = docScores.get(docId) ?? 0;\n docScores.set(docId, existingScore + weightedScore);\n }\n }\n\n // Build results array\n const results: SearchResult[] = [];\n\n for (const [docId, score] of docScores) {\n const doc = docs[docId];\n if (!doc) continue;\n\n results.push({\n route: doc.route,\n title: doc.title,\n score,\n snippet: generateSnippet(doc.markdown, query),\n matchingHeadings: findMatchingHeadings(doc, query),\n });\n }\n\n // Sort by score (highest first) and limit\n results.sort((a, b) => b.score - a.score);\n return results.slice(0, limit);\n}\n\n/**\n * Generate a snippet from the markdown content around the query terms\n */\nexport function generateSnippet(markdown: string, query: string): string {\n const maxLength = 200;\n const queryTerms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n\n if (queryTerms.length === 0) {\n return markdown.slice(0, maxLength) + (markdown.length > maxLength ? '...' : '');\n }\n\n const lowerMarkdown = markdown.toLowerCase();\n let bestIndex = -1;\n let bestTerm = '';\n\n // Also try stemmed versions of query terms\n const allTerms = [...queryTerms, ...queryTerms.map(englishStemmer)];\n\n for (const term of allTerms) {\n const index = lowerMarkdown.indexOf(term);\n if (index !== -1 && (bestIndex === -1 || index < bestIndex)) {\n bestIndex = index;\n bestTerm = term;\n }\n }\n\n if (bestIndex === -1) {\n // No term found, return beginning of document\n return markdown.slice(0, maxLength) + (markdown.length > maxLength ? '...' : '');\n }\n\n const snippetStart = Math.max(0, bestIndex - 50);\n const snippetEnd = Math.min(markdown.length, bestIndex + bestTerm.length + 150);\n\n let snippet = markdown.slice(snippetStart, snippetEnd);\n\n snippet = snippet\n // Remove markdown headings\n .replace(/^#{1,6}\\s+/gm, '')\n // Remove markdown links but keep text\n .replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, '$1')\n // Remove markdown images\n .replace(/!\\[([^\\]]*)\\]\\([^)]+\\)/g, '')\n // Remove code block markers\n .replace(/```[a-z]*\\n?/g, '')\n // Remove inline code backticks\n .replace(/`([^`]+)`/g, '$1')\n // Clean up whitespace\n .replace(/\\s+/g, ' ')\n .trim();\n\n const prefix = snippetStart > 0 ? '...' : '';\n const suffix = snippetEnd < markdown.length ? '...' : '';\n\n return prefix + snippet + suffix;\n}\n\n/**\n * Find headings that match the query (including stemmed forms)\n */\nfunction findMatchingHeadings(doc: ProcessedDoc, query: string): string[] {\n const queryTerms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n // Include stemmed versions for better matching\n const allTerms = [...queryTerms, ...queryTerms.map(englishStemmer)];\n const matching: string[] = [];\n\n for (const heading of doc.headings) {\n const headingLower = heading.text.toLowerCase();\n const headingStemmed = headingLower.split(/\\s+/).map(englishStemmer).join(' ');\n\n // Check if any query term matches the heading or its stemmed form\n if (\n allTerms.some(\n (term) => headingLower.includes(term) || headingStemmed.includes(englishStemmer(term))\n )\n ) {\n matching.push(heading.text);\n }\n }\n\n return matching.slice(0, 3); // Limit to 3 matching headings\n}\n\n/**\n * Export the search index to a serializable format\n */\nexport async function exportSearchIndex(index: FlexSearchDocument): Promise<unknown> {\n const exportData: Record<string, unknown> = {};\n\n await index.export((key, data) => {\n exportData[key as string] = data;\n });\n\n return exportData;\n}\n\n/**\n * Import a search index from serialized data\n */\nexport async function importSearchIndex(\n data: Record<string, unknown>\n): Promise<FlexSearchDocument> {\n const index = createSearchIndex();\n\n for (const [key, value] of Object.entries(data)) {\n // FlexSearch's import expects the data in a specific format\n await (index as unknown as { import: (key: string, data: unknown) => Promise<void> }).import(\n key,\n value\n );\n }\n\n return index;\n}\n","import fs from 'fs-extra';\nimport type { ProcessedDoc, SearchResult } from '../../types/index.js';\nimport type {\n SearchProvider,\n ProviderContext,\n SearchProviderInitData,\n SearchOptions,\n} from '../types.js';\nimport {\n importSearchIndex,\n searchIndex,\n type FlexSearchDocument,\n} from '../../search/flexsearch-indexer.js';\n\n/**\n * Built-in FlexSearch search provider.\n *\n * This provider uses the local FlexSearch index for search queries.\n * Supports both file-based loading (Node.js) and pre-loaded data (Workers).\n */\nexport class FlexSearchProvider implements SearchProvider {\n readonly name = 'flexsearch';\n\n private docs: Record<string, ProcessedDoc> | null = null;\n private searchIndex: FlexSearchDocument | null = null;\n private ready = false;\n\n async initialize(_context: ProviderContext, initData?: SearchProviderInitData): Promise<void> {\n if (!initData) {\n throw new Error('[FlexSearch] SearchProviderInitData required for FlexSearch provider');\n }\n\n // Pre-loaded data mode (Cloudflare Workers, etc.)\n if (initData.docs && initData.indexData) {\n this.docs = initData.docs;\n this.searchIndex = await importSearchIndex(initData.indexData as Record<string, unknown>);\n this.ready = true;\n return;\n }\n\n // File-based mode (Node.js)\n if (initData.docsPath && initData.indexPath) {\n if (await fs.pathExists(initData.docsPath)) {\n this.docs = await fs.readJson(initData.docsPath);\n } else {\n throw new Error(`[FlexSearch] Docs file not found: ${initData.docsPath}`);\n }\n\n if (await fs.pathExists(initData.indexPath)) {\n const indexData = await fs.readJson(initData.indexPath);\n this.searchIndex = await importSearchIndex(indexData);\n } else {\n throw new Error(`[FlexSearch] Search index not found: ${initData.indexPath}`);\n }\n\n this.ready = true;\n return;\n }\n\n throw new Error(\n '[FlexSearch] Invalid init data: must provide either file paths (docsPath, indexPath) or pre-loaded data (docs, indexData)'\n );\n }\n\n isReady(): boolean {\n return this.ready && this.docs !== null && this.searchIndex !== null;\n }\n\n async search(query: string, options?: SearchOptions): Promise<SearchResult[]> {\n if (!this.isReady() || !this.docs || !this.searchIndex) {\n throw new Error('[FlexSearch] Provider not initialized');\n }\n\n const limit = options?.limit ?? 5;\n return searchIndex(this.searchIndex, this.docs, query, { limit });\n }\n\n async getDocument(route: string): Promise<ProcessedDoc | null> {\n if (!this.docs) {\n throw new Error('[FlexSearch] Provider not initialized');\n }\n\n // Try exact match first\n if (this.docs[route]) {\n return this.docs[route];\n }\n\n // Try with/without leading slash\n const normalizedRoute = route.startsWith('/') ? route : `/${route}`;\n const withoutSlash = route.startsWith('/') ? route.slice(1) : route;\n\n return this.docs[normalizedRoute] ?? this.docs[withoutSlash] ?? null;\n }\n\n async healthCheck(): Promise<{ healthy: boolean; message?: string }> {\n if (!this.isReady()) {\n return { healthy: false, message: 'FlexSearch provider not initialized' };\n }\n\n const docCount = this.docs ? Object.keys(this.docs).length : 0;\n return {\n healthy: true,\n message: `FlexSearch provider ready with ${docCount} documents`,\n };\n }\n\n /**\n * Get all loaded documents (for compatibility with existing server code)\n */\n getDocs(): Record<string, ProcessedDoc> | null {\n return this.docs;\n }\n\n /**\n * Get the FlexSearch index (for compatibility with existing server code)\n */\n getSearchIndex(): FlexSearchDocument | null {\n return this.searchIndex;\n }\n}\n","import type { ContentIndexer, SearchProvider } from './types.js';\nimport { FlexSearchIndexer } from './indexers/flexsearch-indexer.js';\nimport { FlexSearchProvider } from './search/flexsearch-provider.js';\n\n/**\n * Load an indexer by name or module path.\n *\n * @param specifier - Either 'flexsearch' for the built-in indexer, or a module path\n * (relative path like './my-indexer.js' or npm package like '@myorg/indexer')\n * @returns Instantiated ContentIndexer\n *\n * @example\n * ```typescript\n * // Built-in\n * const indexer = await loadIndexer('flexsearch');\n *\n * // Custom relative path\n * const indexer = await loadIndexer('./src/providers/algolia-indexer.js');\n *\n * // Custom npm package\n * const indexer = await loadIndexer('@myorg/custom-indexer');\n * ```\n */\nexport async function loadIndexer(specifier: string): Promise<ContentIndexer> {\n // Built-in FlexSearch indexer\n if (specifier === 'flexsearch') {\n return new FlexSearchIndexer();\n }\n\n try {\n const module = await import(specifier);\n const IndexerClass = module.default;\n\n if (typeof IndexerClass === 'function') {\n // It's a class constructor\n const instance = new IndexerClass();\n\n if (!isContentIndexer(instance)) {\n throw new Error(\n `Invalid indexer module \"${specifier}\": does not implement ContentIndexer interface`\n );\n }\n\n return instance;\n }\n\n if (isContentIndexer(IndexerClass)) {\n return IndexerClass;\n }\n\n throw new Error(\n `Invalid indexer module \"${specifier}\": must export a default class or ContentIndexer instance`\n );\n } catch (error) {\n if (error instanceof Error && error.message.includes('Cannot find module')) {\n throw new Error(`Indexer module not found: \"${specifier}\". Check the path or package name.`);\n }\n throw error;\n }\n}\n\n/**\n * Load a search provider by name or module path.\n *\n * @param specifier - Either 'flexsearch' for the built-in provider, or a module path\n * (relative path like './my-search.js' or npm package like '@myorg/search')\n * @returns Instantiated SearchProvider\n *\n * @example\n * ```typescript\n * // Built-in\n * const provider = await loadSearchProvider('flexsearch');\n *\n * // Custom relative path\n * const provider = await loadSearchProvider('./src/providers/glean-search.js');\n *\n * // Custom npm package\n * const provider = await loadSearchProvider('@myorg/glean-search');\n * ```\n */\nexport async function loadSearchProvider(specifier: string): Promise<SearchProvider> {\n if (specifier === 'flexsearch') {\n return new FlexSearchProvider();\n }\n\n try {\n const module = await import(specifier);\n const ProviderClass = module.default;\n\n if (typeof ProviderClass === 'function') {\n const instance = new ProviderClass();\n\n if (!isSearchProvider(instance)) {\n throw new Error(\n `Invalid search provider module \"${specifier}\": does not implement SearchProvider interface`\n );\n }\n\n return instance;\n }\n\n if (isSearchProvider(ProviderClass)) {\n return ProviderClass;\n }\n\n throw new Error(\n `Invalid search provider module \"${specifier}\": must export a default class or SearchProvider instance`\n );\n } catch (error) {\n if (error instanceof Error && error.message.includes('Cannot find module')) {\n throw new Error(\n `Search provider module not found: \"${specifier}\". Check the path or package name.`\n );\n }\n throw error;\n }\n}\n\n/**\n * Type guard to check if an object implements ContentIndexer\n */\nfunction isContentIndexer(obj: unknown): obj is ContentIndexer {\n if (!obj || typeof obj !== 'object') {\n return false;\n }\n\n const indexer = obj as ContentIndexer;\n return (\n typeof indexer.name === 'string' &&\n typeof indexer.initialize === 'function' &&\n typeof indexer.indexDocuments === 'function' &&\n typeof indexer.finalize === 'function'\n );\n}\n\n/**\n * Type guard to check if an object implements SearchProvider\n */\nfunction isSearchProvider(obj: unknown): obj is SearchProvider {\n if (!obj || typeof obj !== 'object') {\n return false;\n }\n\n const provider = obj as SearchProvider;\n return (\n typeof provider.name === 'string' &&\n typeof provider.initialize === 'function' &&\n typeof provider.isReady === 'function' &&\n typeof provider.search === 'function'\n );\n}\n","import type { ProcessedDoc, SearchResult, DocsSearchParams } from '../../types/index.js';\nimport { searchIndex, type FlexSearchDocument } from '../../search/flexsearch-indexer.js';\n\n/**\n * Tool definition for docs_search\n */\nexport const docsSearchTool = {\n name: 'docs_search',\n description:\n 'Search across developer documentation. Returns ranked results with snippets and matching headings.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n query: {\n type: 'string',\n description: 'Search query string',\n },\n limit: {\n type: 'number',\n description: 'Maximum number of results to return (default: 5, max: 20)',\n default: 5,\n },\n },\n required: ['query'],\n },\n};\n\n/**\n * Execute the docs_search tool\n */\nexport function executeDocsSearch(\n params: DocsSearchParams,\n index: FlexSearchDocument,\n docs: Record<string, ProcessedDoc>\n): SearchResult[] {\n const { query, limit = 5 } = params;\n\n // Validate parameters\n if (!query || typeof query !== 'string' || query.trim().length === 0) {\n throw new Error('Query parameter is required and must be a non-empty string');\n }\n\n const effectiveLimit = Math.min(Math.max(1, limit), 20);\n\n // Search the index\n const results = searchIndex(index, docs, query.trim(), {\n limit: effectiveLimit,\n });\n\n return results;\n}\n\n/**\n * Format search results for MCP response\n */\nexport function formatSearchResults(results: SearchResult[], baseUrl?: string): string {\n if (results.length === 0) {\n return 'No matching documents found.';\n }\n\n const lines: string[] = [`Found ${results.length} result(s):\\n`];\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n if (!result) continue;\n\n lines.push(`${i + 1}. **${result.title}**`);\n\n // Include full URL if baseUrl is provided\n if (baseUrl) {\n const fullUrl = `${baseUrl.replace(/\\/$/, '')}${result.route}`;\n lines.push(` URL: ${fullUrl}`);\n }\n\n lines.push(` Route: ${result.route}`);\n\n if (result.matchingHeadings && result.matchingHeadings.length > 0) {\n lines.push(` Matching sections: ${result.matchingHeadings.join(', ')}`);\n }\n\n lines.push(` ${result.snippet}`);\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n","import type { ProcessedDoc, DocsGetPageParams } from '../../types/index.js';\n\n/**\n * Tool definition for docs_get_page\n */\nexport const docsGetPageTool = {\n name: 'docs_get_page',\n description:\n 'Retrieve the full content of a documentation page as markdown. Use this after searching to get complete page content.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n route: {\n type: 'string',\n description: 'The route path of the page (e.g., /docs/getting-started)',\n },\n },\n required: ['route'],\n },\n};\n\n/**\n * Execute the docs_get_page tool\n */\nexport function executeDocsGetPage(\n params: DocsGetPageParams,\n docs: Record<string, ProcessedDoc>\n): ProcessedDoc | null {\n const { route } = params;\n\n // Validate parameters\n if (!route || typeof route !== 'string') {\n throw new Error('Route parameter is required and must be a string');\n }\n\n // Normalize route (ensure leading slash, remove trailing slash)\n let normalizedRoute = route.trim();\n if (!normalizedRoute.startsWith('/')) {\n normalizedRoute = '/' + normalizedRoute;\n }\n if (normalizedRoute.length > 1 && normalizedRoute.endsWith('/')) {\n normalizedRoute = normalizedRoute.slice(0, -1);\n }\n\n // Look up the document\n const doc = docs[normalizedRoute];\n\n if (!doc) {\n // Try without leading slash\n const altRoute = normalizedRoute.slice(1);\n if (docs[altRoute]) {\n return docs[altRoute] ?? null;\n }\n return null;\n }\n\n return doc;\n}\n\n/**\n * Format page content for MCP response\n */\nexport function formatPageContent(doc: ProcessedDoc | null, baseUrl?: string): string {\n if (!doc) {\n return 'Page not found. Please check the route path and try again.';\n }\n\n const lines: string[] = [];\n\n // Header\n lines.push(`# ${doc.title}`);\n lines.push('');\n\n // Metadata\n if (doc.description) {\n lines.push(`> ${doc.description}`);\n lines.push('');\n }\n\n // Include full URL if baseUrl is provided\n if (baseUrl) {\n const fullUrl = `${baseUrl.replace(/\\/$/, '')}${doc.route}`;\n lines.push(`**URL:** ${fullUrl}`);\n }\n\n lines.push(`**Route:** ${doc.route}`);\n lines.push('');\n\n // Table of contents (if there are headings)\n if (doc.headings.length > 0) {\n lines.push('## Contents');\n lines.push('');\n for (const heading of doc.headings) {\n if (heading.level <= 3) {\n const indent = ' '.repeat(heading.level - 1);\n lines.push(`${indent}- [${heading.text}](#${heading.id})`);\n }\n }\n lines.push('');\n lines.push('---');\n lines.push('');\n }\n\n // Main content\n lines.push(doc.markdown);\n\n return lines.join('\\n');\n}\n","import type { DocHeading } from '../types/index.js';\n\n/**\n * Extract headings from markdown content with their positions\n */\nexport function extractHeadingsFromMarkdown(markdown: string): DocHeading[] {\n const headings: DocHeading[] = [];\n const lines = markdown.split('\\n');\n let currentOffset = 0;\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? '';\n const headingMatch = line.match(/^(#{1,6})\\s+(.+?)(?:\\s+\\{#([^}]+)\\})?$/);\n\n if (headingMatch) {\n const hashes = headingMatch[1] ?? '';\n const level = hashes.length;\n let text = headingMatch[2] ?? '';\n let id = headingMatch[3] ?? '';\n\n // If no explicit ID, generate one from text (Docusaurus style)\n if (!id) {\n id = generateHeadingId(text);\n }\n\n // Clean up text (remove any remaining markdown formatting)\n text = text.replace(/\\*\\*([^*]+)\\*\\*/g, '$1'); // Remove bold\n text = text.replace(/_([^_]+)_/g, '$1'); // Remove italic\n text = text.replace(/`([^`]+)`/g, '$1'); // Remove code\n\n headings.push({\n level,\n text: text.trim(),\n id,\n startOffset: currentOffset,\n endOffset: -1, // Will be calculated below\n });\n }\n\n currentOffset += line.length + 1; // +1 for newline\n }\n\n // Calculate end offsets (each heading ends where the next same-or-higher level heading starts)\n for (let i = 0; i < headings.length; i++) {\n const current = headings[i];\n if (!current) continue;\n\n let endOffset = markdown.length;\n\n // Find the next heading at the same or higher level\n for (let j = i + 1; j < headings.length; j++) {\n const next = headings[j];\n if (next && next.level <= current.level) {\n endOffset = next.startOffset;\n break;\n }\n }\n\n current.endOffset = endOffset;\n }\n\n return headings;\n}\n\n/**\n * Generate a URL-safe heading ID (Docusaurus style)\n */\nexport function generateHeadingId(text: string): string {\n return (\n text\n .toLowerCase()\n // Remove any non-alphanumeric characters except spaces and hyphens\n .replace(/[^\\w\\s-]/g, '')\n // Replace spaces with hyphens\n .replace(/\\s+/g, '-')\n // Remove consecutive hyphens\n .replace(/-+/g, '-')\n // Remove leading/trailing hyphens\n .replace(/^-|-$/g, '')\n );\n}\n\n/**\n * Extract a specific section from markdown by heading ID\n */\nexport function extractSection(\n markdown: string,\n headingId: string,\n headings: DocHeading[]\n): string | null {\n const heading = headings.find((h) => h.id === headingId);\n\n if (!heading) {\n return null;\n }\n\n return markdown.slice(heading.startOffset, heading.endOffset).trim();\n}\n","import type { ProcessedDoc, DocsGetSectionParams } from '../../types/index.js';\nimport { extractSection } from '../../processing/heading-extractor.js';\n\n/**\n * Tool definition for docs_get_section\n */\nexport const docsGetSectionTool = {\n name: 'docs_get_section',\n description:\n 'Retrieve a specific section of a documentation page by heading ID. Use this to get focused content from a larger page.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n route: {\n type: 'string',\n description: 'The route path of the page (e.g., /docs/getting-started)',\n },\n headingId: {\n type: 'string',\n description: 'The ID of the heading to retrieve (e.g., authentication)',\n },\n },\n required: ['route', 'headingId'],\n },\n};\n\n/**\n * Result of executing docs_get_section\n */\nexport interface SectionResult {\n /** The section content as markdown */\n content: string | null;\n /** The document the section belongs to */\n doc: ProcessedDoc | null;\n /** The heading text */\n headingText: string | null;\n /** Available headings in the document */\n availableHeadings: Array<{ id: string; text: string; level: number }>;\n}\n\n/**\n * Execute the docs_get_section tool\n */\nexport function executeDocsGetSection(\n params: DocsGetSectionParams,\n docs: Record<string, ProcessedDoc>\n): SectionResult {\n const { route, headingId } = params;\n\n // Validate parameters\n if (!route || typeof route !== 'string') {\n throw new Error('Route parameter is required and must be a string');\n }\n if (!headingId || typeof headingId !== 'string') {\n throw new Error('HeadingId parameter is required and must be a string');\n }\n\n // Normalize route\n let normalizedRoute = route.trim();\n if (!normalizedRoute.startsWith('/')) {\n normalizedRoute = '/' + normalizedRoute;\n }\n if (normalizedRoute.length > 1 && normalizedRoute.endsWith('/')) {\n normalizedRoute = normalizedRoute.slice(0, -1);\n }\n\n // Look up the document\n const doc = docs[normalizedRoute];\n\n if (!doc) {\n return {\n content: null,\n doc: null,\n headingText: null,\n availableHeadings: [],\n };\n }\n\n // Get available headings\n const availableHeadings = doc.headings.map((h) => ({\n id: h.id,\n text: h.text,\n level: h.level,\n }));\n\n // Find the heading\n const heading = doc.headings.find((h) => h.id === headingId.trim());\n\n if (!heading) {\n return {\n content: null,\n doc,\n headingText: null,\n availableHeadings,\n };\n }\n\n // Extract the section content\n const content = extractSection(doc.markdown, headingId.trim(), doc.headings);\n\n return {\n content,\n doc,\n headingText: heading.text,\n availableHeadings,\n };\n}\n\n/**\n * Format section content for MCP response\n */\nexport function formatSectionContent(\n result: SectionResult,\n headingId: string,\n baseUrl?: string\n): string {\n if (!result.doc) {\n return 'Page not found. Please check the route path and try again.';\n }\n\n if (!result.content) {\n const lines = [`Section \"${headingId}\" not found in this document.`, '', 'Available sections:'];\n\n for (const heading of result.availableHeadings) {\n const indent = ' '.repeat(heading.level - 1);\n lines.push(`${indent}- ${heading.text} (id: ${heading.id})`);\n }\n\n return lines.join('\\n');\n }\n\n const lines: string[] = [];\n\n // Build URL with anchor if baseUrl is provided\n const fullUrl = baseUrl ? `${baseUrl.replace(/\\/$/, '')}${result.doc.route}#${headingId}` : null;\n\n // Header\n lines.push(`# ${result.headingText}`);\n if (fullUrl) {\n lines.push(`> From: ${result.doc.title} - ${fullUrl}`);\n } else {\n lines.push(`> From: ${result.doc.title} (${result.doc.route})`);\n }\n lines.push('');\n lines.push('---');\n lines.push('');\n\n // Section content\n lines.push(result.content);\n\n return lines.join('\\n');\n}\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';\nimport { z } from 'zod';\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport type {\n ProcessedDoc,\n McpServerConfig,\n McpServerFileConfig,\n McpServerDataConfig,\n} from '../types/index.js';\nimport { loadSearchProvider } from '../providers/loader.js';\nimport { FlexSearchProvider } from '../providers/search/flexsearch-provider.js';\nimport type {\n SearchProvider,\n ProviderContext,\n SearchProviderInitData,\n} from '../providers/types.js';\nimport { formatSearchResults } from './tools/docs-search.js';\nimport { formatPageContent } from './tools/docs-get-page.js';\nimport { formatSectionContent } from './tools/docs-get-section.js';\nimport { extractSection } from '../processing/heading-extractor.js';\n\n/**\n * Type guard to check if config uses file-based loading\n */\nfunction isFileConfig(config: McpServerConfig): config is McpServerFileConfig {\n return 'docsPath' in config && 'indexPath' in config;\n}\n\n/**\n * Type guard to check if config uses pre-loaded data\n */\nfunction isDataConfig(config: McpServerConfig): config is McpServerDataConfig {\n return 'docs' in config && 'searchIndexData' in config;\n}\n\n/**\n * MCP Server for documentation\n *\n * This class provides the MCP server implementation that can be used\n * with any HTTP framework (Express, Vercel, Cloudflare Workers, etc.)\n *\n * Supports two modes:\n * - File-based: Load docs and search index from filesystem (Node.js)\n * - Pre-loaded: Accept docs and search index data directly (Workers)\n *\n * Uses the official MCP SDK for proper protocol handling.\n */\nexport class McpDocsServer {\n private config: McpServerConfig;\n private searchProvider: SearchProvider | null = null;\n private mcpServer: McpServer;\n private initialized = false;\n\n constructor(config: McpServerConfig) {\n this.config = config;\n\n // Create MCP server using the high-level API\n this.mcpServer = new McpServer(\n {\n name: config.name,\n version: config.version ?? '1.0.0',\n },\n {\n capabilities: {\n tools: {},\n },\n }\n );\n\n this.registerTools();\n }\n\n /**\n * Register all MCP tools using the SDK's registerTool API\n */\n private registerTools(): void {\n // docs_search - Search across documentation\n this.mcpServer.registerTool(\n 'docs_search',\n {\n description:\n 'Search the documentation for relevant pages. Returns matching documents with snippets and relevance scores. Use this to find information across all documentation.',\n inputSchema: {\n query: z.string().min(1).describe('The search query string'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(20)\n .optional()\n .default(5)\n .describe('Maximum number of results to return (1-20, default: 5)'),\n },\n },\n async ({ query, limit }) => {\n await this.initialize();\n\n if (!this.searchProvider || !this.searchProvider.isReady()) {\n return {\n content: [{ type: 'text' as const, text: 'Server not initialized. Please try again.' }],\n isError: true,\n };\n }\n\n try {\n const results = await this.searchProvider.search(query, { limit });\n return {\n content: [\n { type: 'text' as const, text: formatSearchResults(results, this.config.baseUrl) },\n ],\n };\n } catch (error) {\n console.error('[MCP] Search error:', error);\n return {\n content: [{ type: 'text' as const, text: `Search error: ${String(error)}` }],\n isError: true,\n };\n }\n }\n );\n\n // docs_get_page - Retrieve full page content\n this.mcpServer.registerTool(\n 'docs_get_page',\n {\n description:\n 'Retrieve the complete content of a documentation page as markdown. Use this when you need the full content of a specific page.',\n inputSchema: {\n route: z\n .string()\n .min(1)\n .describe('The page route path (e.g., \"/docs/getting-started\" or \"/api/reference\")'),\n },\n },\n async ({ route }) => {\n await this.initialize();\n\n if (!this.searchProvider || !this.searchProvider.isReady()) {\n return {\n content: [{ type: 'text' as const, text: 'Server not initialized. Please try again.' }],\n isError: true,\n };\n }\n\n try {\n const doc = await this.getDocument(route);\n return {\n content: [{ type: 'text' as const, text: formatPageContent(doc, this.config.baseUrl) }],\n };\n } catch (error) {\n console.error('[MCP] Get page error:', error);\n return {\n content: [{ type: 'text' as const, text: `Error getting page: ${String(error)}` }],\n isError: true,\n };\n }\n }\n );\n\n // docs_get_section - Retrieve a specific section\n this.mcpServer.registerTool(\n 'docs_get_section',\n {\n description:\n 'Retrieve a specific section from a documentation page by its heading ID. Use this when you need only a portion of a page rather than the entire content.',\n inputSchema: {\n route: z.string().min(1).describe('The page route path'),\n headingId: z\n .string()\n .min(1)\n .describe(\n 'The heading ID of the section to extract (e.g., \"installation\", \"api-reference\")'\n ),\n },\n },\n async ({ route, headingId }) => {\n await this.initialize();\n\n if (!this.searchProvider || !this.searchProvider.isReady()) {\n return {\n content: [{ type: 'text' as const, text: 'Server not initialized. Please try again.' }],\n isError: true,\n };\n }\n\n try {\n const doc = await this.getDocument(route);\n if (!doc) {\n return {\n content: [\n {\n type: 'text' as const,\n text: formatSectionContent(\n { content: null, doc: null, headingText: null, availableHeadings: [] },\n headingId,\n this.config.baseUrl\n ),\n },\n ],\n };\n }\n\n // Get available headings\n const availableHeadings = doc.headings.map((h) => ({\n id: h.id,\n text: h.text,\n level: h.level,\n }));\n\n // Find the heading\n const heading = doc.headings.find((h) => h.id === headingId.trim());\n\n if (!heading) {\n return {\n content: [\n {\n type: 'text' as const,\n text: formatSectionContent(\n { content: null, doc, headingText: null, availableHeadings },\n headingId,\n this.config.baseUrl\n ),\n },\n ],\n };\n }\n\n // Extract the section content\n const sectionContent = extractSection(doc.markdown, headingId.trim(), doc.headings);\n\n return {\n content: [\n {\n type: 'text' as const,\n text: formatSectionContent(\n { content: sectionContent, doc, headingText: heading.text, availableHeadings },\n headingId,\n this.config.baseUrl\n ),\n },\n ],\n };\n } catch (error) {\n console.error('[MCP] Get section error:', error);\n return {\n content: [{ type: 'text' as const, text: `Error getting section: ${String(error)}` }],\n isError: true,\n };\n }\n }\n );\n }\n\n /**\n * Get a document by route using the search provider\n */\n private async getDocument(route: string): Promise<ProcessedDoc | null> {\n if (!this.searchProvider) {\n return null;\n }\n\n // Use the provider's getDocument if available\n if (this.searchProvider.getDocument) {\n return this.searchProvider.getDocument(route);\n }\n\n // For FlexSearchProvider, we can access docs directly\n if (this.searchProvider instanceof FlexSearchProvider) {\n const docs = this.searchProvider.getDocs();\n if (!docs) return null;\n\n // Try exact match first\n if (docs[route]) {\n return docs[route];\n }\n\n // Try with/without leading slash\n const normalizedRoute = route.startsWith('/') ? route : `/${route}`;\n const withoutSlash = route.startsWith('/') ? route.slice(1) : route;\n\n return docs[normalizedRoute] ?? docs[withoutSlash] ?? null;\n }\n\n return null;\n }\n\n /**\n * Load docs and search index using the configured search provider\n *\n * For file-based config: reads from disk\n * For data config: uses pre-loaded data directly\n */\n async initialize(): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n try {\n // Load the search provider\n const searchSpecifier = this.config.search ?? 'flexsearch';\n this.searchProvider = await loadSearchProvider(searchSpecifier);\n\n // Build provider context\n const providerContext: ProviderContext = {\n baseUrl: this.config.baseUrl ?? '',\n serverName: this.config.name,\n serverVersion: this.config.version ?? '1.0.0',\n outputDir: '', // Not relevant for runtime\n };\n\n // Build init data based on config type\n const initData: SearchProviderInitData = {};\n\n if (isDataConfig(this.config)) {\n // Pre-loaded data mode (Cloudflare Workers, etc.)\n initData.docs = this.config.docs;\n initData.indexData = this.config.searchIndexData;\n } else if (isFileConfig(this.config)) {\n // File-based mode (Node.js)\n initData.docsPath = this.config.docsPath;\n initData.indexPath = this.config.indexPath;\n } else {\n throw new Error('Invalid server config: must provide either file paths or pre-loaded data');\n }\n\n // Initialize the search provider\n await this.searchProvider.initialize(providerContext, initData);\n\n this.initialized = true;\n } catch (error) {\n console.error('[MCP] Failed to initialize:', error);\n throw error;\n }\n }\n\n /**\n * Handle an HTTP request using the MCP SDK's transport\n *\n * This method is designed for serverless environments (Vercel, Netlify).\n * It creates a stateless transport instance and processes the request.\n *\n * @param req - Node.js IncomingMessage or compatible request object\n * @param res - Node.js ServerResponse or compatible response object\n * @param parsedBody - Optional pre-parsed request body\n */\n async handleHttpRequest(\n req: IncomingMessage,\n res: ServerResponse,\n parsedBody?: unknown\n ): Promise<void> {\n await this.initialize();\n\n // Create a stateless transport for this request\n // enableJsonResponse: true means we get simple JSON responses instead of SSE\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined, // Stateless mode - no session tracking\n enableJsonResponse: true, // Return JSON instead of SSE streams\n });\n\n // Connect the server to this transport\n await this.mcpServer.connect(transport);\n\n try {\n // Let the transport handle the request\n await transport.handleRequest(req, res, parsedBody);\n } finally {\n // Clean up the transport after request\n await transport.close();\n }\n }\n\n /**\n * Handle a Web Standard Request (Cloudflare Workers, Deno, Bun)\n *\n * This method is designed for Web Standard environments that use\n * the Fetch API Request/Response pattern.\n *\n * @param request - Web Standard Request object\n * @returns Web Standard Response object\n */\n async handleWebRequest(request: Request): Promise<Response> {\n await this.initialize();\n\n // Create a stateless transport for Web Standards\n const transport = new WebStandardStreamableHTTPServerTransport({\n sessionIdGenerator: undefined, // Stateless mode\n enableJsonResponse: true,\n });\n\n // Connect the server to this transport\n await this.mcpServer.connect(transport);\n\n try {\n // Let the transport handle the request and return the response\n return await transport.handleRequest(request);\n } finally {\n // Clean up the transport after request\n await transport.close();\n }\n }\n\n /**\n * Get server status information\n *\n * Useful for health checks and debugging\n */\n async getStatus(): Promise<{\n name: string;\n version: string;\n initialized: boolean;\n docCount: number;\n baseUrl?: string;\n searchProvider?: string;\n }> {\n let docCount = 0;\n\n // Get doc count from FlexSearchProvider if available\n if (this.searchProvider instanceof FlexSearchProvider) {\n const docs = this.searchProvider.getDocs();\n docCount = docs ? Object.keys(docs).length : 0;\n }\n\n return {\n name: this.config.name,\n version: this.config.version ?? '1.0.0',\n initialized: this.initialized,\n docCount,\n baseUrl: this.config.baseUrl,\n searchProvider: this.searchProvider?.name,\n };\n }\n\n /**\n * Get the underlying McpServer instance\n *\n * Useful for advanced use cases like custom transports\n */\n getMcpServer(): McpServer {\n return this.mcpServer;\n }\n}\n","/**\n * Vercel adapter for MCP server\n *\n * Creates a Vercel serverless function handler for the MCP server.\n *\n * @example\n * // api/mcp.js\n * const { createVercelHandler } = require('docusaurus-plugin-mcp-server/adapters');\n * const path = require('path');\n *\n * module.exports = createVercelHandler({\n * docsPath: path.join(__dirname, '../build/mcp/docs.json'),\n * indexPath: path.join(__dirname, '../build/mcp/search-index.json'),\n * name: 'my-docs',\n * baseUrl: 'https://docs.example.com',\n * });\n */\n\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport { McpDocsServer } from '../mcp/server.js';\nimport type { McpServerConfig } from '../types/index.js';\n\n/**\n * Vercel request object (extends Node.js IncomingMessage)\n */\nexport interface VercelRequest extends IncomingMessage {\n body?: unknown;\n}\n\n/**\n * Vercel response object (extends Node.js ServerResponse)\n */\nexport interface VercelResponse extends ServerResponse {\n status(code: number): VercelResponse;\n json(data: unknown): void;\n}\n\n/**\n * Create a Vercel serverless function handler for the MCP server\n *\n * Uses the MCP SDK's StreamableHTTPServerTransport for proper protocol handling.\n */\nexport function createVercelHandler(config: McpServerConfig) {\n let server: McpDocsServer | null = null;\n\n function getServer(): McpDocsServer {\n if (!server) {\n server = new McpDocsServer(config);\n }\n return server;\n }\n\n return async function handler(req: VercelRequest, res: VercelResponse) {\n // Handle GET requests for health check\n if (req.method === 'GET') {\n const mcpServer = getServer();\n const status = await mcpServer.getStatus();\n return res.status(200).json(status);\n }\n\n // Only allow POST requests for MCP\n if (req.method !== 'POST') {\n return res.status(405).json({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32600,\n message: 'Method not allowed. Use POST for MCP requests, GET for status.',\n },\n });\n }\n\n try {\n const mcpServer = getServer();\n // Use the SDK transport to handle the request\n await mcpServer.handleHttpRequest(req, res, req.body);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error('MCP Server Error:', error);\n return res.status(500).json({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32603,\n message: `Internal server error: ${errorMessage}`,\n },\n });\n }\n };\n}\n","/**\n * Netlify adapter for MCP server\n *\n * Creates a Netlify serverless function handler for the MCP server.\n * Converts Netlify's AWS Lambda-style events to Web Standard Request\n * and uses the MCP SDK's transport for proper protocol handling.\n *\n * @example\n * // netlify/functions/mcp.js\n * const { createNetlifyHandler } = require('docusaurus-plugin-mcp-server/adapters');\n * const path = require('path');\n *\n * exports.handler = createNetlifyHandler({\n * docsPath: path.join(__dirname, '../../build/mcp/docs.json'),\n * indexPath: path.join(__dirname, '../../build/mcp/search-index.json'),\n * name: 'my-docs',\n * baseUrl: 'https://docs.example.com',\n * });\n */\n\nimport { McpDocsServer } from '../mcp/server.js';\nimport type { McpServerConfig } from '../types/index.js';\n\n/**\n * Netlify event object (simplified interface)\n */\nexport interface NetlifyEvent {\n httpMethod: string;\n headers: Record<string, string | undefined>;\n body: string | null;\n isBase64Encoded?: boolean;\n path?: string;\n rawUrl?: string;\n}\n\n/**\n * Netlify context object (simplified interface)\n */\nexport interface NetlifyContext {\n functionName: string;\n functionVersion?: string;\n invokedFunctionArn?: string;\n memoryLimitInMB?: string;\n awsRequestId?: string;\n logGroupName?: string;\n logStreamName?: string;\n getRemainingTimeInMillis?: () => number;\n}\n\n/**\n * Netlify function response\n */\ninterface NetlifyResponse {\n statusCode: number;\n headers?: Record<string, string>;\n body?: string;\n}\n\n/**\n * Convert a Netlify event to a Web Standard Request\n */\nfunction eventToRequest(event: NetlifyEvent): Request {\n const url = event.rawUrl || `https://localhost${event.path || '/'}`;\n\n const headers = new Headers();\n for (const [key, value] of Object.entries(event.headers)) {\n if (value) {\n headers.set(key, value);\n }\n }\n\n // Decode body if base64 encoded\n let body: string | null = event.body;\n if (body && event.isBase64Encoded) {\n body = Buffer.from(body, 'base64').toString('utf-8');\n }\n\n return new Request(url, {\n method: event.httpMethod,\n headers,\n body: event.httpMethod !== 'GET' && event.httpMethod !== 'HEAD' ? body : undefined,\n });\n}\n\n/**\n * Convert a Web Standard Response to a Netlify response\n */\nasync function responseToNetlify(response: Response): Promise<NetlifyResponse> {\n const headers: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const body = await response.text();\n\n return {\n statusCode: response.status,\n headers,\n body: body || undefined,\n };\n}\n\n/**\n * Create a Netlify serverless function handler for the MCP server\n *\n * Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for\n * proper protocol handling.\n */\nexport function createNetlifyHandler(config: McpServerConfig) {\n let server: McpDocsServer | null = null;\n\n function getServer(): McpDocsServer {\n if (!server) {\n server = new McpDocsServer(config);\n }\n return server;\n }\n\n return async function handler(\n event: NetlifyEvent,\n _context: NetlifyContext\n ): Promise<NetlifyResponse> {\n const headers = {\n 'Content-Type': 'application/json',\n };\n\n // Handle GET requests for health check\n if (event.httpMethod === 'GET') {\n const mcpServer = getServer();\n const status = await mcpServer.getStatus();\n return {\n statusCode: 200,\n headers,\n body: JSON.stringify(status),\n };\n }\n\n // Only allow POST requests for MCP\n if (event.httpMethod !== 'POST') {\n return {\n statusCode: 405,\n headers,\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32600,\n message: 'Method not allowed. Use POST for MCP requests, GET for status.',\n },\n }),\n };\n }\n\n try {\n const mcpServer = getServer();\n\n // Convert Netlify event to Web Standard Request\n const request = eventToRequest(event);\n\n // Use the SDK's Web Standard transport to handle the request\n const response = await mcpServer.handleWebRequest(request);\n\n // Convert back to Netlify response format\n return await responseToNetlify(response);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error('MCP Server Error:', error);\n return {\n statusCode: 500,\n headers,\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32603,\n message: `Internal server error: ${errorMessage}`,\n },\n }),\n };\n }\n };\n}\n","/**\n * Cloudflare Workers adapter for MCP server\n *\n * Creates a Cloudflare Workers fetch handler for the MCP server.\n * Since Workers can't access the filesystem, this adapter requires\n * pre-loaded docs and search index data.\n *\n * Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for proper\n * protocol handling with Web Standard Request/Response.\n *\n * @example\n * // src/worker.js\n * import { createCloudflareHandler } from 'docusaurus-plugin-mcp-server/adapters';\n * import docs from '../build/mcp/docs.json';\n * import searchIndex from '../build/mcp/search-index.json';\n *\n * export default {\n * fetch: createCloudflareHandler({\n * docs,\n * searchIndexData: searchIndex,\n * name: 'my-docs',\n * baseUrl: 'https://docs.example.com',\n * }),\n * };\n */\n\nimport { McpDocsServer } from '../mcp/server.js';\nimport type { ProcessedDoc, McpServerDataConfig } from '../types/index.js';\n\n/**\n * Config for Cloudflare Workers adapter\n */\nexport interface CloudflareAdapterConfig {\n /** Pre-loaded docs data (imported from docs.json) */\n docs: Record<string, ProcessedDoc>;\n /** Pre-loaded search index data (imported from search-index.json) */\n searchIndexData: Record<string, unknown>;\n /** Server name */\n name: string;\n /** Server version */\n version?: string;\n /** Base URL for constructing full page URLs */\n baseUrl?: string;\n}\n\n/**\n * Create a Cloudflare Workers fetch handler for the MCP server\n *\n * Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for\n * proper protocol handling.\n */\nexport function createCloudflareHandler(config: CloudflareAdapterConfig) {\n let server: McpDocsServer | null = null;\n\n const serverConfig: McpServerDataConfig = {\n docs: config.docs,\n searchIndexData: config.searchIndexData,\n name: config.name,\n version: config.version,\n baseUrl: config.baseUrl,\n };\n\n function getServer(): McpDocsServer {\n if (!server) {\n server = new McpDocsServer(serverConfig);\n }\n return server;\n }\n\n return async function fetch(request: Request): Promise<Response> {\n const headers = {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type',\n };\n\n // Handle CORS preflight\n if (request.method === 'OPTIONS') {\n return new Response(null, { status: 204, headers });\n }\n\n // Handle GET requests for health check\n if (request.method === 'GET') {\n const mcpServer = getServer();\n const status = await mcpServer.getStatus();\n return new Response(JSON.stringify(status), {\n status: 200,\n headers: { ...headers, 'Content-Type': 'application/json' },\n });\n }\n\n // Only allow POST requests for MCP\n if (request.method !== 'POST') {\n return new Response(\n JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32600,\n message: 'Method not allowed. Use POST for MCP requests, GET for status.',\n },\n }),\n {\n status: 405,\n headers: { ...headers, 'Content-Type': 'application/json' },\n }\n );\n }\n\n try {\n const mcpServer = getServer();\n // Use the SDK's Web Standard transport to handle the request\n const response = await mcpServer.handleWebRequest(request);\n\n // Add CORS headers to the response\n const newHeaders = new Headers(response.headers);\n Object.entries(headers).forEach(([key, value]) => {\n newHeaders.set(key, value);\n });\n\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers: newHeaders,\n });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error('MCP Server Error:', error);\n return new Response(\n JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32603,\n message: `Internal server error: ${errorMessage}`,\n },\n }),\n {\n status: 500,\n headers: { ...headers, 'Content-Type': 'application/json' },\n }\n );\n }\n };\n}\n","/**\n * Adapter file generator\n *\n * Generates platform-specific adapter files for deploying the MCP server.\n */\n\nexport type Platform = 'vercel' | 'netlify' | 'cloudflare';\n\nexport interface GeneratorOptions {\n /** Target platform */\n platform: Platform;\n /** Server name */\n name: string;\n /** Base URL for the documentation site */\n baseUrl: string;\n /** Output path for the generated files (defaults to current directory) */\n outputPath?: string;\n}\n\nexport interface GeneratedFile {\n /** Relative path for the file */\n path: string;\n /** File contents */\n content: string;\n /** Description of the file */\n description: string;\n}\n\n/**\n * Generate adapter files for a specific platform\n */\nexport function generateAdapterFiles(options: GeneratorOptions): GeneratedFile[] {\n const { platform, name, baseUrl } = options;\n\n switch (platform) {\n case 'vercel':\n return generateVercelFiles(name, baseUrl);\n case 'netlify':\n return generateNetlifyFiles(name, baseUrl);\n case 'cloudflare':\n return generateCloudflareFiles(name, baseUrl);\n default:\n throw new Error(`Unknown platform: ${platform}`);\n }\n}\n\nfunction generateVercelFiles(name: string, baseUrl: string): GeneratedFile[] {\n return [\n {\n path: 'api/mcp.js',\n description: 'Vercel serverless function for MCP server',\n content: `/**\n * Vercel API route for MCP server\n * Deploy to Vercel and this will be available at /api/mcp\n */\n\nconst { createVercelHandler } = require('docusaurus-plugin-mcp-server/adapters');\nconst path = require('path');\n\nconst projectRoot = path.join(__dirname, '..');\n\nmodule.exports = createVercelHandler({\n docsPath: path.join(projectRoot, 'build/mcp/docs.json'),\n indexPath: path.join(projectRoot, 'build/mcp/search-index.json'),\n name: '${name}',\n version: '1.0.0',\n baseUrl: '${baseUrl}',\n});\n`,\n },\n {\n path: 'vercel.json',\n description: 'Vercel configuration (merge with existing if present)',\n content: `{\n \"functions\": {\n \"api/mcp.js\": {\n \"includeFiles\": \"build/mcp/**\"\n }\n },\n \"rewrites\": [\n {\n \"source\": \"/mcp\",\n \"destination\": \"/api/mcp\"\n }\n ]\n}\n`,\n },\n ];\n}\n\nfunction generateNetlifyFiles(name: string, baseUrl: string): GeneratedFile[] {\n return [\n {\n path: 'netlify/functions/mcp.js',\n description: 'Netlify serverless function for MCP server',\n content: `/**\n * Netlify function for MCP server\n * Deploy to Netlify and this will be available at /.netlify/functions/mcp\n */\n\nconst { createNetlifyHandler } = require('docusaurus-plugin-mcp-server/adapters');\nconst path = require('path');\n\nconst projectRoot = path.join(__dirname, '../..');\n\nexports.handler = createNetlifyHandler({\n docsPath: path.join(projectRoot, 'build/mcp/docs.json'),\n indexPath: path.join(projectRoot, 'build/mcp/search-index.json'),\n name: '${name}',\n version: '1.0.0',\n baseUrl: '${baseUrl}',\n});\n`,\n },\n {\n path: 'netlify.toml',\n description: 'Netlify configuration (merge with existing if present)',\n content: `[build]\n publish = \"build\"\n command = \"npm run build\"\n\n[functions]\n directory = \"netlify/functions\"\n included_files = [\"build/mcp/**\"]\n\n[[redirects]]\n from = \"/mcp\"\n to = \"/.netlify/functions/mcp\"\n status = 200\n`,\n },\n ];\n}\n\nfunction generateCloudflareFiles(name: string, baseUrl: string): GeneratedFile[] {\n return [\n {\n path: 'workers/mcp.js',\n description: 'Cloudflare Worker for MCP server',\n content: `/**\n * Cloudflare Worker for MCP server\n *\n * Note: This requires bundling docs.json and search-index.json with the worker,\n * or using Cloudflare KV/R2 for storage.\n *\n * For bundling, use wrangler with custom build configuration.\n */\n\nimport { createCloudflareHandler } from 'docusaurus-plugin-mcp-server/adapters';\n\n// Option 1: Import bundled data (requires bundler configuration)\n// import docs from '../build/mcp/docs.json';\n// import searchIndex from '../build/mcp/search-index.json';\n\n// Option 2: Use KV bindings (requires KV namespace configuration)\n// const docs = await env.MCP_KV.get('docs', { type: 'json' });\n// const searchIndex = await env.MCP_KV.get('search-index', { type: 'json' });\n\nexport default {\n fetch: createCloudflareHandler({\n name: '${name}',\n version: '1.0.0',\n baseUrl: '${baseUrl}',\n // docsPath and indexPath are used for file-based loading\n // For Workers, you'll need to configure data loading differently\n docsPath: './mcp/docs.json',\n indexPath: './mcp/search-index.json',\n }),\n};\n`,\n },\n {\n path: 'wrangler.toml',\n description: 'Cloudflare Wrangler configuration',\n content: `name = \"${name}-mcp\"\nmain = \"workers/mcp.js\"\ncompatibility_date = \"2024-01-01\"\n\n# Uncomment to use KV for storing docs\n# [[kv_namespaces]]\n# binding = \"MCP_KV\"\n# id = \"your-kv-namespace-id\"\n\n# Static assets (the Docusaurus build)\n# [site]\n# bucket = \"./build\"\n`,\n },\n ];\n}\n"]}