Skip to main content
Glama
by m-yoshiro
get-component-details.test.ts2.64 kB
import { beforeEach, describe, expect, it, spyOn } from 'bun:test'; import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js'; import * as storybookApi from '../storybook-api.js' import type { Component } from '../storybook-api.js'; import { getComponentDetails } from './get-component-details.js'; describe('get-component-details', () => { const mockConfig = { storybookStaticDir: './test-storybook-static' }; const mockComponents: Component[] = [ { id: 'button', name: 'Button', props: [{ name: 'color', type: 'string', defaultValue: null }, { name: 'size', type: 'string', defaultValue: null }], variants: { 'default': { name: 'Default', title: 'Button', parameters: { __id: 'button-default', docsOnly: false, fileName: 'button.stories.js', jsx: '<Button>Click me</Button>' } } } }, { id: 'card', name: 'Card', props: [{ name: 'title', type: 'string', defaultValue: null }], variants: { } } ]; beforeEach(() => { // Mock getComponents to return our test components spyOn(storybookApi, 'getComponents').mockResolvedValue(mockComponents); }); it('should return the component details when the component is found', async () => { const result = await getComponentDetails({ name: 'Button', storybookStaticDir: mockConfig.storybookStaticDir }); expect(storybookApi.getComponents).toHaveBeenCalledWith(mockConfig.storybookStaticDir); expect(result).toEqual({ content: [ { type: 'text', text: JSON.stringify(mockComponents[0], null, 2), }, ], }); }); it('should throw McpError when the component is not found', async () => { spyOn(console, 'error').mockImplementation(() => {}); await expect(getComponentDetails({ name: 'NonExistent', storybookStaticDir: mockConfig.storybookStaticDir })) .rejects .toThrow(new McpError(ErrorCode.MethodNotFound, 'Component "NonExistent" not found')); }); it('should throw McpError when getComponents fails', async () => { // Mock getComponents to throw an error const testError = new Error('Test error'); spyOn(storybookApi, 'getComponents').mockRejectedValue(testError); // Expect function to throw McpError await expect(getComponentDetails({ name: 'Button', storybookStaticDir: mockConfig.storybookStaticDir })).rejects.toThrow(McpError); // Verify console error was called expect(console.error).toHaveBeenCalledWith('Error getting component details:', testError); }); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/m-yoshiro/storybook-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server