Skip to main content
Glama
by m-yoshiro
find-components-by-name.ts1.03 kB
import { ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; import { type Component, getComponents } from '../storybook-api.js'; const FindComponentByNameParamsSchema = z.object({ name: z.string().describe('Component name or keyword to search for'), }); export const findComponentsByName = async ( args: z.infer<typeof FindComponentByNameParamsSchema> & { storybookStaticDir: string } ) => { try { const components = await getComponents(args.storybookStaticDir); const searchTerm = args.name.toLowerCase(); const matchingComponents = components.filter((component: Component) => component.name.toLowerCase().includes(searchTerm) ); return { content: [ { type: 'text', text: JSON.stringify(matchingComponents, null, 2), }, ], }; } catch (error) { console.error('Error finding component by name:', error); throw new McpError(ErrorCode.InternalError, 'Failed to find component by name'); } };

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