Skip to main content
Glama

Compare Packages

compare_packages

Compare two npm packages side-by-side to analyze differences in features, dependencies, and statistics for informed package selection decisions.

Instructions

Compare two packages side-by-side

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageName1Yes
packageName2Yes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
packagesYes

Implementation Reference

  • The handler function for the 'compare_packages' tool. It fetches full package information and last-month download stats for two packages from the npm registry, extracts latest versions, constructs a comparison output with details like version, description, downloads, maintainers, and keywords, formats a textual comparison, and returns both structured data and formatted text, handling errors appropriately.
    async ({ packageName1, packageName2 }) => {
      try {
        const [pkg1Full, pkg2Full, pkg1Stats, pkg2Stats] = await Promise.all([
          fetchFullPackageInfo(packageName1),
          fetchFullPackageInfo(packageName2),
          fetch(
            `https://api.npmjs.org/downloads/point/last-month/${encodeURIComponent(
              packageName1
            )}`
          ).then((r) => r.json()),
          fetch(
            `https://api.npmjs.org/downloads/point/last-month/${encodeURIComponent(
              packageName2
            )}`
          ).then((r) => r.json()),
        ]);
    
        const pkg1Latest = pkg1Full.versions[pkg1Full["dist-tags"].latest];
        const pkg2Latest = pkg2Full.versions[pkg2Full["dist-tags"].latest];
    
        const output = {
          packages: [
            {
              name: pkg1Latest.name,
              version: pkg1Latest.version,
              description: pkg1Latest.description,
              downloads: pkg1Stats.downloads || 0,
              maintainers: pkg1Latest.maintainers?.map((m: any) => m.name) || [],
              keywords: pkg1Latest.keywords,
            },
            {
              name: pkg2Latest.name,
              version: pkg2Latest.version,
              description: pkg2Latest.description,
              downloads: pkg2Stats.downloads || 0,
              maintainers: pkg2Latest.maintainers?.map((m: any) => m.name) || [],
              keywords: pkg2Latest.keywords,
            },
          ],
        };
    
        const formattedText = `Package Comparison:\n\n${pkg1Latest.name} vs ${
          pkg2Latest.name
        }\n\n${pkg1Latest.name}:\n  Version: ${
          pkg1Latest.version
        }\n  Description: ${
          pkg1Latest.description || "N/A"
        }\n  Downloads (last month): ${(
          pkg1Stats.downloads || 0
        ).toLocaleString()}\n  Maintainers: ${
          output.packages[0].maintainers.join(", ") || "N/A"
        }\n  Keywords: ${pkg1Latest.keywords?.join(", ") || "None"}\n\n${
          pkg2Latest.name
        }:\n  Version: ${pkg2Latest.version}\n  Description: ${
          pkg2Latest.description || "N/A"
        }\n  Downloads (last month): ${(
          pkg2Stats.downloads || 0
        ).toLocaleString()}\n  Maintainers: ${
          output.packages[1].maintainers.join(", ") || "N/A"
        }\n  Keywords: ${pkg2Latest.keywords?.join(", ") || "None"}`;
    
        return {
          content: [
            {
              type: "text",
              text: formattedText,
            },
          ],
          structuredContent: output,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error comparing packages: ${
                error instanceof Error ? error.message : "Unknown error"
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • Input and output schemas defining the parameters (packageName1, packageName2 as strings) and the structured output (array of package objects with name, version, description, downloads, maintainers, keywords).
    {
      title: "Compare Packages",
      description: "Compare two packages side-by-side",
      inputSchema: {
        packageName1: z.string(),
        packageName2: z.string(),
      },
      outputSchema: {
        packages: z.array(
          z.object({
            name: z.string(),
            version: z.string(),
            description: z.string().optional(),
            downloads: z.number(),
            maintainers: z.array(z.string()),
            keywords: z.array(z.string()).optional(),
          })
        ),
      },
    },
  • src/index.ts:727-833 (registration)
    Registration of the 'compare_packages' tool using server.registerTool, including the tool name, schema, and handler function.
    server.registerTool(
      "compare_packages",
      {
        title: "Compare Packages",
        description: "Compare two packages side-by-side",
        inputSchema: {
          packageName1: z.string(),
          packageName2: z.string(),
        },
        outputSchema: {
          packages: z.array(
            z.object({
              name: z.string(),
              version: z.string(),
              description: z.string().optional(),
              downloads: z.number(),
              maintainers: z.array(z.string()),
              keywords: z.array(z.string()).optional(),
            })
          ),
        },
      },
      async ({ packageName1, packageName2 }) => {
        try {
          const [pkg1Full, pkg2Full, pkg1Stats, pkg2Stats] = await Promise.all([
            fetchFullPackageInfo(packageName1),
            fetchFullPackageInfo(packageName2),
            fetch(
              `https://api.npmjs.org/downloads/point/last-month/${encodeURIComponent(
                packageName1
              )}`
            ).then((r) => r.json()),
            fetch(
              `https://api.npmjs.org/downloads/point/last-month/${encodeURIComponent(
                packageName2
              )}`
            ).then((r) => r.json()),
          ]);
    
          const pkg1Latest = pkg1Full.versions[pkg1Full["dist-tags"].latest];
          const pkg2Latest = pkg2Full.versions[pkg2Full["dist-tags"].latest];
    
          const output = {
            packages: [
              {
                name: pkg1Latest.name,
                version: pkg1Latest.version,
                description: pkg1Latest.description,
                downloads: pkg1Stats.downloads || 0,
                maintainers: pkg1Latest.maintainers?.map((m: any) => m.name) || [],
                keywords: pkg1Latest.keywords,
              },
              {
                name: pkg2Latest.name,
                version: pkg2Latest.version,
                description: pkg2Latest.description,
                downloads: pkg2Stats.downloads || 0,
                maintainers: pkg2Latest.maintainers?.map((m: any) => m.name) || [],
                keywords: pkg2Latest.keywords,
              },
            ],
          };
    
          const formattedText = `Package Comparison:\n\n${pkg1Latest.name} vs ${
            pkg2Latest.name
          }\n\n${pkg1Latest.name}:\n  Version: ${
            pkg1Latest.version
          }\n  Description: ${
            pkg1Latest.description || "N/A"
          }\n  Downloads (last month): ${(
            pkg1Stats.downloads || 0
          ).toLocaleString()}\n  Maintainers: ${
            output.packages[0].maintainers.join(", ") || "N/A"
          }\n  Keywords: ${pkg1Latest.keywords?.join(", ") || "None"}\n\n${
            pkg2Latest.name
          }:\n  Version: ${pkg2Latest.version}\n  Description: ${
            pkg2Latest.description || "N/A"
          }\n  Downloads (last month): ${(
            pkg2Stats.downloads || 0
          ).toLocaleString()}\n  Maintainers: ${
            output.packages[1].maintainers.join(", ") || "N/A"
          }\n  Keywords: ${pkg2Latest.keywords?.join(", ") || "None"}`;
    
          return {
            content: [
              {
                type: "text",
                text: formattedText,
              },
            ],
            structuredContent: output,
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error comparing packages: ${
                  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 the action (compare) but doesn't describe what the comparison entails (e.g., returns a structured output, side-by-side view), any limitations (e.g., only works for certain package types), or potential side effects. For a tool with no annotation coverage, this is a significant gap in transparency.

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 extremely concise with a single sentence, 'Compare two packages side-by-side', which is front-loaded and wastes no words. It efficiently conveys the core action without unnecessary elaboration, making it easy to parse quickly.

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

Completeness3/5

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

Given the tool has an output schema (which should document return values), the description doesn't need to explain outputs. However, with 2 parameters at 0% schema coverage and no annotations, the description is too minimal—it doesn't clarify comparison aspects or usage context. For a simple comparison tool, it's borderline adequate but lacks depth for reliable agent use.

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

Parameters2/5

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

Schema description coverage is 0%, so the schema provides no details on parameters. The description mentions 'two packages' but doesn't specify what 'packageName1' and 'packageName2' represent (e.g., package IDs, names, versions) or any constraints (e.g., must be valid packages). This fails to compensate for the lack of schema documentation, leaving parameters largely unexplained.

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

Purpose3/5

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

The description 'Compare two packages side-by-side' clearly states the verb (compare) and resource (packages), making the purpose understandable. However, it's vague about what aspects are compared (e.g., versions, dependencies, quality) and doesn't distinguish from sibling tools like 'get_package_dependencies' or 'get_package_quality', which might offer overlapping functionality. This leaves room for ambiguity in tool selection.

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_dependencies' and 'get_package_quality', it's unclear if this tool aggregates such data or serves a different purpose. There's no mention of prerequisites, exclusions, or specific contexts for use, leaving the agent to guess based on tool names alone.

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