Skip to main content
Glama

fetch-package-docs

Retrieve package documentation from multiple programming languages by specifying package name and language to access READMEs, API docs, and code examples for analysis.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYesName of the package to fetch documentation for
languageNoProgramming language or repository type (e.g., javascript, python, java, dotnet)

Implementation Reference

  • The handler function for the 'fetch-package-docs' tool. It resolves the package URL using getPackageUrl based on language, fetches the documentation using scraperService, and returns the content or error.
    async ({ packageName, language = "javascript" }) => { console.error( `Fetching documentation for package: ${packageName} (${language})` ); try { const packageUrl = getPackageUrl(packageName, language); console.error(`Using package URL: ${packageUrl}`); const documentationContent = await scraperService.fetchLibraryDocumentation(packageUrl); return { content: [ { type: "text", text: documentationContent, }, ], }; } catch (error) { console.error("Error fetching package content:", error); const errorMessage = `Error fetching package documentation: ${ error instanceof Error ? error.message : String(error) }`; return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; } } );
  • Input schema for the 'fetch-package-docs' tool using Zod validation for packageName (required string) and optional language.
    { packageName: z .string() .describe("Name of the package to fetch documentation for"), language: z .string() .optional() .describe( "Programming language or repository type (e.g., javascript, python, java, dotnet)" ), },
  • src/index.ts:174-225 (registration)
    Registration of the 'fetch-package-docs' tool on the MCP server, specifying name, input schema, and handler function.
    server.tool( "fetch-package-docs", { packageName: z .string() .describe("Name of the package to fetch documentation for"), language: z .string() .optional() .describe( "Programming language or repository type (e.g., javascript, python, java, dotnet)" ), }, async ({ packageName, language = "javascript" }) => { console.error( `Fetching documentation for package: ${packageName} (${language})` ); try { const packageUrl = getPackageUrl(packageName, language); console.error(`Using package URL: ${packageUrl}`); const documentationContent = await scraperService.fetchLibraryDocumentation(packageUrl); return { content: [ { type: "text", text: documentationContent, }, ], }; } catch (error) { console.error("Error fetching package content:", error); const errorMessage = `Error fetching package documentation: ${ error instanceof Error ? error.message : String(error) }`; return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; } } );
  • Helper function getPackageUrl used by the tool handler to map package names and languages to appropriate documentation repository URLs.
    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}`; } }
  • Key helper method fetchLibraryDocumentation in ScraperService, called by the tool to scrape and compile documentation from the resolved package URL.
    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; } }

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