UNPKG

ids-enterprise-mcp-server

Version:

Model Context Protocol (MCP) server providing comprehensive IDS Enterprise Web Components documentation access via GitLab API. Use with npx and GitLab token for instant access.

191 lines 8.19 kB
/** * Utility functions for IDS Enterprise Web Components MCP Server */ import { logger } from './logger.js'; export class ComponentUtils { /** * Categorize a component based on its name */ static categorizeComponent(componentName) { const name = componentName.toLowerCase(); let category = 'Other Components'; // default if (name.includes('input') || name.includes('textarea') || name.includes('dropdown') || name.includes('checkbox') || name.includes('radio') || name.includes('switch') || name.includes('date-picker') || name.includes('time-picker') || name.includes('lookup') || name.includes('multiselect') || name.includes('spinbox') || name.includes('slider') || name.includes('color-picker') || name.includes('editor') || name.includes('upload')) { category = 'Form Input Components'; } else if (name.includes('button') || name.includes('menu') || name.includes('tab') || name.includes('breadcrumb') || name.includes('pager') || name.includes('tree') || name.includes('wizard') || name.includes('modal') || name.includes('popup')) { category = 'Navigation and Interaction'; } else if (name.includes('chart') || name.includes('graph') || name.includes('progress') || name.includes('stats') || name.includes('kpi') || name.includes('treemap')) { category = 'Data Visualization'; } else if (name.includes('grid') || name.includes('list') || name.includes('card') || name.includes('accordion') || name.includes('splitter') || name.includes('container')) { category = 'Layout and Structure'; } else if (name.includes('alert') || name.includes('message') || name.includes('toast') || name.includes('notification') || name.includes('tooltip') || name.includes('loading')) { category = 'Feedback and Status'; } logger.debug(`Categorized ${componentName} as: ${category}`); return category; } /** * Extract component name from file path */ static extractComponentNameFromPath(filePath) { // Extract component name from file path const pathParts = filePath.split('/'); // Look for ids- component names in the path for (const part of pathParts) { if (part.startsWith('ids-')) { return part; } } // Look for component names in filename const fileName = pathParts[pathParts.length - 1]; if (fileName.includes('ids-')) { const match = fileName.match(/ids-[a-z-]+/); if (match) { return match[0]; } } // Fallback: use the directory name or filename const dirName = pathParts[pathParts.length - 2] || fileName.replace(/\.[^/.]+$/, ""); return dirName.startsWith('ids-') ? dirName : `ids-${dirName}`; } /** * Parse component README content */ static parseComponentReadme(componentName, content, filePath) { logger.debug(`Parsing README for component: ${componentName}`); const lines = content.split('\n'); let description = ''; const features = []; const attributes = []; const methods = []; const events = []; const examples = []; let currentSection = ''; let inCodeBlock = false; let currentExample = ''; for (const line of lines) { const trimmedLine = line.trim(); // Track code blocks for examples if (trimmedLine.startsWith('```')) { if (inCodeBlock) { if (currentExample.trim()) { examples.push(currentExample.trim()); logger.debug(`Found code example for ${componentName} (${currentExample.length} chars)`); } currentExample = ''; inCodeBlock = false; } else { inCodeBlock = true; } continue; } if (inCodeBlock) { currentExample += line + '\n'; continue; } // Section headers if (trimmedLine.startsWith('## ')) { currentSection = trimmedLine.replace('## ', '').toLowerCase(); logger.debug(`Found section in ${componentName}: ${currentSection}`); continue; } // Extract description (usually after # title and before first ##) if (!description && trimmedLine && !trimmedLine.startsWith('#') && currentSection === '') { description = trimmedLine; logger.debug(`Found description for ${componentName}: ${description.substring(0, 100)}...`); } // Extract attributes, methods, events based on section if (trimmedLine.startsWith('- ') || trimmedLine.startsWith('* ')) { const item = trimmedLine.substring(2); if (currentSection.includes('attribute') || currentSection.includes('properties')) { attributes.push(item); } else if (currentSection.includes('method')) { methods.push(item); } else if (currentSection.includes('event')) { events.push(item); } else if (currentSection.includes('feature')) { features.push(item); } } } const componentInfo = { name: componentName, category: ComponentUtils.categorizeComponent(componentName), description: description || `${componentName} component`, content, features, attributes, methods, events, examples, filePath }; logger.debug(`Parsed ${componentName}: ${features.length} features, ${attributes.length} attributes, ${methods.length} methods, ${events.length} events, ${examples.length} examples`); return componentInfo; } } export class FrameworkUtils { /** * Extract framework description from README content */ static extractFrameworkDescription(readmeContent) { const lines = readmeContent.split('\n'); for (let i = 0; i < Math.min(lines.length, 10); i++) { const line = lines[i].trim(); if (line && !line.startsWith('#') && !line.startsWith('```') && line.length > 20) { return line; } } return 'Framework integration examples for IDS Enterprise Web Components'; } } export class SearchUtils { /** * Calculate relevance score for search results */ static calculateRelevanceScore(searchTerms, component) { let relevanceScore = 0; for (const term of searchTerms) { if (component.name.toLowerCase().includes(term)) { relevanceScore += 5; // Component name matches are most important } if (component.description.toLowerCase().includes(term)) { relevanceScore += 3; // Description matches } if (component.category.toLowerCase().includes(term)) { relevanceScore += 2; // Category matches } if (component.content.toLowerCase().includes(term)) { relevanceScore += 1; // Content matches } // Check features, attributes, methods if (component.features.some(f => f.toLowerCase().includes(term))) { relevanceScore += 2; } if (component.attributes.some(a => a.toLowerCase().includes(term))) { relevanceScore += 2; } if (component.methods.some(m => m.toLowerCase().includes(term))) { relevanceScore += 2; } } return relevanceScore; } } //# sourceMappingURL=index.js.map