erp-core-backend-v2/src/modules/mcp/mcp.module.ts
rckrdmrd ca07b4268d feat: Add complete module structure for ERP backend
- Add modules: ai, audit, billing-usage, biometrics, branches, dashboard,
  feature-flags, invoices, mcp, mobile, notifications, partners,
  payment-terminals, products, profiles, purchases, reports, sales,
  storage, warehouses, webhooks, whatsapp
- Add controllers, DTOs, entities, and services for each module
- Add shared services and utilities

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 00:40:54 -06:00

65 lines
2.0 KiB
TypeScript

import { Router } from 'express';
import { DataSource } from 'typeorm';
import { McpServerService, ToolRegistryService, ToolLoggerService } from './services';
import { McpController } from './controllers';
import { ToolCall, ToolCallResult } from './entities';
import {
ProductsToolsService,
InventoryToolsService,
OrdersToolsService,
CustomersToolsService,
FiadosToolsService,
} from './tools';
export interface McpModuleOptions {
dataSource: DataSource;
basePath?: string;
}
export class McpModule {
public router: Router;
public mcpService: McpServerService;
public toolRegistry: ToolRegistryService;
private dataSource: DataSource;
private basePath: string;
constructor(options: McpModuleOptions) {
this.dataSource = options.dataSource;
this.basePath = options.basePath || '';
this.router = Router();
this.initializeServices();
this.initializeRoutes();
}
private initializeServices(): void {
// Repositories
const toolCallRepository = this.dataSource.getRepository(ToolCall);
const toolCallResultRepository = this.dataSource.getRepository(ToolCallResult);
// Tool Logger
const toolLogger = new ToolLoggerService(toolCallRepository, toolCallResultRepository);
// Tool Registry
this.toolRegistry = new ToolRegistryService();
// Register tool providers
this.toolRegistry.registerProvider(new ProductsToolsService());
this.toolRegistry.registerProvider(new InventoryToolsService());
this.toolRegistry.registerProvider(new OrdersToolsService());
this.toolRegistry.registerProvider(new CustomersToolsService());
this.toolRegistry.registerProvider(new FiadosToolsService());
// MCP Server Service
this.mcpService = new McpServerService(this.toolRegistry, toolLogger);
}
private initializeRoutes(): void {
const mcpController = new McpController(this.mcpService);
this.router.use(`${this.basePath}/mcp`, mcpController.router);
}
static getEntities(): Function[] {
return [ToolCall, ToolCallResult];
}
}