Repository navigation
Conversation
…device Add an `sb-rn` bin to @storybook/react-native, modelled on upstream Storybook's `storybook tools` / `storybook skills`: - `sb-rn docs list|show|show-story` runs the @storybook/mcp docs tools in-process against the story files, so it answers exactly like the MCP server and needs no device or bundler. - `sb-rn stories list|select`, `args update|reset`, `globals update` and `status` drive the connected device through the channel server and wait for it to confirm. - `sb-rn skills ui-workflow|component-docs|write-story` prints agent instructions that ship with the package; thin skills in skills/ point at them. The channel server gets a device-control layer shared by its HTTP endpoints and the MCP tools. It tracks each device's story, args, globals and last render error, decoding the telejson markers the device sends. New endpoints: GET /state, POST /update-args-sync, /reset-args-sync and /update-globals-sync. /select-story-sync keeps its 1000ms default and response shape, accepts ?timeout=, fails as soon as the story errors, and suggests ids when the story is not in the index. MCP gains get-device-state, update-story-args, reset-story-args and update-globals, and select-story now waits for the render. The running channel server writes its address to node_modules/.cache/storybook-react-native/channel-server.json so sb-rn finds it without guessing ports.
🦋 Changeset detectedLatest commit: 059709e The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
# Conflicts: # packages/react-native/src/metro/mcpServer.ts
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: N/A. Follows upstream Storybook 11's agent tooling (
storybook tools/storybook skills), which explicitly excludes React Native.What I did
Upstream Storybook moved its agent skills from MCP to a CLI (
npx storybook tools …). Their evals showed that coding agents that can run shell commands use the tools more reliably that way, and it needs no MCP client config. Upstream's CLI can't attach to us: it needs astorybook devinstance and a web builder. This PR adds an RN equivalent that uses the same vocabulary and is built on our channel server.New
sb-rnCLI (bin in@storybook/react-native)sb-rn docs list | show --id | show-story --storyIdruns the@storybook/mcpdocs tools in-process against the story files. The output is identical to the MCPdocs-*tools, with tool references rewritten to the CLI commands. It needs no device or bundler.sb-rn stories listlists the story ids from the node-side index.sb-rn stories select,args update,args reset,globals updateandstatusdrive the device through the channel server. Each waits for the device to confirm and prints the result: the rendered story, or the resulting args or globals.sb-rn skills ui-workflow | component-docs | write-storyprints agent instructions that ship with the installed version.--jsonis available, and the exit code is 1 on failure.--url/--host/--port, thenSTORYBOOK_WS_HOST/PORT, then a record the running server writes tonode_modules/.cache/storybook-react-native/channel-server.json, thenlocalhost:7007.Channel server: shared device-control layer (
deviceControl.ts)_duplicate_,_undefined_,_date_); before this, globals showed up as_duplicate_[…]strings.connectedClientsreports all clients.GET /state,POST /update-args-sync,/reset-args-syncand/update-globals-sync. Errors return{ success: false, code, error }.POST /select-story-sync/:idkeeps its 1000ms default and response shape for existing Maestro flows. It now also accepts?timeout=, fails right away with 422 when the story throws or is missing, and returns 404 with same-component suggestions when the id isn't in the index.beforeExitlistener when it closes. Tests that create many servers previously triggeredMaxListenersExceededWarning.MCP
get-device-state,update-story-args,reset-story-argsandupdate-globals.select-storynow waits for the render instead of firing and forgetting.manifestProvider.ts).Other
buildIndexreadsprocess.cwd()per call instead of at import, so--cwdworks.sb-rn)" page, and the MCP page lists the device tools.react-native-storybook-ui-workflowandreact-native-storybook-component-docsskills that defer tonpx sb-rn skills <id>. Both READMEs andAGENTS.md/CLAUDE.mdare updated.@storybook/react-native.Not in this PR (follow-ups):
/send-eventcurl and Maestro usage, so it needs its own discussion.componentPathand real tags inbuildIndex, which would enablefind-by-componentand!manifestfiltering.simctloradb; the skill says so.How to test
Unit tests:
pnpm -F @storybook/react-native test. There are 22 new tests: device-control endpoints against a fake device, telejson decoding, endpoint resolution order, the record file round trip, client error mapping, and a check that skill text only names real commands. All 87 tests pass, along withcheck:types,lintandformat:check.On a device (I ran this against
expo-exampleon an iOS 26.4 simulator, with Metro on 8090 andSTORYBOOK_WS_PORT=7017):Transcript from the device run:
Screenshots confirmed the device rendered the selected story, the updated title and variant, the args set over MCP
update-story-args, and the background change fromglobals update. The MCPtools/listreturned all 9 tools.docs/docs/intro/configuration/agent-cli.mdandmcp-configuration.md.