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.
345 lines • 15 kB
JavaScript
/**
* Main MCP Server class for IDS Enterprise Web Components
*/
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from '@modelcontextprotocol/sdk/types.js';
import { ConfigManager } from './config/index.js';
import { GitLabService } from './services/gitlab.js';
import { DataLoaderService } from './services/data-loader.js';
import { ToolHandlers } from './handlers/tool-handlers.js';
import { logger } from './utils/logger.js';
export class IDSEnterpriseWCMCPServer {
server;
config;
gitlabService;
dataLoader;
toolHandlers = null;
// Data storage
components = [];
documentation = [];
examples = [];
frameworks = [];
constructor() {
logger.separator('IDS ENTERPRISE WC MCP SERVER');
logger.setup('Initializing server...');
// Initialize configuration
const configManager = ConfigManager.getInstance();
this.config = configManager.getConfig();
logger.debug('✓ Configuration loaded');
// Initialize services
this.gitlabService = new GitLabService(this.config);
this.dataLoader = new DataLoaderService(this.config, this.gitlabService);
logger.debug('✓ Services initialized');
// Initialize MCP server
this.server = new Server({
name: 'ids-enterprise-mcp-server',
version: '1.0.0',
}, {
capabilities: {
tools: {},
},
});
logger.debug('✓ MCP server created');
// Set up tool handlers immediately
this.setupToolHandlers();
logger.debug('✓ Tool handlers configured');
// Load documentation asynchronously but don't wait for it
this.initializeDocumentation();
this.server.onerror = (error) => logger.error('MCP Server error:', error);
process.on('SIGINT', async () => {
logger.info('Shutting down server...');
await this.server.close();
process.exit(0);
});
}
/**
* Initialize documentation and data loading
*/
async initializeDocumentation() {
const startTime = Date.now();
try {
logger.separator('LOADING DOCUMENTATION & EXAMPLES');
await Promise.all([
this.loadDocumentationFromGitLab(),
this.loadExamplesFromGitLab()
]);
// Initialize tool handlers with loaded data
this.toolHandlers = new ToolHandlers(this.components, this.documentation, this.examples, this.frameworks);
const stats = {
'Components': this.components.length,
'Documentation Files': this.documentation.length,
'Examples': this.examples.length,
'Frameworks': this.frameworks.length
};
logger.table(stats);
logger.performance('Total initialization', startTime);
logger.setup('🚀 Server ready for requests!');
}
catch (error) {
logger.error('❌ Failed to load documentation from GitLab:', error);
// Initialize with empty data
this.toolHandlers = new ToolHandlers([], [], [], []);
}
}
/**
* Load documentation from GitLab
*/
async loadDocumentationFromGitLab() {
logger.setup('Loading documentation from GitLab API...');
try {
// Test GitLab connection first
await this.gitlabService.testConnection();
// Load components and documentation
await Promise.all([
this.loadComponents(),
this.loadGeneralDocumentation()
]);
}
catch (error) {
logger.error('❌ Failed to load from GitLab:', error);
throw error;
}
}
/**
* Load components
*/
async loadComponents() {
this.components = await this.dataLoader.loadComponents();
}
/**
* Load general documentation
*/
async loadGeneralDocumentation() {
this.documentation = await this.dataLoader.loadDocumentation();
}
/**
* Load examples from GitLab
*/
async loadExamplesFromGitLab() {
const { frameworks, examples } = await this.dataLoader.loadExamples();
this.frameworks = frameworks;
this.examples = examples;
}
/**
* Set up tool handlers for MCP requests
*/
setupToolHandlers() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
// === PROJECT DISCOVERY (Start Here) ===
{
name: 'get_project_overview',
description: 'Get an overview of the IDS Enterprise Web Components project - START HERE',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'list_all_categories',
description: 'List all available component categories with counts and descriptions',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'list_frameworks',
description: 'List all available framework integrations (React, Angular, etc.)',
inputSchema: {
type: 'object',
properties: {},
},
},
// === COMPONENT DISCOVERY ===
{
name: 'list_components_by_category',
description: 'List all components in a specific category',
inputSchema: {
type: 'object',
properties: {
category: {
type: 'string',
description: 'Category name (e.g., "Form Input Components", "Navigation and Interaction")',
},
},
required: ['category'],
},
},
{
name: 'search_components',
description: 'Search IDS Enterprise Web Components for specific components, features, or concepts',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Search query (e.g., "button", "data grid", "form validation")',
},
category: {
type: 'string',
description: 'Optional: Filter by category (Form Input Components, Navigation and Interaction, etc.)',
},
limit: {
type: 'number',
description: 'Maximum number of results to return (default: 5)',
default: 5,
},
},
required: ['query'],
},
},
{
name: 'get_component_details',
description: 'Get detailed information about a specific IDS component including features, attributes, methods, and events',
inputSchema: {
type: 'object',
properties: {
component: {
type: 'string',
description: 'Component name (e.g., "ids-button", "ids-data-grid")',
},
},
required: ['component'],
},
},
// === IMPLEMENTATION EXAMPLES ===
{
name: 'get_component_readme_examples',
description: 'Get basic code examples from component README documentation (main repository)',
inputSchema: {
type: 'object',
properties: {
component: {
type: 'string',
description: 'Component name (e.g., "ids-button", "ids-data-grid")',
},
},
required: ['component'],
},
},
{
name: 'get_component_framework_examples',
description: 'Get real implementation examples from framework-specific examples repository',
inputSchema: {
type: 'object',
properties: {
component: {
type: 'string',
description: 'Component name (e.g., "ids-button", "ids-data-grid")',
},
framework: {
type: 'string',
description: 'Required: Specific framework (React, Angular, etc.)',
},
},
required: ['component', 'framework'],
},
},
// === DEVELOPMENT RESOURCES ===
{
name: 'get_framework_guide',
description: 'Get setup guide and integration instructions for a specific framework',
inputSchema: {
type: 'object',
properties: {
framework: {
type: 'string',
description: 'Framework name (e.g., "React", "Angular", "Vue", "SvelteKit")',
},
},
required: ['framework'],
},
},
{
name: 'search_documentation',
description: 'Search general documentation including migration guides, testing guidelines, and best practices',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Search query for documentation (e.g., "migration", "testing", "accessibility")',
},
limit: {
type: 'number',
description: 'Maximum number of results to return (default: 3)',
default: 3,
},
},
required: ['query'],
},
},
{
name: 'get_development_guidelines',
description: 'Get development guidelines and best practices for specific topics',
inputSchema: {
type: 'object',
properties: {
topic: {
type: 'string',
description: 'Specific topic (e.g., "testing", "accessibility", "theming", "performance")',
},
},
},
},
],
}));
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
const { name, arguments: args } = request.params;
// Wait for tool handlers to be initialized
if (!this.toolHandlers) {
throw new McpError(ErrorCode.InternalError, 'Server is still initializing. Please try again in a moment.');
}
switch (name) {
// === PROJECT DISCOVERY ===
case 'get_project_overview':
return await this.toolHandlers.getProjectOverview();
case 'list_all_categories':
return await this.toolHandlers.listAllCategories();
case 'list_frameworks':
return await this.toolHandlers.listFrameworks();
// === COMPONENT DISCOVERY ===
case 'list_components_by_category':
return await this.toolHandlers.listComponentsByCategory(args || {});
case 'search_components':
return await this.toolHandlers.searchComponents(args || {});
case 'get_component_details':
return await this.toolHandlers.getComponentDetails(args || {});
// === IMPLEMENTATION EXAMPLES ===
case 'get_component_readme_examples':
return await this.toolHandlers.getComponentReadmeExamples(args || {});
case 'get_component_framework_examples':
return await this.toolHandlers.getComponentFrameworkExamples(args || {});
// === DEVELOPMENT RESOURCES ===
case 'get_framework_guide':
return await this.toolHandlers.getFrameworkGuide(args || {});
case 'search_documentation':
return await this.toolHandlers.searchDocumentation(args || {});
case 'get_development_guidelines':
return await this.toolHandlers.getDevelopmentGuidelines(args || {});
default:
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
}
}
catch (error) {
if (error instanceof McpError) {
throw error;
}
logger.error('Tool execution failed:', error);
throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${error}`);
}
});
}
/**
* Start the MCP server
*/
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
logger.info('🚀 IDS Enterprise Web Components MCP server running on stdio');
}
}
//# sourceMappingURL=server.js.map