Skip to main content
Glama
ashios15

MCP Frontend Tools Server

by ashios15

Bundle Budget Check

bundle_budget_check

Analyzes build output file sizes and flags files that exceed a global or per-entry KB budget for CI integration.

Instructions

Walk a build directory, measure raw + gzip (+ optional brotli) sizes per file, and flag files that exceed a global or per-entry KB budget. CI-friendly JSON output.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
buildDirYesAbsolute path to the build output directory (e.g. dist, .next/static).
budgetKbNoGlobal size budget in KB. Flags any file above this (gzipped). Default: 250.
perEntryBudgetKbNoPer-file budgets in KB keyed by glob-ish substring match. Matching file is checked against the most specific (longest) matching key.
extNoFile extensions to include (default: ['.js','.mjs','.cjs','.css']).
includeBrotliNoAlso compute brotli sizes (slower).

Implementation Reference

  • The `registerBundleBudget` handler function that implements the bundle_budget_check tool logic: walks a build directory, computes raw/gzip/brotli sizes, checks against global and per-entry budgets, and returns a JSON report indicating pass/fail status.
    export function registerBundleBudget(server: McpServer) {
      server.registerTool(
        "bundle_budget_check",
        {
          title: "Bundle Budget Check",
          description:
            "Walk a build directory, measure raw + gzip (+ optional brotli) sizes per file, and flag files that exceed a global or per-entry KB budget. CI-friendly JSON output.",
          inputSchema: InputShape,
        },
        async (args) => {
          try {
            const exts = args.ext && args.ext.length ? args.ext : DEFAULT_EXT;
            const budgetKb = args.budgetKb ?? 250;
            const stat = await fs.stat(args.buildDir).catch(() => null);
            if (!stat || !stat.isDirectory()) {
              return errorResult(`buildDir not a directory: ${args.buildDir}`);
            }
            const files = await walk(args.buildDir, exts);
            const report = [];
            let overCount = 0;
            let totalRaw = 0;
            let totalGzip = 0;
            for (const f of files) {
              const buf = await fs.readFile(f);
              const gz = await gzip(buf);
              const br = args.includeBrotli ? await brotli(buf) : undefined;
              const rel = path.relative(args.buildDir, f);
              const match = matchBudget(rel, args.perEntryBudgetKb);
              const effectiveBudget = match?.budgetKb ?? budgetKb;
              const gzKb = gz.length / 1024;
              const over = gzKb > effectiveBudget;
              if (over) overCount++;
              totalRaw += buf.length;
              totalGzip += gz.length;
              report.push({
                file: rel,
                rawBytes: buf.length,
                rawKb: +(buf.length / 1024).toFixed(2),
                gzipBytes: gz.length,
                gzipKb: +gzKb.toFixed(2),
                ...(br ? { brotliBytes: br.length, brotliKb: +(br.length / 1024).toFixed(2) } : {}),
                budgetKb: effectiveBudget,
                budgetKey: match?.key ?? "(global)",
                over,
                overBy: over ? +(gzKb - effectiveBudget).toFixed(2) : 0,
              });
            }
            report.sort((a, b) => b.gzipBytes - a.gzipBytes);
            return jsonResult({
              buildDir: args.buildDir,
              fileCount: files.length,
              overBudgetCount: overCount,
              totals: {
                rawKb: +(totalRaw / 1024).toFixed(2),
                gzipKb: +(totalGzip / 1024).toFixed(2),
              },
              files: report,
              status: overCount === 0 ? "pass" : "fail",
            });
          } catch (err) {
            return errorResult(err instanceof Error ? err.message : String(err));
          }
        }
      );
    }
  • Input schema for the bundle_budget_check tool using Zod, defining buildDir (required), budgetKb, perEntryBudgetKb, ext, and includeBrotli parameters.
    const InputShape = {
      buildDir: z.string().describe("Absolute path to the build output directory (e.g. dist, .next/static)."),
      budgetKb: z
        .number()
        .positive()
        .optional()
        .describe("Global size budget in KB. Flags any file above this (gzipped). Default: 250."),
      perEntryBudgetKb: z
        .record(z.number().positive())
        .optional()
        .describe(
          "Per-file budgets in KB keyed by glob-ish substring match. Matching file is checked against the most specific (longest) matching key."
        ),
      ext: z
        .array(z.string())
        .optional()
        .describe("File extensions to include (default: ['.js','.mjs','.cjs','.css'])."),
      includeBrotli: z.boolean().optional().describe("Also compute brotli sizes (slower)."),
    };
  • src/index.ts:26-26 (registration)
    Registration call: `registerBundleBudget(server)` which is the entry point that wires the bundle_budget_check tool into the MCP server.
    registerBundleBudget(server);
  • Helper function `walk()` that recursively walks a directory and collects files matching given extensions.
    async function walk(dir: string, exts: string[]): Promise<string[]> {
      const out: string[] = [];
      async function visit(d: string) {
        const entries = await fs.readdir(d, { withFileTypes: true });
        for (const e of entries) {
          const full = path.join(d, e.name);
          if (e.isDirectory()) await visit(full);
          else if (exts.includes(path.extname(e.name))) out.push(full);
        }
      }
      await visit(dir);
      return out;
    }
  • Helper function `matchBudget()` that finds the most specific per-entry budget key matching a file path via substring matching.
    function matchBudget(
      relPath: string,
      perEntry: Record<string, number> | undefined
    ): { key: string; budgetKb: number } | null {
      if (!perEntry) return null;
      let best: { key: string; budgetKb: number } | null = null;
      for (const [key, budget] of Object.entries(perEntry)) {
        if (relPath.includes(key)) {
          if (!best || key.length > best.key.length) best = { key, budgetKb: budget };
        }
      }
      return best;
    }
Behavior4/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. It explicitly states it walks a directory, measures sizes, and flags exceedances. It also mentions CI-friendly JSON output. While it doesn't disclose potential actions (e.g., read-only or any side effects), the described behavior aligns with a read-only check, making it fairly transparent.

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?

Two sentences, each purposeful. Front-loaded with the core action ('Walk a build directory...'). No wasted words. The structure is optimal for quick agent comprehension.

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?

No output schema is present, so the description should clarify the output format. It mentions 'CI-friendly JSON output' but does not specify structure, exit codes, or how budgets are compared. With 5 parameters and a nested object, more detail would help the agent use it effectively. Score 3 reflects adequate but not complete guidance.

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?

Schema coverage is 100%, so baseline is 3. The description adds minimal value beyond the schema: it mentions 'global or per-entry KB budget' but does not explain the glob matching or default values. The schema already describes each parameter adequately. Thus, the description does not significantly enhance parameter understanding.

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

Purpose5/5

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

The description uses a specific verb ('Walk') and resource ('build directory') and clearly states the action: measure raw/gzip/brotli sizes and flag budget violations. This distinguishes it from sibling tools like 'axe_audit' (accessibility) and 'scaffold_react_component', which serve entirely different purposes.

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

Usage Guidelines4/5

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

The description clearly implies the tool is for bundle size checks, providing context for use. It does not explicitly state when not to use it or compare with alternatives, but siblings are in unrelated domains, so the context is sufficient. A score of 4 reflects clear context without formal exclusions.

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/ashios15/mcp-frontend-tools'

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