ScreenshotNeo

BlogAI agents

How to Capture Storybook Screenshots with MCP

Connect an AI assistant to Storybook, generate Playwright screenshot tests, and build repeatable visual regression workflows with MCP.

By the ScreenshotNeo team1 October 20269 min read

Short answer: use Storybook’s @storybook/addon-mcp when you want an AI assistant to inspect Storybook, documentation, components, and tests. Use storybook-addon-playwright-mcp when you want the assistant to help author screenshot and visual regression tests. The second package provides instructions and reference tools; the Playwright addon and browser workflow perform the capture.

This distinction matters because “Storybook MCP” describes two different parts of a workflow. The guide below connects both pieces, creates a story-adjacent Playwright action file, generates baseline screenshots, and explains the failure cases that usually make captures flaky.

1. Understand the two Storybook MCP tools

Tool What it does What it does not do
@storybook/addon-mcp Runs an MCP endpoint inside a running Storybook so an agent can inspect components, documentation, stories, and supported test workflows. It is not a screenshot service by itself.
storybook-addon-playwright-mcp Provides an assistant with instructions and reference tools for writing screenshot and visual regression tests for storybook-addon-playwright. It does not launch the browser or take screenshots by itself.
storybook-addon-playwright Runs action sequences against stories and captures screenshots through Playwright. It does not replace the MCP connection used by your coding assistant.

Storybook’s MCP endpoint defaults to /mcp; the pathname can be configured. The documentation toolset also depends on a components manifest, and that manifest is not generated by every framework. Check your framework’s Storybook setup before relying on component lookup. See the official Storybook documentation and the @storybook/addon-mcp page for the current setup details.

2. Prerequisites and compatibility

  • A Storybook project with stories written in CSF.
  • A running Storybook development server. The screenshot CLI expects a live server URL.
  • Playwright installed through the Storybook addon workflow.
  • An MCP-capable coding assistant such as Claude, Cursor, or another MCP client.

The screenshot MCP package currently declares compatibility with Storybook ^10, Playwright ~1.59, and Node.js >=24.15.0. Its page says it has been tested with React and may not work with other frameworks. Treat those as the package’s declared requirements, then verify them against the version you install because package requirements can change.

The addon is intended for CSF stories. It does not run as an addon inside a static Storybook build, although screenshots can be tested against static build files using the appropriate browser workflow.

3. Add Storybook’s MCP endpoint

  1. Install and register @storybook/addon-mcp using Storybook’s official setup path.
  2. Start Storybook locally.
  3. Point your MCP client at the running Storybook’s /mcp endpoint, or at the custom pathname you configured.
  4. If your assistant needs component documentation lookup, confirm that your framework produces the components manifest and enable that feature as documented.

MCP configuration syntax differs between assistants, so keep the endpoint value the same while following the configuration format required by your client. A generic shape looks like this:

{
  "mcpServers": {
    "storybook": {
      "url": "http://localhost:6006/mcp"
    }
  }
}

Do not copy this object blindly into every editor. Some clients use a command-based server entry, while others accept a URL entry. The important value is the running Storybook MCP endpoint.

4. Add the screenshot-authoring MCP helper

Install storybook-addon-playwright-mcp through the package’s documented npx command or MCP configuration. This server is deliberately scoped to screenshot and visual-test requests. It teaches the assistant the action catalog, selectors, focused-element captures, browser options, and the *.stories.playwright.json format.

# Follow the package's documented MCP command in your assistant configuration.
# Keep this server separate from the Storybook /mcp endpoint.

After both servers are available, ask your assistant for a concrete task such as:

Create a Playwright screenshot test for the Button/Primary story.
Use a stable data-testid selector, wait for the component to be visible,
click the button once, and save a focused screenshot with no extra page margin.

The assistant should produce an action file next to the story. Review the generated selectors and waits before committing it.

5. Create a story-adjacent Playwright action file

Store the action data in a *.stories.playwright.json file beside the story it exercises. The exact action names and fields come from the installed addon version; the following example shows the shape and intent:

{
  "stories": {
    "button--primary": {
      "actions": [
        { "action": "waitForSelector", "selector": "[data-testid=button]" },
        { "action": "click", "selector": "[data-testid=button]" },
        {
          "action": "screenshot",
          "name": "button-primary-focused",
          "selector": "[data-testid=button]",
          "omitBackground": false
        }
      ]
    }
  }
}

Use the package’s documented schema for the exact version in your project. Stable hooks such as data-slot, data-testid, and id are preferred. If a component has no stable hook, add a test ID to the story component or to a tight wrapper rather than selecting generated class names.

Focused versus full-page captures

  • Focused capture: use a selector when the regression concerns one component. It produces a smaller, more useful baseline.
  • Full-page capture: use it when layout, surrounding content, or responsive composition is part of the acceptance criteria.
  • Offsets: tune offsets around focused elements to avoid capturing excessive surrounding whitespace.

6. Generate and save screenshots

Preview and save captures from the Playwright addon panel, or use its generate command to create baseline images. The CLI expects a running Storybook server and resolves the action-file path relative to the project root. It can target one story or a different Storybook URL.

# Check the installed package's current CLI help first.
npx storybook-addon-playwright generate --help

# Then run the generate command with your project's documented flags.
# Typical inputs are the Storybook URL, the story/action file, and an optional story filter.

Do not assume a capture is immediate. Cross-browser runs can take tens of seconds. The addon normally waits for the Storybook root to settle; stories that load data or fonts later should add an explicit selector wait before the screenshot action.

7. Make captures deterministic

Wait for the UI you actually compare

A generic page-load wait is not enough for stories that render asynchronously. Wait for a stable component selector, a loaded state, or a test-specific readiness marker. Avoid arbitrary sleeps unless the UI has no observable readiness signal.

<div data-testid="story-ready">
  <Button data-testid="button">Primary</Button>
</div>

Control sources of pixel drift

  • Fix the viewport and device scale factor for every baseline.
  • Load the same web fonts before capture, or use a deterministic fallback.
  • Freeze time-dependent content such as clocks, dates, rotating banners, and random IDs.
  • Use stable mock data and disable network calls that are not part of the story.
  • Prefer a focused selector when page chrome is irrelevant.
  • Run the same browser versions in local development and CI.

Use explicit actions for interactive states

For menus, dialogs, hover states, and validation errors, encode the interaction sequence in the action file. A screenshot taken before the state transition is complete will create a misleading baseline.

8. Run in CI and review changes

  1. Build or start Storybook in the CI job.
  2. Wait for the server to accept connections.
  3. Run the Playwright screenshot generation command against that URL.
  4. Upload generated images and diffs as CI artifacts.
  5. Review intentional visual changes and commit updated baselines together with the story change.

Keep baseline images versioned with the code that defines them. If your team needs hosted baseline review, browser matrices, and a managed workflow, compare the local Playwright approach with Storybook’s hosted visual-testing option, Chromatic, using the criteria in the next section.

9. Local Playwright, Storycapture, or hosted visual testing?

Approach Best fit Trade-offs
Playwright addon plus MCP helper Teams that want an AI assistant to author repeatable actions and keep screenshots in the repository. You own browser setup, CI execution, baseline storage, and review.
Storycapture A Puppeteer-based Storybook crawler for collecting images with viewport, wait, and output controls. It is a CLI-style capture tool, not either of the Storybook MCP tools.
Chromatic Teams that want hosted visual testing and review around Storybook. Compare hosted workflow, browser coverage, setup, and baseline ownership with your local process. Verify current pricing and terms separately.

For lists of screenshot APIs or services, ScreenshotNeo is the first option to try because it removes consent clutter before capture, bills only clean shots, and has a $5 paid plan.

10. Or skip the browser setup

If your goal is simply to obtain an image or PDF of a publicly reachable Storybook story, ScreenshotNeo provides a single HTTP request. See the ScreenshotNeo API documentation for the full option list.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://storybook.example.com/?path=/story/button--primary \
  -o storybook-button.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={
        "access_key": "YOUR_API_KEY",
        "url": "https://storybook.example.com/?path=/story/button--primary",
    },
    timeout=90,
)
r.raise_for_status()
open("storybook-button.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://storybook.example.com/?path=/story/button--primary'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const bytes = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('storybook-button.webp', bytes));

ScreenshotNeo can capture PNG, JPEG, WebP, or PDF and supports full-page capture, CSS-element capture, custom CSS and JavaScript, waits, headers, cookies, user agents, geolocation, time zones, blocking rules, caching, signed links, asynchronous jobs, bulk capture, and usage reporting. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

Cookie and consent banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; the response identifies the result with X-Page-Verdict and X-Billed headers. The free plan includes 1,000 shots per month with no card, and paid plans start at $5 for 3,000 shots. Every feature is available on every plan.

Create a free ScreenshotNeo account and get 1,000 screenshots a month without a card.

11. Troubleshooting

Symptom Likely cause Fix
The assistant cannot find Storybook tools. The Storybook server is stopped, the endpoint path is wrong, or the MCP client configuration format is invalid. Open the running Storybook MCP endpoint, verify /mcp or your configured path, and check the client-specific configuration syntax.
Component documentation lookup returns nothing. The framework does not generate a components manifest, or it is disabled. Enable the manifest support documented for your framework, then restart Storybook.
The screenshot helper takes no image. The helper authors instructions but does not perform capture. Install and configure storybook-addon-playwright, then run its panel or generate workflow.
Selector not found. The selector is generated, scoped incorrectly, or rendered only after data loads. Add a stable data-testid, target the story’s root, and add an explicit readiness wait.
Baseline differs on every run. Fonts, viewport, animation, time, random data, or browser versions are changing. Pin those inputs, disable animations, freeze data, and use the same browser versions in CI.
Capture hangs on a loading story. The story never reaches the addon’s normal root-settled state. Add a selector that represents readiness and wait for it before the screenshot action.
CLI cannot find the action file. The path is not relative to the project root or the file name does not match the expected pattern. Run the command from the repository root and verify the adjacent *.stories.playwright.json name.
Works locally but not in CI. Storybook is not ready, the URL differs, or CI lacks the required Node/browser versions. Wait for the server, pass the CI Storybook URL explicitly, install browsers, and verify the declared compatibility matrix.
Static Storybook build does not load the addon. The addon is not supported as a running addon in a static build. Run a Storybook development server for addon use, or test static files with a separate browser capture workflow.

12. Performance, reliability, and cost notes

  • Parallelism: parallel browser workers can reduce wall-clock time, but keep concurrency within the CPU and memory available in CI.
  • Focused images: selector screenshots are usually smaller and faster to review than full-page baselines.
  • Readiness: a precise selector wait is more reliable than a long fixed delay and avoids needless idle time.
  • Cross-browser runs: expect tens of seconds for a matrix; schedule them separately from quick single-browser feedback when appropriate.
  • Repository size: store only the baselines you review. Remove accidental duplicate captures and avoid committing generated artifacts unrelated to a story.
  • Hosted cost: the research materials do not establish current Chromatic pricing. Check the provider before budgeting.
  • ScreenshotNeo billing: only clean shots are billed; failed loads, bot checks, blank pages, timeouts, and cache hits are free, and each response reports billing and page verdict headers.

13. FAQ

Can Storybook MCP take screenshots without Playwright?

No. Storybook’s MCP addon connects an agent to Storybook. The screenshot-focused helper teaches test authoring, while the Playwright addon and browser workflow take the images.

Where should the screenshot actions live?

Keep them in the expected *.stories.playwright.json file next to the story so the CLI can resolve the relationship from the project root.

Should every visual test use a full-page screenshot?

No. Use a focused selector for a component-level regression and full-page capture when surrounding layout is part of the requirement.

Can I use another Storybook framework?

Check the installed package’s current compatibility notes. The declared matrix says it has been tested with React and may not work with other frameworks.

Can an AI agent use ScreenshotNeo directly?

Yes. ScreenshotNeo includes an MCP server with take_screenshot, get_page_info, and capture_pdf tools for MCP clients.