Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/jolly-gifts-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@storybook/addon-mcp': patch
---

Fix enabling docs toolset even when component manifests were not present
2 changes: 1 addition & 1 deletion packages/addon-mcp/src/mcp-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
const responseText = dataLine!.replace(/^data: /, '').trim();
const parsedResponse = JSON.parse(responseText);

expect(parsedResponse.result.instructions).toContain(

Check failure on line 340 in packages/addon-mcp/src/mcp-handler.test.ts

View workflow job for this annotation

GitHub Actions / Test

src/mcp-handler.test.ts > mcpServerHandler > should include docs-style instructions when docs toolset is selected and manifest is available

AssertionError: expected '' to contain 'Follow these workflows when working w…' - Expected + Received - Follow these workflows when working with UI and/or Storybook. ❯ src/mcp-handler.test.ts:340:46
'Follow these workflows when working with UI and/or Storybook.',
);
expect(parsedResponse.result.instructions).toContain('## Documentation Workflow');
Expand Down Expand Up @@ -401,7 +401,7 @@
return { componentsManifest: true };
}
if (key === 'experimental_manifests') {
return vi.fn();
return { components: { v: 1, components: {} } };
}
return defaultValue;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/addon-mcp/src/preset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
return Promise.resolve({ experimentalComponentsManifest: true });
}
if (key === 'experimental_manifests') {
return Promise.resolve({});
return Promise.resolve({ components: { v: 1, components: {} } });
}
return Promise.resolve(undefined);
}),
Expand Down Expand Up @@ -275,7 +275,7 @@
await (experimental_devServer as any)(mockApp, optionsWithRefs);

// The preset should have called presets.apply('refs')
expect(optionsWithRefs.presets.apply).toHaveBeenCalledWith('refs', {});

Check warning on line 278 in packages/addon-mcp/src/preset.test.ts

View workflow job for this annotation

GitHub Actions / Lint

typescript-eslint(unbound-method)

void`, or consider using an arrow function instead.
});

it('should handle refs config returning non-object gracefully', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/addon-mcp/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const experimental_devServer: PresetPropertyFn<'experimental_devServer'>
</div>`;
} else if (!manifestStatus.hasFeatureFlag) {
docsNotice = `<div class="toolset-notice">
This toolset requires enabling the experimental component manifest feature.
This toolset requires enabling the component manifest feature.
<a target="_blank" href="https://github.com/storybookjs/mcp/tree/main/packages/addon-mcp#docs-tools-experimental">Learn how to enable it</a>
Comment thread
JReinhold marked this conversation as resolved.
</div>`;
}
Expand Down
23 changes: 23 additions & 0 deletions packages/addon-mcp/src/tools/is-manifest-available.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,27 @@ describe('getManifestStatus', () => {
const result = await getManifestStatus(mockOptions);
expect(result).toEqual(expected);
});

it('should correctly detect no manifests when components are not present in experimental_manifests', async () => {
// the `manifests` preset can be present but without manifests.components, because `addon-docs` sets manifests.docs
const result = await getManifestStatus({
presets: {
apply: vi.fn(async (key: string) => {
if (key === 'features') {
return { componentsManifest: true };
}
if (key === 'experimental_manifests') {
// addon-docs has set manifests.docs, but there are no actual component manifests
return { docs: { v: 1, docs: {} } };
}
return undefined;
}),
},
} as unknown as Options);
expect(result).toEqual({
available: false,
hasManifests: false,
hasFeatureFlag: true,
});
});
});
3 changes: 2 additions & 1 deletion packages/addon-mcp/src/tools/is-manifest-available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const getManifestStatus = async (options: Options): Promise<ManifestStatu
options.presets.apply('experimental_componentManifestGenerator'),
]);

const hasManifests = !!manifests || !!legacyComponentManifestGenerator;
const hasManifests =
(manifests && 'components' in manifests) || !!legacyComponentManifestGenerator;
const hasFeatureFlag = !!(
features?.componentsManifest ?? features?.experimentalComponentsManifest
);
Expand Down
Loading