UNPKG

mcp-quiz-server

Version:

🧠 AI-Powered Quiz Management via Model Context Protocol (MCP) - Create, manage, and take quizzes directly from VS Code, Claude, and other AI agents.

169 lines (168 loc) • 8.61 kB
"use strict"; /** * @fileoverview Service Registry - Configure all services for Clean Architecture * @version 1.0.0 * @since 2025-07-29 * @module ServiceRegistry * @description Central service configuration for dependency injection */ Object.defineProperty(exports, "__esModule", { value: true }); exports.McpToolFactory = exports.ServiceTokens = void 0; exports.configureServices = configureServices; exports.createContainer = createContainer; const DIContainer_1 = require("./DIContainer"); // Domain Services const QuizScoringService_1 = require("../../domain/services/QuizScoringService"); const QuizValidationService_1 = require("../../domain/services/QuizValidationService"); // Application Handlers const CreateQuizCommandHandler_1 = require("../../application/commands/CreateQuizCommandHandler"); const DeleteQuizCommandHandler_1 = require("../../application/commands/DeleteQuizCommandHandler"); const GetQuizQueryHandler_1 = require("../../application/queries/GetQuizQueryHandler"); const ListQuizzesQueryHandler_1 = require("../../application/queries/ListQuizzesQueryHandler"); // MCP Tools - Standard tools only (enhanced tools removed) const create_quiz_1 = require("../../mcp/tools/quiz/create-quiz"); const delete_quiz_1 = require("../../mcp/tools/quiz/delete-quiz"); const get_quiz_1 = require("../../mcp/tools/quiz/get-quiz"); const list_quizzes_1 = require("../../mcp/tools/quiz/list-quizzes"); // Infrastructure Services const TypeORMQuizRepository_1 = require("../repositories/TypeORMQuizRepository"); // DISABLED: Over-engineered repository // import { TypeORMQuestionRepository } from '../repositories/TypeORMQuestionRepository'; const InMemoryEventBus_1 = require("../events/InMemoryEventBus"); const ConsoleNotificationService_1 = require("../services/ConsoleNotificationService"); const InMemoryCache_1 = require("../services/InMemoryCache"); const SimplePermissionService_1 = require("../services/SimplePermissionService"); // Dashboard Services (MVVM) - DISABLED for now due to compilation issues // import { DashboardViewModelFactory } from '../http/viewmodels/DashboardViewModels'; /** * Service Tokens - Type-safe service identifiers */ exports.ServiceTokens = { // Infrastructure DataSource: 'DataSource', EventBus: 'EventBus', CacheService: 'CacheService', NotificationService: 'NotificationService', PermissionService: 'PermissionService', // Repositories QuizRepository: 'QuizRepository', // Domain Services QuizScoringService: 'QuizScoringService', QuizValidationService: 'QuizValidationService', // Application Handlers CreateQuizCommandHandler: 'CreateQuizCommandHandler', DeleteQuizCommandHandler: 'DeleteQuizCommandHandler', GetQuizQueryHandler: 'GetQuizQueryHandler', ListQuizzesQueryHandler: 'ListQuizzesQueryHandler', // MCP Tools - Enhanced // Enhanced tools removed - using standard tools // MCP Tools - Legacy CreateQuizTool: 'CreateQuizTool', GetQuizTool: 'GetQuizTool', ListQuizzesTool: 'ListQuizzesTool', DeleteQuizTool: 'DeleteQuizTool', // MCP Tool Factory McpToolFactory: 'McpToolFactory', // Dashboard Services (MVVM Architecture) DashboardService: 'DashboardService', DashboardViewModelFactory: 'DashboardViewModelFactory', }; /** * Configure all services in the DI container */ function configureServices(container, dataSource) { // Infrastructure Services (Singletons) container.registerInstance(exports.ServiceTokens.DataSource, dataSource); container.registerSingleton(exports.ServiceTokens.EventBus, () => new InMemoryEventBus_1.InMemoryEventBus()); container.registerSingleton(exports.ServiceTokens.CacheService, () => new InMemoryCache_1.InMemoryCache({ defaultTTL: 3600, maxKeys: 1000 })); container.registerSingleton(exports.ServiceTokens.NotificationService, () => new ConsoleNotificationService_1.ConsoleNotificationService()); container.registerSingleton(exports.ServiceTokens.PermissionService, () => new SimplePermissionService_1.SimplePermissionService({ defaultPermissions: ['quiz:read', 'quiz:create'] })); // Repositories (Singletons) container.registerSingleton(exports.ServiceTokens.QuizRepository, c => new TypeORMQuizRepository_1.TypeORMQuizRepository(c.resolve(exports.ServiceTokens.DataSource))); // Domain Services (Transient) container.register(exports.ServiceTokens.QuizScoringService, () => new QuizScoringService_1.QuizScoringService()); container.register(exports.ServiceTokens.QuizValidationService, () => new QuizValidationService_1.QuizValidationService()); // Application Handlers (Transient) container.register(exports.ServiceTokens.CreateQuizCommandHandler, c => new CreateQuizCommandHandler_1.CreateQuizCommandHandler(c.resolve(exports.ServiceTokens.QuizRepository), c.resolve(exports.ServiceTokens.QuizValidationService), c.resolve(exports.ServiceTokens.EventBus)), 'transient'); container.register(exports.ServiceTokens.GetQuizQueryHandler, c => new GetQuizQueryHandler_1.GetQuizQueryHandler(c.resolve(exports.ServiceTokens.QuizRepository), c.resolve(exports.ServiceTokens.PermissionService), c.resolve(exports.ServiceTokens.CacheService)), 'transient'); container.register(exports.ServiceTokens.DeleteQuizCommandHandler, c => new DeleteQuizCommandHandler_1.DeleteQuizCommandHandler({ quizRepository: c.resolve(exports.ServiceTokens.QuizRepository), eventBus: c.resolve(exports.ServiceTokens.EventBus), cacheService: c.resolve(exports.ServiceTokens.CacheService), }), 'transient'); container.register(exports.ServiceTokens.ListQuizzesQueryHandler, c => new ListQuizzesQueryHandler_1.ListQuizzesQueryHandler({ quizRepository: c.resolve(exports.ServiceTokens.QuizRepository), permissionService: c.resolve(exports.ServiceTokens.PermissionService), cacheService: c.resolve(exports.ServiceTokens.CacheService), }), 'transient'); // Enhanced tools removed - using standard tools only // MCP Tools - Legacy (backward compatibility) container.register(exports.ServiceTokens.CreateQuizTool, () => new create_quiz_1.CreateQuizTool(), 'transient'); container.register(exports.ServiceTokens.GetQuizTool, () => new get_quiz_1.GetQuizTool(), 'transient'); container.register(exports.ServiceTokens.ListQuizzesTool, () => new list_quizzes_1.ListQuizzesTool(), 'transient'); container.register(exports.ServiceTokens.DeleteQuizTool, () => new delete_quiz_1.DeleteQuizTool(), 'transient'); // MCP Tool Factory for seamless tool selection container.registerSingleton(exports.ServiceTokens.McpToolFactory, c => new McpToolFactory(c)); // Dashboard Services (MVVM Architecture) - DISABLED for now // container.registerSingleton( // ServiceTokens.DashboardViewModelFactory, // () => DashboardViewModelFactory // ); } /** * MCP Tool Factory - Smart tool selection between enhanced and legacy */ class McpToolFactory { constructor(container) { this.container = container; } /** * Get the best available tool (enhanced if Clean Architecture is working, legacy otherwise) */ getCreateQuizTool() { // Enhanced tool removed - using standard tool only return this.container.resolve(exports.ServiceTokens.CreateQuizTool); } getGetQuizTool() { return this.container.resolve(exports.ServiceTokens.GetQuizTool); } getListQuizzesTool() { return this.container.resolve(exports.ServiceTokens.ListQuizzesTool); } getDeleteQuizTool() { return this.container.resolve(exports.ServiceTokens.DeleteQuizTool); } /** * Get all available tools with enhanced preference */ getAllTools() { return { create_quiz: this.getCreateQuizTool(), get_quiz: this.getGetQuizTool(), list_quizzes: this.getListQuizzesTool(), delete_quiz: this.getDeleteQuizTool(), }; } /** * Check if enhanced tools are available */ hasEnhancedTools() { try { this.container.resolve(exports.ServiceTokens.CreateQuizCommandHandler); this.container.resolve(exports.ServiceTokens.GetQuizQueryHandler); return true; } catch (_a) { return false; } } } exports.McpToolFactory = McpToolFactory; /** * Create and configure a new DI container */ function createContainer(dataSource) { const container = new DIContainer_1.DIContainer(); configureServices(container, dataSource); return container; }