Skip to main content
Glama

Get Package Size

get_package_size

Retrieve bundle size information for npm packages to analyze performance impact before installation.

Instructions

Get bundle size information from bundlephobia

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYes
versionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
gzipYes
nameYes
sizeYes
versionYes
dependencyCountYes

Implementation Reference

  • The core handler function for the 'get_package_size' MCP tool. It fetches the package metadata from the npm registry to determine the version, then queries the BundlePhobia API for bundle size metrics (minified and gzipped sizes, dependency count), validates the response using PackageSizeSchema, formats a text summary, and returns structured content.
    async ({ packageName, version }) => {
      try {
        const pkgInfo = await fetchPackageData(packageName, version);
        const versionToCheck = pkgInfo.version || "latest";
    
        const response = await fetch(
          `https://bundlephobia.com/api/size?package=${encodeURIComponent(
            packageName
          )}@${versionToCheck}`
        );
    
        if (!response.ok) {
          throw new Error(`Failed to fetch package size: ${response.statusText}`);
        }
    
        const rawData = await response.json();
        const parseResult = PackageSizeSchema.safeParse(rawData);
    
        if (!parseResult.success) {
          throw new Error(
            `Invalid package size structure: ${parseResult.error.message}`
          );
        }
    
        const data = parseResult.data;
        const output = {
          name: data.name,
          version: data.version,
          size: data.size,
          gzip: data.gzip,
          dependencyCount: data.dependencyCount,
        };
    
        const formattedText = `Package: ${data.name}@${
          data.version
        }\n\nBundle Size:\n  Minified: ${(data.size / 1024).toFixed(
          2
        )} KB\n  Gzipped: ${(data.gzip / 1024).toFixed(2)} KB\n\nDependencies: ${
          data.dependencyCount
        }`;
    
        return {
          content: [
            {
              type: "text",
              text: formattedText,
            },
          ],
          structuredContent: output,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching package size: ${
                error instanceof Error ? error.message : "Unknown error"
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema for validating the JSON response from the BundlePhobia API, used in the get_package_size tool handler for output parsing.
    const PackageSizeSchema = z.object({
      name: z.string(),
      version: z.string(),
      size: z.number(),
      gzip: z.number(),
      dependencyCount: z.number(),
      scoped: z.boolean().optional(),
      repository: z.string().optional(),
    });
  • src/index.ts:836-852 (registration)
    Registration of the 'get_package_size' tool on the MCP server, defining its title, description, input schema (packageName required, version optional), and output schema.
    server.registerTool(
      "get_package_size",
      {
        title: "Get Package Size",
        description: "Get bundle size information from bundlephobia",
        inputSchema: {
          packageName: z.string(),
          version: z.string().optional(),
        },
        outputSchema: {
          name: z.string(),
          version: z.string(),
          size: z.number(),
          gzip: z.number(),
          dependencyCount: z.number(),
        },
      },
  • Helper utility function to retrieve package metadata from the npm registry, called by the get_package_size handler to resolve the package version.
    async function fetchPackageData(
      packageName: string,
      version?: string
    ): Promise<any> {
      const versionPath = version || "latest";
      const encodedPackageName = encodeURIComponent(packageName);
      const response = await fetch(
        `https://registry.npmjs.org/${encodedPackageName}/${versionPath}`
      );
    
      if (!response.ok) {
        throw new Error(
          `Failed to fetch package ${packageName}: ${response.statusText}`
        );
      }
    
      return await response.json();
    }
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 information, implying a read-only operation, but doesn't cover aspects like rate limits, error handling, authentication needs, or what the output contains (though an output schema exists). This is a significant gap for a tool with zero 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 directly states the tool's function and source. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly without unnecessary detail.

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's moderate complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate. It specifies the action and source, but lacks usage guidelines, parameter details, and behavioral context. The output schema mitigates some gaps, but overall completeness is limited, aligning with a baseline score.

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%, meaning parameters are undocumented in the schema. The description adds no meaning beyond the schema—it doesn't explain what 'packageName' or 'version' represent, their formats, or examples. For a tool with 2 parameters and low coverage, this fails to compensate, leaving semantics unclear.

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 as 'Get bundle size information from bundlephobia', specifying the action (get), resource (bundle size information), and source (bundlephobia). It distinguishes from siblings like get_package_info or get_package_dependencies by focusing specifically on size metrics, though it doesn't explicitly contrast them.

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 (which might include size) or compare_packages (for relative sizing), there's no indication of context, prerequisites, or exclusions, leaving the agent to infer usage.

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