Skip to content

Commit d2d0c5c

Browse files
committed
Do not include get-changed-stories instructions when changeDetection is disabled
1 parent 3bf69df commit d2d0c5c

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

packages/addon-mcp/src/instructions/storybook-story-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ play: async ({ canvas }) => {
146146
## Story Linking Agent Behavior
147147

148148
- ALWAYS provide story links after any changes to stories files, including changes to existing stories.
149-
- After changing UI, call `{{GET_CHANGED_STORIES_TOOL_NAME}}` first, then use `{{PREVIEW_STORIES_TOOL_NAME}}` with selected `storyId` values from those results.
149+
- {{STORY_LINKING_WORKFLOW}}
150150
- When sharing links, choose the most relevant subset for the user and avoid long lists (generally no more than 5 links).
151-
- If you do not share all changed story links, include this Storybook fallback link so the user can view the complete changed list: `/?statuses=affected;modified;new`.
151+
- {{CHANGED_STORY_FALLBACK_LINK_GUIDANCE}}
152152
- After changing any UI components, ALWAYS search for related stories that might cover the changes you've made. If you find any, provide the story links to the user. THIS IS VERY IMPORTANT, as it allows the user to visually inspect the changes you've made. Even later in a session when changing UI components or stories that have already been linked to previously, YOU MUST PROVIDE THE LINKS AGAIN.

packages/addon-mcp/src/tools/get-storybook-story-instructions.test.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot';
44
import { getAddonVitestConstants } from './run-story-tests.ts';
55
import { addGetUIBuildingInstructionsTool } from './get-storybook-story-instructions.ts';
66
import type { AddonContext } from '../types.ts';
7-
import { PREVIEW_STORIES_TOOL_NAME, GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME } from './tool-names.ts';
7+
import {
8+
PREVIEW_STORIES_TOOL_NAME,
9+
GET_CHANGED_STORIES_TOOL_NAME,
10+
GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME,
11+
} from './tool-names.ts';
812

913
vi.mock('./run-story-tests.ts', () => ({
1014
getAddonVitestConstants: vi.fn(),
@@ -157,7 +161,11 @@ describe('getUIBuildingInstructionsTool', () => {
157161
it('should return UI building instructions with framework placeholders replaced', async () => {
158162
const mockOptions = {
159163
presets: {
160-
apply: vi.fn().mockResolvedValue('@storybook/react-vite'),
164+
apply: vi.fn(async (presetName: string) => {
165+
if (presetName === 'framework') return '@storybook/react-vite';
166+
if (presetName === 'features') return { changeDetection: true };
167+
return undefined;
168+
}),
161169
},
162170
};
163171

@@ -188,13 +196,56 @@ describe('getUIBuildingInstructionsTool', () => {
188196
expect(instructions).toContain('@storybook/react-vite');
189197
expect(instructions).toContain('@storybook/react');
190198
expect(instructions).toContain(PREVIEW_STORIES_TOOL_NAME);
199+
expect(instructions).toContain(GET_CHANGED_STORIES_TOOL_NAME);
191200

192201
// Check that no placeholders remain
193202
expect(instructions).not.toContain('{{FRAMEWORK}}');
194203
expect(instructions).not.toContain('{{RENDERER}}');
195204
expect(instructions).not.toContain('{{PREVIEW_STORIES_TOOL_NAME}}');
196205
});
197206

207+
it('should not mention changed stories workflow when change detection is disabled', async () => {
208+
const mockOptions = {
209+
presets: {
210+
apply: vi.fn(async (presetName: string) => {
211+
if (presetName === 'framework') {
212+
return '@storybook/react-vite';
213+
}
214+
if (presetName === 'features') {
215+
return { changeDetection: false };
216+
}
217+
return undefined;
218+
}),
219+
},
220+
};
221+
222+
const testContext: AddonContext = {
223+
origin: 'http://localhost:6006',
224+
options: mockOptions as any,
225+
disableTelemetry: true,
226+
};
227+
228+
const request = {
229+
jsonrpc: '2.0' as const,
230+
id: 1,
231+
method: 'tools/call',
232+
params: {
233+
name: GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME,
234+
arguments: {},
235+
},
236+
};
237+
238+
const response = await server.receive(request, {
239+
sessionId: 'test-session',
240+
custom: testContext,
241+
});
242+
243+
const instructions = response.result?.content[0].text as string;
244+
245+
expect(instructions).toContain(PREVIEW_STORIES_TOOL_NAME);
246+
expect(instructions).not.toContain(GET_CHANGED_STORIES_TOOL_NAME);
247+
});
248+
198249
it('should handle Vue framework', async () => {
199250
const mockOptions = {
200251
presets: {

packages/addon-mcp/src/tools/get-storybook-story-instructions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,23 @@ Even if you're familiar with Storybook, call this tool to ensure you're followin
7777
}
7878

7979
const frameworkPreset = await options.presets.apply('framework');
80+
const featuresPreset = await options.presets.apply('features', {});
81+
const changeDetectionEnabled = featuresPreset?.changeDetection ?? false;
8082
const framework =
8183
typeof frameworkPreset === 'string' ? frameworkPreset : frameworkPreset?.name;
8284
const renderer = frameworkToRendererMap[framework!];
85+
const storyLinkingWorkflow = changeDetectionEnabled
86+
? `After changing UI, call \`${GET_CHANGED_STORIES_TOOL_NAME}\` first, then use \`${PREVIEW_STORIES_TOOL_NAME}\` with selected \`storyId\` values from those results.`
87+
: `After changing UI, call \`${PREVIEW_STORIES_TOOL_NAME}\` and share the most relevant links for the changes.`;
88+
const changedStoryFallbackLinkGuidance = changeDetectionEnabled
89+
? `If you do not share all changed story links, include this Storybook fallback link so the user can view the complete changed list: \`/?statuses=affected;modified;new\`.`
90+
: `When linking only a subset of stories, mention that additional relevant stories may exist in Storybook.`;
8391

8492
let uiInstructions = storyInstructionsTemplate
8593
.replace('{{FRAMEWORK}}', framework)
8694
.replace('{{RENDERER}}', renderer ?? framework)
87-
.replace('{{PREVIEW_STORIES_TOOL_NAME}}', PREVIEW_STORIES_TOOL_NAME)
88-
.replace('{{GET_CHANGED_STORIES_TOOL_NAME}}', GET_CHANGED_STORIES_TOOL_NAME);
95+
.replace('{{STORY_LINKING_WORKFLOW}}', storyLinkingWorkflow)
96+
.replace('{{CHANGED_STORY_FALLBACK_LINK_GUIDANCE}}', changedStoryFallbackLinkGuidance);
8997

9098
// Conditionally append story testing instructions if test toolset is enabled and addon-vitest is available
9199
const testToolsetAvailable =

0 commit comments

Comments
 (0)