Skip to main content
Glama
custom-tools.test.ts1.93 kB
import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { StorybookMCPServer } from '../src/server.js'; describe('Custom Tools Support', () => { let originalEnv: typeof process.env; beforeEach(() => { originalEnv = { ...process.env }; }); afterEach(() => { process.env = originalEnv; }); it('should parse valid CUSTOM_TOOLS configuration', () => { const customTools = [ { name: "getIconList", description: "Get All Icons from the Icon page", parameters: {}, page: "https://example.com/storybook/?path=/docs/icon--docs", handler: "Array.from(document.querySelectorAll('.icon-name')).map(i => i.textContent)" } ]; process.env.STORYBOOK_URL = "https://example.com/index.json"; process.env.CUSTOM_TOOLS = JSON.stringify(customTools); expect(() => new StorybookMCPServer()).not.toThrow(); }); it('should handle invalid CUSTOM_TOOLS JSON gracefully', () => { process.env.STORYBOOK_URL = "https://example.com/index.json"; process.env.CUSTOM_TOOLS = "invalid json"; expect(() => new StorybookMCPServer()).not.toThrow(); }); it('should validate custom tool fields', () => { const invalidCustomTools = [ { name: "invalidTool", // Missing required fields }, { name: "anotherInvalidTool", description: "Valid description", page: "invalid-url", handler: "valid handler code" } ]; process.env.STORYBOOK_URL = "https://example.com/index.json"; process.env.CUSTOM_TOOLS = JSON.stringify(invalidCustomTools); expect(() => new StorybookMCPServer()).not.toThrow(); }); it('should handle missing CUSTOM_TOOLS environment variable', () => { process.env.STORYBOOK_URL = "https://example.com/index.json"; delete process.env.CUSTOM_TOOLS; expect(() => new StorybookMCPServer()).not.toThrow(); }); });

Latest Blog Posts

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/mcpland/storybook-mcp'

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