All files / src/seeding mcp-config-seeding.service.ts

45.45% Statements 10/22
0% Branches 0/2
25% Functions 1/4
42.1% Lines 8/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 376x 6x 6x 6x 6x     6x 6x       6x                                                
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { McpConfig } from '../core-entities';
import { defaultMcpConfigs } from './data/mcp-configs/default-configs';
 
@Injectable()
export class McpConfigSeedingService {
  private readonly logger = new Logger(McpConfigSeedingService.name);
 
  constructor(
    @InjectRepository(McpConfig)
    private readonly mcpConfigRepository: Repository<McpConfig>,
  ) {}
 
  async seed() {
    const existingConfigs = await this.mcpConfigRepository.find();
    const existingConfigNames = existingConfigs.map((c) => c.server_name);
 
    const configsToSeed = defaultMcpConfigs.filter(
      (c) => !existingConfigNames.includes(c.server_name),
    );
 
    if (configsToSeed.length > 0) {
      this.logger.log(`Seeding ${configsToSeed.length} new MCP configs...`);
      const newConfigs = this.mcpConfigRepository.create(configsToSeed);
      const savedConfigs = await this.mcpConfigRepository.save(newConfigs);
 
      for (const savedConfig of savedConfigs) {
        this.logger.log(`Seeded MCP config: ${savedConfig.server_name}`);
      }
    } else {
      this.logger.log('MCP configs are up to date. No seeding required.');
    }
  }
}