Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
19 changes: 8 additions & 11 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"@storybook/mcp-internal-storybook": "0.0.0",
"@storybook/addon-mcp": "0.1.3",
"@storybook/mcp": "0.0.6"
},
"changesets": [
"dull-impalas-vanish",
"strict-boxes-sort"
]
"mode": "pre",
"tag": "next",
"initialVersions": {
"@storybook/mcp-internal-storybook": "0.0.0",
"@storybook/addon-mcp": "0.1.3",
"@storybook/mcp": "0.0.6"
},
"changesets": ["dull-impalas-vanish", "strict-boxes-sort"]
}
5 changes: 1 addition & 4 deletions packages/mcp/src/utils/error-to-mcp-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { errorToMCPContent, ManifestGetError } from './get-manifest.ts';

describe('errorToMCPContent', () => {
it('should convert ManifestGetError to MCP error content', () => {
const error = new ManifestGetError(
'Failed to get',
'https://example.com',
);
const error = new ManifestGetError('Failed to get', 'https://example.com');

const result = errorToMCPContent(error);

Expand Down
42 changes: 42 additions & 0 deletions packages/mcp/src/utils/format-manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,48 @@ describe('formatComponentManifest', () => {
</component>"
`);
});

it('should skip examples without snippets (e.g., when there are errors)', () => {
const manifest: ComponentManifest = {
id: 'button',
name: 'Button',
path: 'src/components/Button.tsx',
import: 'import { Button } from "@/components";',
examples: [
{
name: 'BrokenExample',
description: 'This example has an error and no snippet',
// No snippet property - should be skipped
},
{
name: 'WorkingExample',
description: 'This example works fine',
snippet: '<Button>Click me</Button>',
},
],
};

const result = formatComponentManifest(manifest);

// Should only include the working example, not the broken one
expect(result).toMatchInlineSnapshot(`
"<component>
<id>button</id>
<name>Button</name>
<example>
<example_name>Working Example</example_name>
<example_description>
This example works fine
</example_description>
<example_code>
import { Button } from "@/components";

<Button>Click me</Button>
</example_code>
</example>
</component>"
`);
});
});

describe('complete component', () => {
Expand Down
43 changes: 43 additions & 0 deletions packages/mcp/src/utils/get-manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,49 @@ describe('getManifest', () => {
'https://example.com/manifest.json',
);
});

it('should accept examples with missing snippets', async () => {
const manifestWithMissingSnippets: ComponentManifestMap = {
v: 1,
components: {
button: {
id: 'button',
path: 'src/components/Button.tsx',
name: 'Button',
description: 'A button component',
examples: [
{
name: 'Default',
description: 'Default button',
// snippet is optional and missing here (e.g., when there's an error)
},
{
name: 'Primary',
description: 'Primary button',
snippet: '<Button variant="primary">Click me</Button>',
},
],
},
},
};

global.fetch = vi.fn().mockResolvedValue({
ok: true,
headers: {
get: vi.fn().mockReturnValue('application/json'),
},
text: vi
.fn()
.mockResolvedValue(JSON.stringify(manifestWithMissingSnippets)),
});

const result = await getManifest('https://example.com/manifest.json');

expect(result).toEqual(manifestWithMissingSnippets);
expect(global.fetch).toHaveBeenCalledExactlyOnceWith(
'https://example.com/manifest.json',
);
});
});

describe('manifestProvider', () => {
Expand Down
Loading