Skip to main content
Glama
ashios15

MCP Frontend Tools Server

by ashios15

Storybook Story Run

storybook_story_run

Load a Storybook story in headless Chromium, optionally capture a screenshot, and run an axe-core accessibility audit.

Instructions

Load a single Storybook story in headless Chromium via iframe.html, optionally screenshot it, and run an axe-core audit against the rendered output. Requires playwright.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
storybookUrlYesBase URL of a running Storybook, e.g. http://localhost:6006.
storyIdYesStory id as it appears in the URL (e.g. 'components-button--primary').
screenshotPathNoIf set, save a PNG of the rendered story to this absolute path.
runAxeNoRun an axe-core audit of the rendered story (default true).
viewportNo
colorSchemeNo
timeoutMsNo

Implementation Reference

  • The registerStorybookStoryRun function registers the 'storybook_story_run' tool with the MCP server. The handler (lines 40-126) launches headless Chromium via Playwright, navigates to the story's iframe.html URL, optionally takes a screenshot, and runs an axe-core accessibility audit against the rendered story.
    export function registerStorybookStoryRun(server: McpServer) {
      server.registerTool(
        "storybook_story_run",
        {
          title: "Storybook Story Run",
          description:
            "Load a single Storybook story in headless Chromium via iframe.html, optionally screenshot it, and run an axe-core audit against the rendered output. Requires `playwright`.",
          inputSchema: InputShape,
        },
        async (args) => {
          try {
            const pw = await loadOptional<typeof import("playwright")>(
              "playwright",
              "npm i -D playwright && npx playwright install chromium"
            );
            const runAxe = args.runAxe ?? true;
            const timeout = args.timeoutMs ?? 20000;
            const base = args.storybookUrl.replace(/\/+$/, "");
            const iframeUrl = `${base}/iframe.html?viewMode=story&id=${encodeURIComponent(args.storyId)}`;
            const browser = await pw.chromium.launch();
            try {
              const context = await browser.newContext({
                viewport: args.viewport ?? { width: 1280, height: 800 },
                colorScheme: args.colorScheme ?? "light",
              });
              const page = await context.newPage();
              const errors: string[] = [];
              page.on("pageerror", (e: Error) => errors.push(e.message));
              await page.goto(iframeUrl, { waitUntil: "networkidle", timeout });
              // Storybook renders inside #storybook-root (newer) or #root (older)
              await page
                .waitForSelector("#storybook-root, #root", { timeout })
                .catch(() => {});
              const result: Record<string, unknown> = {
                storyId: args.storyId,
                iframeUrl,
                pageErrors: errors,
              };
              if (args.screenshotPath) {
                await fs.mkdir(path.dirname(args.screenshotPath), { recursive: true });
                await page.screenshot({ path: args.screenshotPath, fullPage: false });
                result.screenshotPath = args.screenshotPath;
              }
              if (runAxe) {
                await page.addScriptTag({ content: axeSource.source });
                const axeResults = await page.evaluate(async () => {
                  // @ts-expect-error axe injected
                  const axe = window.axe;
                  const res = await axe.run(
                    document.querySelector("#storybook-root, #root") ?? document,
                    {
                      runOnly: {
                        type: "tag",
                        values: ["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa", "best-practice"],
                      },
                      resultTypes: ["violations", "incomplete"],
                    }
                  );
                  return res;
                });
                const r = axeResults as {
                  violations: Array<{
                    id: string;
                    impact: string | null;
                    help: string;
                    helpUrl: string;
                    nodes: Array<{ target: string[]; html: string; failureSummary?: string }>;
                  }>;
                  incomplete: Array<{ id: string; help: string; nodes: unknown[] }>;
                };
                result.axe = {
                  violationCount: r.violations.length,
                  violations: r.violations.map((v) => ({
                    id: v.id,
                    impact: v.impact,
                    help: v.help,
                    helpUrl: v.helpUrl,
                    nodes: v.nodes.slice(0, 3).map((n) => ({
                      target: n.target,
                      html: n.html.slice(0, 300),
                      failureSummary: n.failureSummary,
                    })),
                    nodeCount: v.nodes.length,
                  })),
                  incompleteCount: r.incomplete.length,
                };
              }
              return jsonResult(result);
            } finally {
              await browser.close();
            }
          } catch (err) {
            return errorResult(err instanceof Error ? err.message : String(err));
          }
        }
      );
    }
  • Input validation schema for the tool using Zod: storybookUrl (URL), storyId (string), screenshotPath (optional string), runAxe (optional boolean, default true), viewport (optional {width, height}), colorScheme (optional 'light'|'dark'|'no-preference'), timeoutMs (optional positive integer).
    const InputShape = {
      storybookUrl: z
        .string()
        .url()
        .describe("Base URL of a running Storybook, e.g. http://localhost:6006."),
      storyId: z
        .string()
        .describe("Story id as it appears in the URL (e.g. 'components-button--primary')."),
      screenshotPath: z
        .string()
        .optional()
        .describe("If set, save a PNG of the rendered story to this absolute path."),
      runAxe: z.boolean().optional().describe("Run an axe-core audit of the rendered story (default true)."),
      viewport: z
        .object({
          width: z.number().int().positive(),
          height: z.number().int().positive(),
        })
        .optional(),
      colorScheme: z.enum(["light", "dark", "no-preference"]).optional(),
      timeoutMs: z.number().int().positive().optional(),
    };
  • src/index.ts:8-29 (registration)
    Import of registerStorybookStoryRun from the tool module.
    import { registerStorybookStoryRun } from "./tools/storybook-story-run.js";
    import { registerScaffoldComponent } from "./tools/scaffold-component.js";
    
    async function main() {
      const server = new McpServer(
        {
          name: "mcp-frontend-tools",
          version: "2.0.0",
        },
        {
          capabilities: { tools: {} },
          instructions:
            "Frontend engineering toolbox: run real axe-core accessibility audits, take Playwright screenshots, enforce bundle budgets, diff design tokens, and execute Storybook stories headlessly. Use these before opening a PR that touches UI.",
        }
      );
    
      registerAxeAudit(server);
      registerPageScreenshot(server);
      registerBundleBudget(server);
      registerDesignTokenDiff(server);
      registerStorybookStoryRun(server);
      registerScaffoldComponent(server);
  • src/index.ts:28-28 (registration)
    Registration call: registerStorybookStoryRun(server) wires the tool into the MCP server.
    registerStorybookStoryRun(server);
  • The loadOptional helper used by the handler to dynamically import the 'playwright' peer dependency, providing a user-friendly install hint if missing.
    export async function loadOptional<T>(
      moduleName: string,
      install: string
    ): Promise<T> {
      try {
        return (await import(/* @vite-ignore */ moduleName)) as T;
      } catch (err) {
        const hint = `The '${moduleName}' package is not installed. Install it with:\n  ${install}`;
        const cause = err instanceof Error ? err.message : String(err);
        throw new Error(`${hint}\n\nUnderlying error: ${cause}`);
      }
    }
Behavior3/5

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

With no annotations, the description must cover behavioral traits. It discloses the main actions (load, screenshot, audit) and the need for Playwright, but lacks details on side effects like browser resource usage, error handling, or that it returns axe results.

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 with no fluff. The purpose and key requirement are front-loaded in the first sentence, making it efficient.

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

Completeness2/5

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

The tool has 7 parameters, nested objects, and no output schema. The description omits return values, parameter interactions, and behavioral details like error scenarios or required environment setup, making it incomplete for a complex tool.

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 57%, so the description should add meaning, but it does not explain parameters beyond the schema. It only gives a generic summary, leaving parameter nuances (e.g., viewport, colorScheme, timeoutMs) solely to the schema.

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 it loads a single Storybook story via headless Chromium, with optional screenshot and axe-core audit. It distinguishes from siblings like page_screenshot (general) and axe_audit (general audit) by focusing on Storybook stories.

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

Usage Guidelines3/5

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

The description implies usage for testing Storybook stories but does not explicitly contrast with sibling tools or specify when not to use it. It only mentions a prerequisite (Playwright), not exclusion criteria.

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