Skip to main content
Glama

fetch-multilingual-docs

Fetch package documentation across multiple programming languages to extract READMEs, API docs, and code examples for analysis.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYesName of the package to fetch documentation for
languagesYesList of programming languages or repository types to check (e.g., javascript, python, java)

Implementation Reference

  • Full implementation of the 'fetch-multilingual-docs' tool: registers the tool with input schema (packageName and languages array) and the async handler function that attempts to fetch documentation from multiple language repositories using getPackageUrl and scraperService.fetchLibraryDocumentation, compiles results with summary of successes/failures, returns formatted content from the first successful fetch.
    server.tool( "fetch-multilingual-docs", { packageName: z .string() .describe("Name of the package to fetch documentation for"), languages: z .array(z.string()) .describe( "List of programming languages or repository types to check (e.g., javascript, python, java)" ), }, async ({ packageName, languages }) => { console.error( `Fetching documentation for package: ${packageName} across languages: ${languages.join( ", " )}` ); const results: Record<string, any> = {}; let hasSuccessfulFetch = false; for (const language of languages) { try { console.error(`Trying ${language} repository...`); const packageUrl = getPackageUrl(packageName, language); const documentationContent = await scraperService.fetchLibraryDocumentation(packageUrl); results[language] = { url: packageUrl, success: true, content: documentationContent, }; hasSuccessfulFetch = true; } catch (error) { console.error(`Error fetching ${language} documentation:`, error); results[language] = { success: false, error: error instanceof Error ? error.message : String(error), }; } } if (!hasSuccessfulFetch) { return { content: [ { type: "text", text: `Failed to fetch documentation for ${packageName} in any of the requested languages: ${languages.join( ", " )}.`, }, ], isError: true, }; } // Format the successful results const bestLanguage = Object.keys(results).find((lang) => results[lang].success) || languages[0]; const bestContent = results[bestLanguage].content; // Include a summary of all language results const summaryLines = [ `## Documentation Search Results for '${packageName}'`, ]; summaryLines.push(""); for (const language of languages) { const result = results[language]; if (result.success) { summaryLines.push( `✅ **${language}**: Successfully fetched documentation from ${result.url}` ); } else { summaryLines.push(`❌ **${language}**: Failed - ${result.error}`); } } summaryLines.push(""); summaryLines.push(`---`); summaryLines.push(""); summaryLines.push( `# Documentation Content (from ${bestLanguage} repository)` ); summaryLines.push(""); const summary = summaryLines.join("\n"); const completeContent = summary + bestContent; return { content: [ { type: "text", text: completeContent, }, ], }; } );
  • Zod input schema for the 'fetch-multilingual-docs' tool defining packageName (string) and languages (array of strings).
    { packageName: z .string() .describe("Name of the package to fetch documentation for"), languages: z .array(z.string()) .describe( "List of programming languages or repository types to check (e.g., javascript, python, java)" ), },
  • src/index.ts:287-287 (registration)
    Registration of the 'fetch-multilingual-docs' tool on the MCP server.
    server.tool(
  • Helper function getPackageUrl used by the tool to resolve package names to documentation URLs for different languages/registries.
    import fetch from "node-fetch"; /** * Utility to detect if a string is a URL * @param str String to check * @returns true if the string is a valid URL */ export function isUrl(str: string): boolean { try { new URL(str); return true; } catch (e) { return false; }
  • Helper scraperService.fetchLibraryDocumentation used by the tool to scrape documentation content from URLs.
    // Extract code examples and API signatures const codeExamples = extractCodeExamples(html); const apiSignatures = extractAPISignatures(html, libraryName); // Extract main content const mainContent = $("main, article, .readme, .content, .documentation, #readme").html() || ""; // Extract text from body if no main content found const content = mainContent || $("body").html() || ""; // Create the processed page const processedPage: ProcessedPage = { url, title, content, links, codeExamples, apiSignatures, timestamp: new Date().toISOString(), }; // Cache the page cacheService.setPage(url, processedPage); return processedPage; } catch (error) { console.error(`Error processing ${url}:`, error); return null; } } /** * Crawl documentation pages starting from a URL * @param startUrl Starting URL for crawling * @param libraryName Name of the library * @param maxPages Maximum number of pages to crawl * @param skipCache Whether to skip the cache * @returns Array of processed pages */ public async crawlDocumentation( startUrl: string, libraryName: string, maxPages = 5, skipCache = false ): Promise<ProcessedPage[]> { const visitedUrls = new Set<string>(); const processedPages: ProcessedPage[] = []; const urlsToVisit: string[] = [startUrl];

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cdugo/mcp-get-docs'

If you have feedback or need assistance with the MCP directory API, please join our Discord server