Skip to content

Commit 762c0e8

Browse files
authored
Merge pull request #193 from storybookjs/fix-manifest-detection
Fix: Wrongly enabling docs toolset when only docs manifests where present
2 parents eaf6afa + c34f94a commit 762c0e8

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

.changeset/jolly-gifts-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@storybook/addon-mcp': patch
3+
---
4+
5+
Fix enabling docs toolset even when component manifests were not present

packages/addon-mcp/src/mcp-handler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ describe('mcpServerHandler', () => {
298298
return { experimentalComponentsManifest: true };
299299
}
300300
if (key === 'experimental_manifests') {
301-
return vi.fn();
301+
return { components: { v: 1, components: {} } };
302302
}
303303
return defaultValue;
304304
});
@@ -401,7 +401,7 @@ describe('mcpServerHandler', () => {
401401
return { componentsManifest: true };
402402
}
403403
if (key === 'experimental_manifests') {
404-
return vi.fn();
404+
return { components: { v: 1, components: {} } };
405405
}
406406
return defaultValue;
407407
});

packages/addon-mcp/src/preset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('experimental_devServer', () => {
7777
return Promise.resolve({ experimentalComponentsManifest: true });
7878
}
7979
if (key === 'experimental_manifests') {
80-
return Promise.resolve({});
80+
return Promise.resolve({ components: { v: 1, components: {} } });
8181
}
8282
return Promise.resolve(undefined);
8383
}),

packages/addon-mcp/src/preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const experimental_devServer: PresetPropertyFn<'experimental_devServer'>
130130
</div>`;
131131
} else if (!manifestStatus.hasFeatureFlag) {
132132
docsNotice = `<div class="toolset-notice">
133-
This toolset requires enabling the experimental component manifest feature.
133+
This toolset requires enabling the component manifest feature.
134134
<a target="_blank" href="https://github.com/storybookjs/mcp/tree/main/packages/addon-mcp#docs-tools-experimental">Learn how to enable it</a>
135135
</div>`;
136136
}

packages/addon-mcp/src/tools/is-manifest-available.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,27 @@ describe('getManifestStatus', () => {
9292
const result = await getManifestStatus(mockOptions);
9393
expect(result).toEqual(expected);
9494
});
95+
96+
it('should correctly detect no manifests when components are not present in experimental_manifests', async () => {
97+
// the `manifests` preset can be present but without manifests.components, because `addon-docs` sets manifests.docs
98+
const result = await getManifestStatus({
99+
presets: {
100+
apply: vi.fn(async (key: string) => {
101+
if (key === 'features') {
102+
return { componentsManifest: true };
103+
}
104+
if (key === 'experimental_manifests') {
105+
// addon-docs has set manifests.docs, but there are no actual component manifests
106+
return { docs: { v: 1, docs: {} } };
107+
}
108+
return undefined;
109+
}),
110+
},
111+
} as unknown as Options);
112+
expect(result).toEqual({
113+
available: false,
114+
hasManifests: false,
115+
hasFeatureFlag: true,
116+
});
117+
});
95118
});

packages/addon-mcp/src/tools/is-manifest-available.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const getManifestStatus = async (options: Options): Promise<ManifestStatu
2121
options.presets.apply('experimental_componentManifestGenerator'),
2222
]);
2323

24-
const hasManifests = !!manifests || !!legacyComponentManifestGenerator;
24+
const hasManifests =
25+
(manifests && 'components' in manifests) || !!legacyComponentManifestGenerator;
2526
const hasFeatureFlag = !!(
2627
features?.componentsManifest ?? features?.experimentalComponentsManifest
2728
);

0 commit comments

Comments
 (0)