Skip to main content
Glama
ashios15

MCP Frontend Tools Server

by ashios15

Design Token Diff

design_token_diff

Compare two design token JSON files to identify added, removed, and changed tokens with type-aware classification for design system pull request reviews.

Instructions

Diff two design-token JSON files (W3C DTCG / Style Dictionary style). Reports added, removed, and changed tokens with $type-aware classification. Useful for PR review of design-system changes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
beforePathYesPath to the baseline tokens JSON (Style Dictionary / W3C DTCG format).
afterPathYesPath to the new tokens JSON.
ignoreKeysNoDot-path keys to ignore (e.g. ['$description','$extensions']).

Implementation Reference

  • The registerDesignTokenDiff function that registers and implements the 'design_token_diff' tool. Reads two design-token JSON files, flattens them, diffs by path, and returns added/removed/changed tokens with $type-aware classification.
    export function registerDesignTokenDiff(server: McpServer) {
      server.registerTool(
        "design_token_diff",
        {
          title: "Design Token Diff",
          description:
            "Diff two design-token JSON files (W3C DTCG / Style Dictionary style). Reports added, removed, and changed tokens with $type-aware classification. Useful for PR review of design-system changes.",
          inputSchema: InputShape,
        },
        async (args) => {
          try {
            const [beforeRaw, afterRaw] = await Promise.all([
              fs.readFile(args.beforePath, "utf8"),
              fs.readFile(args.afterPath, "utf8"),
            ]);
            const before = JSON.parse(beforeRaw);
            const after = JSON.parse(afterRaw);
            const beforeMap = new Map<string, Record<string, Json>>();
            const afterMap = new Map<string, Record<string, Json>>();
            flatten(before, "", beforeMap);
            flatten(after, "", afterMap);
            const ignore = new Set(args.ignoreKeys ?? []);
            const changes: Change[] = [];
            const allPaths = new Set<string>([...beforeMap.keys(), ...afterMap.keys()]);
            for (const p of allPaths) {
              if (ignore.has(p)) continue;
              const b = beforeMap.get(p);
              const a = afterMap.get(p);
              if (!b && a) {
                changes.push({ path: p, kind: "added", after: a.$value, type: a.$type as string | undefined });
              } else if (b && !a) {
                changes.push({ path: p, kind: "removed", before: b.$value, type: b.$type as string | undefined });
              } else if (b && a) {
                const bv = JSON.stringify(b.$value);
                const av = JSON.stringify(a.$value);
                if (bv !== av) {
                  const type = (a.$type ?? b.$type) as string | undefined;
                  changes.push({
                    path: p,
                    kind: "changed",
                    before: b.$value,
                    after: a.$value,
                    type,
                    note: classifyNote(type, b.$value, a.$value),
                  });
                }
              }
            }
            const byKind = { added: 0, removed: 0, changed: 0 };
            for (const c of changes) byKind[c.kind]++;
            changes.sort((x, y) => x.path.localeCompare(y.path));
            return jsonResult({
              beforePath: args.beforePath,
              afterPath: args.afterPath,
              tokenCount: { before: beforeMap.size, after: afterMap.size },
              summary: byKind,
              changes,
            });
          } catch (err) {
            return errorResult(err instanceof Error ? err.message : String(err));
          }
        }
      );
    }
  • Input schema definition for the tool using Zod: beforePath (string), afterPath (string), and optional ignoreKeys (array of strings).
    const InputShape = {
      beforePath: z.string().describe("Path to the baseline tokens JSON (Style Dictionary / W3C DTCG format)."),
      afterPath: z.string().describe("Path to the new tokens JSON."),
      ignoreKeys: z
        .array(z.string())
        .optional()
        .describe("Dot-path keys to ignore (e.g. ['$description','$extensions'])."),
    };
  • src/index.ts:27-29 (registration)
    Registration call: registerDesignTokenDiff(server) is invoked to wire up the tool on the MCP server.
    registerDesignTokenDiff(server);
    registerStorybookStoryRun(server);
    registerScaffoldComponent(server);
  • Helper functions: isObject, isToken, flatten (recursively flattens token tree into path→token map), and classifyNote (generates human-readable notes for color/dimension type changes).
    function isObject(v: Json): v is Record<string, Json> {
      return typeof v === "object" && v !== null && !Array.isArray(v);
    }
    
    /**
     * A W3C design token has a `$value` (and usually `$type`). Otherwise it's a group.
     */
    function isToken(v: Json): v is Record<string, Json> {
      return isObject(v) && Object.prototype.hasOwnProperty.call(v, "$value");
    }
    
    interface Change {
      path: string;
      kind: "added" | "removed" | "changed";
      before?: Json;
      after?: Json;
      type?: string;
      note?: string;
    }
    
    function flatten(node: Json, prefix: string, acc: Map<string, Record<string, Json>>) {
      if (isToken(node)) {
        acc.set(prefix, node);
        return;
      }
      if (isObject(node)) {
        for (const [k, v] of Object.entries(node)) {
          if (k.startsWith("$")) continue; // metadata like $description at group level
          flatten(v, prefix ? `${prefix}.${k}` : k, acc);
        }
      }
    }
    
    function classifyNote(type: string | undefined, before: Json, after: Json): string | undefined {
      if (!type) return undefined;
      if (type === "color" && typeof before === "string" && typeof after === "string") {
        return `color change: ${before} → ${after}`;
      }
      if ((type === "dimension" || type === "spacing") && typeof before === "string" && typeof after === "string") {
        return `dimension change: ${before} → ${after}`;
      }
      return undefined;
    }
  • Utility functions used by the handler: jsonResult (wraps data into text content) and errorResult (wraps error messages).
    export function jsonResult(data: unknown) {
      return textResult(JSON.stringify(data, null, 2));
    }
    
    export function errorResult(message: string) {
      return textResult(`ERROR: ${message}`, true);
    }
Behavior4/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It states the tool reports added, removed, and changed tokens with $type-aware classification, which implies a read-only comparison. It does not mention side effects or required permissions, but for a diff tool, the behavior is sufficiently 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?

The description is only two sentences long, front-loading the core action in the first sentence and adding a use case in the second. Every word is informative with no fluff.

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 has no output schema, the description adequately describes what the diff reports (added, removed, changed tokens). It mentions the input format and the classification approach. The absence of output format details is a minor gap, but overall the description is sufficient for an agent to understand the tool's behavior.

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% with clear descriptions for all three parameters. The tool description adds high-level context (e.g., format, output behavior) but does not provide additional meaning about the parameters beyond the schema. Baseline of 3 is appropriate.

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 clearly states the tool diffs design-token JSON files, specifies the format (W3C DTCG / Style Dictionary), and lists what it reports (added, removed, changed tokens with type-aware classification). The use case (PR review) distinguishes it from sibling tools (e.g., axe_audit, bundle_budget_check).

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 explicitly mentions a use case ('Useful for PR review of design-system changes'), which guides when to use it. It does not specify when not to use it or name alternatives, but the context is clear and no sibling tool overlaps with this diffing functionality.

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