Skip to main content
Glama

Get Package Versions

get_package_versions

Retrieve all available versions of an npm package to check compatibility, track updates, or analyze release history.

Instructions

Get all available versions of a package

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
latestYes
distTagsYes
versionsYes
versionCountYes

Implementation Reference

  • The handler function for the 'get_package_versions' tool. It fetches package data from the npm registry, validates it using PackageVersionSchema, extracts versions and dist-tags, formats the output as text and structured content.
    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,
        };
      }
    }
  • Zod schema for validating the npm registry response containing package versions, versions object, and dist-tags.
    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:360-439 (registration)
    MCP server registration of the 'get_package_versions' tool, defining title, description, input/output schemas, and attaching the handler function.
    server.registerTool(
      "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,
          };
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states a read operation ('Get'), implying it is likely safe, but does not mention any behavioral traits such as rate limits, authentication needs, or what the output contains (e.g., list format, pagination). This leaves significant gaps for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It is front-loaded and appropriately sized for the tool's simplicity, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter) and the presence of an output schema, the description is complete enough for basic understanding. However, without annotations and with 0% schema coverage, it could benefit from more context on behavior or usage, but the output schema mitigates some gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It mentions 'packageName' implicitly by referring to 'a package', but does not add meaning beyond the schema, such as format examples or constraints. With 1 parameter and low coverage, the baseline is 3 as it minimally addresses the parameter but lacks detailed semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'all available versions of a package', making the purpose understandable. However, it does not explicitly differentiate from sibling tools like 'get_package_info' or 'get_package_dependencies', which might also provide version-related information, so it lacks sibling differentiation for a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'get_package_info' that might include version data, there is no explicit or implied context for choosing this tool, leaving the agent without usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/JuanSebastianGB/npm-context-agent-mcp'

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