- Create fiados module with 3 entities: - CustomerCreditAccount: Credit accounts per customer - Fiado: Individual credit sales (fiados) - FiadoPayment: Payment/abono tracking - Implement FiadosService with full business logic: - Credit eligibility checking - Fiado creation with automatic due dates - Payment registration with FIFO allocation - Overdue tracking and account freezing - Connect FiadosToolsService to real FiadosService - Update MCP module registration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
71 lines
2.5 KiB
TypeScript
71 lines
2.5 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,
|
|
SalesToolsService,
|
|
FinancialToolsService,
|
|
BranchToolsService,
|
|
} 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 (connected to real services)
|
|
this.toolRegistry.registerProvider(new ProductsToolsService(this.dataSource));
|
|
this.toolRegistry.registerProvider(new InventoryToolsService()); // TODO: Connect to PartService
|
|
this.toolRegistry.registerProvider(new OrdersToolsService()); // TODO: Connect to ServiceOrderService
|
|
this.toolRegistry.registerProvider(new CustomersToolsService()); // TODO: Connect to CustomersService
|
|
this.toolRegistry.registerProvider(new FiadosToolsService(this.dataSource));
|
|
this.toolRegistry.registerProvider(new SalesToolsService(this.dataSource));
|
|
this.toolRegistry.registerProvider(new FinancialToolsService(this.dataSource));
|
|
this.toolRegistry.registerProvider(new BranchToolsService());
|
|
|
|
// 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];
|
|
}
|
|
}
|