UNPKG

@trimble-oss/modus-mcp-server

Version:

An MCP server providing information about Modus React form and UI components

197 lines 7.25 kB
#!/usr/bin/env node import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js'; import { ComponentRegistry } from './modules/component-registry.js'; // Initialize component registry const registry = new ComponentRegistry(); // Create MCP server const server = new Server({ name: 'modus-mcp-server', version: '1.0.0', }, { capabilities: { tools: {}, resources: {}, }, }); // List tools handler server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'getting_started_guidelines', description: 'Get guidelines for installation and usage of Modus components', inputSchema: { type: 'object', properties: {}, additionalProperties: false, }, }, { name: 'get_list_of_all_modus_components', description: 'Get a list of all available Modus components (both form and UI)', inputSchema: { type: 'object', properties: {}, additionalProperties: false, }, }, { name: 'get_component_details', description: 'Get properties and usage examples for a specific Modus component', inputSchema: { type: 'object', properties: { component_name: { type: 'string', description: 'The name of the Modus component', }, framework: { type: 'string', description: 'The framework (optional, defaults to React)', enum: ['react', 'angular'], }, }, required: ['component_name'], additionalProperties: false, }, }, { name: 'get_modus_icons_by_char', description: 'Get Modus icon names that start with the specified character prefix', inputSchema: { type: 'object', properties: { char_prefix: { type: 'string', description: 'Character prefix to filter icons (optional)', default: '', }, }, additionalProperties: false, }, }, ], }; }); // Tool call handler server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case 'getting_started_guidelines': { const guidelines = await registry.getInstallationGuidelines(); return { content: [ { type: 'text', text: JSON.stringify({ success: true, guidelines }, null, 2), }, ], }; } case 'get_list_of_all_modus_components': { const components = await registry.getAllComponents(); return { content: [ { type: 'text', text: JSON.stringify({ success: true, components }, null, 2), }, ], }; } case 'get_component_details': { const { component_name, framework } = args; console.error(`Fetching details for component: ${component_name} (Framework: ${framework || 'React'})`); const details = await registry.getComponentDetails(component_name, framework); return { content: [ { type: 'text', text: JSON.stringify({ success: true, details }, null, 2), }, ], }; } case 'get_modus_icons_by_char': { const { char_prefix = '' } = args; const icons = await registry.getIconsByChar(char_prefix); return { content: [ { type: 'text', text: JSON.stringify({ success: true, icons }, null, 2), }, ], }; } default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2), }, ], isError: true, }; } }); // List resources handler server.setRequestHandler(ListResourcesRequestSchema, async () => { return { resources: [ { uri: 'modus://knowledge-base', name: 'Modus Knowledge Base', description: 'Complete Modus design system knowledge base', mimeType: 'application/json', }, ], }; }); // Read resource handler server.setRequestHandler(ReadResourceRequestSchema, async (request) => { const { uri } = request.params; if (uri === 'modus://knowledge-base') { try { const knowledgeBase = await registry.getKnowledgeBase(); return { contents: [ { uri, mimeType: 'application/json', text: JSON.stringify(knowledgeBase, null, 2), }, ], }; } catch (error) { throw new Error(`Failed to read knowledge base: ${error instanceof Error ? error.message : String(error)}`); } } throw new Error(`Unknown resource: ${uri}`); }); // Start server with stdio transport async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error('Modus MCP Server started with stdio transport'); console.error('Available tools:'); console.error('- getting_started_guidelines'); console.error('- get_list_of_all_modus_components'); console.error('- get_component_details'); console.error('- get_modus_icons_by_char'); } // ES module entry point main().catch((error) => { console.error('Server error:', error); process.exit(1); }); //# sourceMappingURL=index.js.map