Skip to main content
Glama

Get Package Info

get_package_info

Retrieve comprehensive metadata for npm packages including versions, dependencies, and statistics to analyze package details and make informed decisions.

Instructions

Get comprehensive package metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYes
versionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
licenseNo
versionNo
distTagsNo
homepageNo
keywordsNo
repositoryNo
descriptionNo
maintainersNo
totalVersionsNo

Implementation Reference

  • src/index.ts:598-724 (registration)
    Registration of the 'get_package_info' tool using server.registerTool, including title, description, inputSchema, outputSchema, and the handler function.
    server.registerTool(
      "get_package_info",
      {
        title: "Get Package Info",
        description: "Get comprehensive package metadata",
        inputSchema: {
          packageName: z.string(),
          version: z.string().optional(),
        },
        outputSchema: {
          name: z.string(),
          version: z.string().optional(),
          description: z.string().optional(),
          license: z.string().optional(),
          keywords: z.array(z.string()).optional(),
          maintainers: z.array(z.string()).optional(),
          repository: z.string().optional(),
          homepage: z.string().optional(),
          totalVersions: z.number().optional(),
          distTags: z.array(z.string()).optional(),
        },
      },
      async ({ packageName, version }) => {
        try {
          const encodedPackageName = encodeURIComponent(packageName);
          const response = await fetch(
            `https://registry.npmjs.org/${encodedPackageName}${
              version ? `/${version}` : ""
            }`
          );
    
          if (!response.ok) {
            throw new Error(`Failed to fetch package info: ${response.statusText}`);
          }
    
          const rawData = await response.json();
    
          let formattedInfo = "";
          let output: any;
    
          if (version) {
            // Single version info
            const versionData = rawData.versions?.[version];
            if (versionData) {
              output = {
                name: versionData.name,
                version: versionData.version,
                description: versionData.description,
                license: versionData.license,
                keywords: versionData.keywords,
                repository: versionData.repository?.url,
                homepage: versionData.homepage,
              };
    
              formattedInfo = `Package: ${versionData.name}\nVersion: ${
                versionData.version
              }\nDescription: ${versionData.description || "N/A"}\nLicense: ${
                versionData.license || "N/A"
              }\nHomepage: ${versionData.homepage || "N/A"}\n\nKeywords: ${
                versionData.keywords?.join(", ") || "None"
              }\n\nAuthor: ${JSON.stringify(
                versionData.author || "N/A"
              )}\n\nRepository: ${versionData.repository?.url || "N/A"}`;
            }
          } else {
            // Full package info
            const parseResult = PackageInfoSchema.safeParse(rawData);
    
            if (!parseResult.success) {
              throw new Error(
                `Invalid package info structure: ${parseResult.error.message}`
              );
            }
    
            const data = parseResult.data;
            const latestVersion = data["dist-tags"].latest;
            const latestData = data.versions[latestVersion];
    
            output = {
              name: data.name,
              description: data.description,
              license: data.license,
              keywords: latestData.keywords,
              maintainers: latestData.maintainers?.map((m: any) => m.name) || [],
              repository: latestData.repository?.url,
              homepage: latestData.homepage,
              totalVersions: Object.keys(data.versions).length,
              distTags: Object.keys(data["dist-tags"]),
            };
    
            formattedInfo = `Package: ${
              data.name
            }\nLatest Version: ${latestVersion}\nDescription: ${
              data.description || "N/A"
            }\nLicense: ${data.license || "N/A"}\n\nKeywords: ${
              latestData.keywords?.join(", ") || "None"
            }\n\nMaintainers: ${
              latestData.maintainers?.map((m: any) => m.name).join(", ") || "N/A"
            }\n\nTotal Versions: ${
              Object.keys(data.versions).length
            }\nDist Tags: ${Object.keys(data["dist-tags"]).join(", ")}`;
          }
    
          return {
            content: [
              {
                type: "text",
                text: formattedInfo,
              },
            ],
            structuredContent: output,
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching package info: ${
                  error instanceof Error ? error.message : "Unknown error"
                }`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Core handler logic for executing the tool: fetches package data from npm registry, processes for specific version or latest, validates with PackageInfoSchema, constructs formatted text and structured output.
    async ({ packageName, version }) => {
      try {
        const encodedPackageName = encodeURIComponent(packageName);
        const response = await fetch(
          `https://registry.npmjs.org/${encodedPackageName}${
            version ? `/${version}` : ""
          }`
        );
    
        if (!response.ok) {
          throw new Error(`Failed to fetch package info: ${response.statusText}`);
        }
    
        const rawData = await response.json();
    
        let formattedInfo = "";
        let output: any;
    
        if (version) {
          // Single version info
          const versionData = rawData.versions?.[version];
          if (versionData) {
            output = {
              name: versionData.name,
              version: versionData.version,
              description: versionData.description,
              license: versionData.license,
              keywords: versionData.keywords,
              repository: versionData.repository?.url,
              homepage: versionData.homepage,
            };
    
            formattedInfo = `Package: ${versionData.name}\nVersion: ${
              versionData.version
            }\nDescription: ${versionData.description || "N/A"}\nLicense: ${
              versionData.license || "N/A"
            }\nHomepage: ${versionData.homepage || "N/A"}\n\nKeywords: ${
              versionData.keywords?.join(", ") || "None"
            }\n\nAuthor: ${JSON.stringify(
              versionData.author || "N/A"
            )}\n\nRepository: ${versionData.repository?.url || "N/A"}`;
          }
        } else {
          // Full package info
          const parseResult = PackageInfoSchema.safeParse(rawData);
    
          if (!parseResult.success) {
            throw new Error(
              `Invalid package info structure: ${parseResult.error.message}`
            );
          }
    
          const data = parseResult.data;
          const latestVersion = data["dist-tags"].latest;
          const latestData = data.versions[latestVersion];
    
          output = {
            name: data.name,
            description: data.description,
            license: data.license,
            keywords: latestData.keywords,
            maintainers: latestData.maintainers?.map((m: any) => m.name) || [],
            repository: latestData.repository?.url,
            homepage: latestData.homepage,
            totalVersions: Object.keys(data.versions).length,
            distTags: Object.keys(data["dist-tags"]),
          };
    
          formattedInfo = `Package: ${
            data.name
          }\nLatest Version: ${latestVersion}\nDescription: ${
            data.description || "N/A"
          }\nLicense: ${data.license || "N/A"}\n\nKeywords: ${
            latestData.keywords?.join(", ") || "None"
          }\n\nMaintainers: ${
            latestData.maintainers?.map((m: any) => m.name).join(", ") || "N/A"
          }\n\nTotal Versions: ${
            Object.keys(data.versions).length
          }\nDist Tags: ${Object.keys(data["dist-tags"]).join(", ")}`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: formattedInfo,
            },
          ],
          structuredContent: output,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching package info: ${
                error instanceof Error ? error.message : "Unknown error"
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema used for validating the full package information response from the npm registry in the get_package_info handler.
    const PackageInfoSchema = z.object({
      name: z.string(),
      description: z.string().optional(),
      "dist-tags": z.record(z.string(), z.string()),
      versions: z.record(
        z.string(),
        z.object({
          name: z.string(),
          version: z.string(),
          description: z.string().optional(),
          keywords: z.array(z.string()).optional(),
          license: z.string().optional(),
          author: z.any().optional(),
          maintainers: z.array(z.any()).optional(),
          repository: z
            .object({
              type: z.string(),
              url: z.string(),
            })
            .optional(),
          dependencies: z.record(z.string(), z.string()).optional(),
          homepage: z.string().optional(),
        })
      ),
      time: z.record(z.string(), z.string()),
      license: z.string().optional(),
      readme: z.string().optional(),
    });
  • Input and output schemas defined for the 'get_package_info' tool registration.
    {
      title: "Get Package Info",
      description: "Get comprehensive package metadata",
      inputSchema: {
        packageName: z.string(),
        version: z.string().optional(),
      },
      outputSchema: {
        name: z.string(),
        version: z.string().optional(),
        description: z.string().optional(),
        license: z.string().optional(),
        keywords: z.array(z.string()).optional(),
        maintainers: z.array(z.string()).optional(),
        repository: z.string().optional(),
        homepage: z.string().optional(),
        totalVersions: z.number().optional(),
        distTags: z.array(z.string()).optional(),
      },
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 tool retrieves metadata but doesn't describe what 'comprehensive' entails, potential rate limits, authentication needs, error conditions, or the format of returned data. This leaves significant gaps for an AI agent to understand how to use it effectively.

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, front-loaded sentence that directly states the tool's purpose. There's no wasted verbiage, and it efficiently communicates the core function without unnecessary details, 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, the description doesn't need to explain return values, which helps. However, with no annotations, 2 undocumented parameters, and multiple sibling tools, the description is too minimal. It should clarify the scope of 'comprehensive' metadata and when to use this versus other package tools to be fully complete.

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?

The input schema has 2 parameters with 0% description coverage, and the tool description doesn't mention parameters at all. It doesn't explain what 'packageName' and 'version' represent, their expected formats, or whether 'version' is optional for latest versions. This fails to compensate for the lack of schema descriptions, making parameter usage ambiguous.

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 tool's purpose with a specific verb ('Get') and resource ('comprehensive package metadata'), making it easy to understand what it does. However, it doesn't distinguish this tool from its siblings like 'get_package_versions' or 'get_package_dependencies', which also retrieve package metadata but for specific aspects.

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_versions' or 'get_package_quality', it's unclear if this tool should be used for general metadata or as a fallback when more specific tools aren't available. No explicit when/when-not statements or prerequisites are mentioned.

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