All files / src/entities/context registry.ts

100% Statements 12/12
0% Branches 0/1
100% Functions 4/4
100% Lines 12/12

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66            15x   15x 15x                             15x                   2x 1x                       15x 14x           15x 8x             15x 6x    
/**
 * Context tools registry
 *
 * Registers the manage_context CQRS tool with the tool registry system.
 */
 
import * as z from "zod";
import { ToolRegistry, EnhancedToolDefinition } from "../../types";
import { ManageContextSchema } from "./schema";
import { handleManageContext } from "./handlers";
 
/**
 * Context tools registry - 1 CQRS tool with 8 actions
 *
 * manage_context: Runtime context management
 *   - show: Display current context (Query)
 *   - list_presets: List available presets (Query)
 *   - list_profiles: List available profiles - OAuth only (Query)
 *   - whoami: Token introspection and capability discovery (Query)
 *   - switch_preset: Change active preset (Command)
 *   - switch_profile: Change active profile - OAuth only (Command)
 *   - set_scope: Set namespace scope with auto-detection (Command)
 *   - reset: Restore initial context (Command)
 */
export const contextToolRegistry: ToolRegistry = new Map<string, EnhancedToolDefinition>([
  [
    "manage_context",
    {
      name: "manage_context",
      description:
        "View and manage runtime session configuration. Actions: show (current host/preset/scope/mode), list_presets (available tool configurations), list_profiles (OAuth users), whoami (token introspection with live refresh - detects permission changes and updates available tools), switch_preset (change active preset), switch_profile (change OAuth user), set_scope (restrict to namespace), reset (restore initial state). Use whoami to diagnose access issues and verify token permissions.",
      inputSchema: z.toJSONSchema(ManageContextSchema),
      // No gate - context management is always available
      handler: async (args: unknown) => {
        const input = ManageContextSchema.parse(args);
        return handleManageContext(input);
      },
    },
  ],
]);
 
/**
 * Get read-only tool names from the registry
 * manage_context has both read and write actions, but we expose it in read-only mode
 * because the write actions (switch_preset, set_scope, reset) only affect the session,
 * not GitLab data.
 */
export function getContextReadOnlyToolNames(): string[] {
  return ["manage_context"];
}
 
/**
 * Get all tool definitions from the registry
 */
export function getContextToolDefinitions(): EnhancedToolDefinition[] {
  return Array.from(contextToolRegistry.values());
}
 
/**
 * Get filtered tools based on read-only mode
 * Context tools are always available since they don't modify GitLab data
 */
export function getFilteredContextTools(_readOnlyMode: boolean = false): EnhancedToolDefinition[] {
  return getContextToolDefinitions();
}