Skip to content
Merged
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
34 changes: 25 additions & 9 deletions code/e2e-tests/addon-mcp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import process from 'process';
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';
const type = process.env.STORYBOOK_TYPE || 'dev';
const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR;

const MCP_ENDPOINT = `${storybookUrl}/mcp`;

Expand Down Expand Up @@ -187,26 +188,41 @@ test.describe('addon-mcp', () => {
});
});

test.describe('Tool: get-story-urls', () => {
test.describe('Tool: preview-stories', () => {
test('should return story URLs for valid stories', async ({ request }) => {
const storyName = 'Primary';
const expectedPreviewUrl = `${storybookUrl}/?path=/story/example-button--primary`;

// Use a path pattern that works regardless of sandbox location
const response = await mcpRequest(request, 'tools/call', {
name: 'get-story-urls',
name: 'preview-stories',
arguments: {
stories: [
{
exportName: 'Primary',
// Use a relative-style path that the tool should recognize
absoluteStoryPath: '/src/stories/Button.stories.ts',
exportName: storyName,
absoluteStoryPath: `${sandboxDir}/src/stories/Button.stories.ts`,
},
],
},
});

expect(response.result).toHaveProperty('content');
expect(response.result.content).toHaveLength(1);
// Should contain either a valid URL or an error message about the story
expect(response.result.content[0]).toHaveProperty('text');
expect(response.result).toStrictEqual({
content: [
{
type: 'text',
text: expectedPreviewUrl,
},
],
structuredContent: {
stories: [
{
name: storyName,
previewUrl: expectedPreviewUrl,
title: 'Example/Button',
},
],
},
});
});
});

Expand Down
Loading