fetch-library-docs
Fetch comprehensive package documentation from multiple programming language ecosystems for LLMs like Claude without requiring API keys.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| library | Yes | Name of the package or URL of the library documentation to fetch | |
| language | No | Programming language or repository type if providing a package name (e.g., javascript, python, java, dotnet) |
Implementation Reference
- src/index.ts:228-284 (registration)Registration of the 'fetch-library-docs' MCP tool, including input schema, description, and the complete inline handler function that resolves package URLs and fetches documentation.server.tool( "fetch-library-docs", { library: z .string() .describe( "Name of the package or URL of the library documentation to fetch" ), language: z .string() .optional() .describe( "Programming language or repository type if providing a package name (e.g., javascript, python, java, dotnet)" ), }, async ({ library, language = "javascript" }) => { console.error( `Fetching documentation for library: ${library} ${ language ? `(${language})` : "" }` ); try { // Determine if input is a URL or package name const isLibraryUrl = isUrl(library); let url = isLibraryUrl ? library : getPackageUrl(library, language); const documentationContent = await scraperService.fetchLibraryDocumentation(url); return { content: [ { type: "text", text: documentationContent, }, ], }; } catch (error) { console.error("Error fetching library documentation:", error); const errorMessage = `Error fetching library documentation: ${ error instanceof Error ? error.message : String(error) }`; return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; } } );
- src/services/ScraperService.ts:137-195 (handler)Key helper method invoked by the tool handler to perform the actual documentation fetching, crawling multiple pages, processing content with Cheerio, extracting code/API, compiling into Markdown, and adding LLM prompt instructions.public async fetchLibraryDocumentation( url: string, maxPages = 5 ): Promise<string> { try { // If input is not a URL, assume it's a package name if (!url.startsWith("http")) { url = `https://www.npmjs.com/package/${url}`; } // Extract library name from URL const libraryName = extractLibraryName(url); // Crawl documentation const pages = await this.crawlDocumentation(url, libraryName, maxPages); if (pages.length === 0) { throw new Error(`Failed to fetch documentation from ${url}`); } // Compile documentation into a single markdown document const documentation = this.compileDocumentation(pages, libraryName); // Include instructions for using the prompt const promptInstructions = ` --- š For better summarization, use the "summarize-library-docs" prompt with: - libraryName: "${libraryName}" - documentation: <the content above> Example: @summarize-library-docs with libraryName="${libraryName}" `; return documentation + promptInstructions; } catch (error) { console.error(`Error fetching URL content:`, error); // Extract library name from URL const libraryName = extractLibraryName(url); const errorMessage = `Error fetching URL content: ${ error instanceof Error ? error.message : String(error) }`; // Include error-specific prompt instructions const promptInstructions = ` --- š For information about this library despite the fetch error, use the "summarize-library-docs" prompt with: - libraryName: "${libraryName}" - errorStatus: "${error instanceof Error ? error.message : String(error)}" Example: @summarize-library-docs with libraryName="${libraryName}" and errorStatus="fetch failed" `; return errorMessage + promptInstructions; } }
- Utility function used in the tool handler to map package names to their respective repository documentation URLs based on programming language (npm, pypi, maven, nuget, etc.).export function getPackageUrl( packageName: string, language = "javascript" ): string { const lang = language.toLowerCase().trim(); switch (lang) { // JavaScript/TypeScript case "javascript": case "js": case "typescript": case "ts": case "node": case "nodejs": case "npm": return `https://www.npmjs.com/package/${packageName}`; // Python case "python": case "py": case "pypi": return `https://pypi.org/project/${packageName}`; // Java case "java": case "maven": return `https://mvnrepository.com/artifact/${packageName}`; // .NET case "dotnet": case ".net": case "csharp": case "c#": case "nuget": return `https://www.nuget.org/packages/${packageName}`; // Ruby case "ruby": case "gem": case "rubygem": case "rubygems": return `https://rubygems.org/gems/${packageName}`; // PHP case "php": case "composer": case "packagist": return `https://packagist.org/packages/${packageName}`; // Rust case "rust": case "cargo": case "crate": case "crates": return `https://crates.io/crates/${packageName}`; // Go case "go": case "golang": return `https://pkg.go.dev/${packageName}`; // Swift case "swift": case "cocoapods": return `https://cocoapods.org/pods/${packageName}`; // Default to npm default: return `https://www.npmjs.com/package/${packageName}`; } }
- src/utils/packageRepository.ts:8-14 (helper)Utility function used in the tool handler to check if the library input is a direct URL or a package name requiring URL resolution.export function isUrl(str: string): boolean { try { new URL(str); return true; } catch (e) { return false; }
- src/index.ts:230-242 (schema)Zod input schema defining the 'library' parameter (package name or URL) and optional 'language' for repository selection.{ library: z .string() .describe( "Name of the package or URL of the library documentation to fetch" ), language: z .string() .optional() .describe( "Programming language or repository type if providing a package name (e.g., javascript, python, java, dotnet)" ), },