Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.1 KB
Raw Blame
import { McpRegistryService } from './mcp-registry.service';
import { MCP_MODULE_OPTIONS, MCP_TOOL_GATE, type McpModuleOptions } from './types';
import { Module, type DynamicModule } from '@nestjs/common';
import { DiscoveryModule } from '@nestjs/core';

@Module({})
export class McpModule {
  /**
   * Registers the discovery-backed `McpRegistryService` globally. The
   * `accessPolicy` resolves every declarative `access: { group, mode }`
   * marker — the package itself defines no scope semantics. `toolGate` is
   * built from the container, so the gate can inject what it needs.
   */
  static forRoot(options: McpModuleOptions = {}): DynamicModule {
    const gate = options.toolGate;
    return {
      module: McpModule,
      global: true,
      imports: [DiscoveryModule, ...(gate?.imports ?? [])],
      providers: [
        { provide: MCP_MODULE_OPTIONS, useValue: options },
        gate
          ? { provide: MCP_TOOL_GATE, useFactory: gate.useFactory, inject: gate.inject ?? [] }
          : { provide: MCP_TOOL_GATE, useValue: null },
        McpRegistryService,
      ],
      exports: [McpRegistryService],
    };
  }
}