get_package_versions
Retrieve all available versions of an npm package to check compatibility, track release history, and select appropriate versions for your projects.
Instructions
Get all available versions of a package
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | Yes |
Implementation Reference
- src/index.ts:48-58 (schema)Zod schema used to validate and parse the npm package versions response from the registry API.const PackageVersionSchema = z.object({ name: z.string(), versions: z.record( z.string(), z.object({ version: z.string(), publish_time: z.string().optional(), }) ), "dist-tags": z.record(z.string(), z.string()), });
- src/index.ts:361-439 (registration)Full registration of the 'get_package_versions' MCP tool, including inline input/output schemas, and the complete handler implementation that fetches package data from npm registry, validates it, extracts versions and dist-tags, and returns formatted text and structured content."get_package_versions", { title: "Get Package Versions", description: "Get all available versions of a package", inputSchema: { packageName: z.string(), }, outputSchema: { name: z.string(), latest: z.string(), distTags: z.record(z.string(), z.string()), versions: z.array(z.string()), versionCount: z.number(), }, }, async ({ packageName }) => { try { const response = await fetch( `https://registry.npmjs.org/${encodeURIComponent(packageName)}` ); if (!response.ok) { throw new Error( `Failed to fetch package versions: ${response.statusText}` ); } const rawData = await response.json(); const parseResult = PackageVersionSchema.safeParse(rawData); if (!parseResult.success) { throw new Error( `Invalid package versions structure: ${parseResult.error.message}` ); } const data = parseResult.data; const versions = Object.keys(data.versions); const latest = data["dist-tags"].latest; const tags = Object.entries(data["dist-tags"]) .map(([tag, version]) => `${tag}: ${version}`) .join("\n"); const output = { name: data.name, latest, distTags: data["dist-tags"], versions, versionCount: versions.length, }; return { content: [ { type: "text", text: `Package: ${ data.name }\n\nLatest version: ${latest}\n\nDist tags:\n${tags}\n\nAll versions (${ versions.length }):\n${versions.join(", ")}`, }, ], structuredContent: output, }; } catch (error) { return { content: [ { type: "text", text: `Error fetching package versions: ${ error instanceof Error ? error.message : "Unknown error" }`, }, ], isError: true, }; } } );