mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
1a9855cf70
Every write tool used to open with its own demo check, 196 copies across 30 tool files, most of them injecting AuthService for nothing else. The registry now takes a toolGate (built from the container) that runs before each registered tool handler, and TREK's gate refuses a demo account on every tool not annotated read-only with the same canned result. The per-tool checks, the AuthService injections, AuthService.isDemoUser and the AuthModule imports that only fed them are gone; ESLint refuses a demo check in a tool file, and a registry-wide test calls every write tool as the demo account.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
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],
|
|
};
|
|
}
|
|
}
|