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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 85x 85x 85x 85x 85x 85x 85x 85x 85x 90x 85x 90x 85x 85x 85x 82x 85x 84x 85x 84x 85x 84x 85x 84x 85x 84x 85x 84x 85x 83x 85x 48x 85x 48x 85x 48x 85x 5x 85x 5x 85x 5x 85x 5x 85x 85x 85x 85x 6x 6x 8x 10x 10x 10x 10x 8x 10x 9x 10x 9x 10x 9x 10x 9x 10x 9x 10x 9x 10x 9x 10x 5x 10x 5x 10x 5x 10x 10x 10x 10x 10x 10x 10x 354x 354x 87x 87x 87x 86x 87x 87x 31x 2x 87x 1113x 2423x 127x 127x 2296x 11x 11x 2285x 55x 55x 2230x 5x 5x 5x 2225x 2225x 2225x 2225x 2225x 2194x 2194x 1x 2225x 2225x 2225x 7x 2225x 87x 83x 83x 2115x 2109x 2109x 99x 4x 110x 109x 109x 78x 87x 2x 2x 2x 2x 22x 3x 3x 1x 2x 2x 11x 8x 8x 169x 11x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 119x 262x 54x 208x 2x 206x 206x 206x 206x 206x 206x 8x 8x 171x 7x 171x 171x 171x 171x 28x 1x 35x 35x 35x 35x 26x 8x 2x 2x 2x 36x 78x 2x 4x 16x 16x 6x 6x 66x 6x 6x 6x 6x 6x 6x 6x 6x 3x 1x 6x 66x 156x 99x 57x 28x 28x 29x 2x 2x 27x 25x 25x 2x 2x 2x 6x 15x | import { ToolRegistry, EnhancedToolDefinition, ToolDefinition } from "./types";
import { coreToolRegistry, getCoreReadOnlyToolNames } from "./entities/core/registry";
import { labelsToolRegistry, getLabelsReadOnlyToolNames } from "./entities/labels/registry";
import { mrsToolRegistry, getMrsReadOnlyToolNames } from "./entities/mrs/registry";
import { filesToolRegistry, getFilesReadOnlyToolNames } from "./entities/files/registry";
import {
milestonesToolRegistry,
getMilestonesReadOnlyToolNames,
} from "./entities/milestones/registry";
import {
pipelinesToolRegistry,
getPipelinesReadOnlyToolNames,
} from "./entities/pipelines/registry";
import {
variablesToolRegistry,
getVariablesReadOnlyToolNames,
} from "./entities/variables/registry";
import { wikiToolRegistry, getWikiReadOnlyToolNames } from "./entities/wiki/registry";
import {
workitemsToolRegistry,
getWorkitemsReadOnlyToolNames,
} from "./entities/workitems/registry";
import { webhooksToolRegistry, getWebhooksReadOnlyToolNames } from "./entities/webhooks/registry";
import { snippetsToolRegistry, getSnippetsReadOnlyToolNames } from "./entities/snippets/registry";
import {
integrationsToolRegistry,
getIntegrationsReadOnlyToolNames,
} from "./entities/integrations/registry";
import { releasesToolRegistry, getReleasesReadOnlyToolNames } from "./entities/releases/registry";
import { refsToolRegistry, getRefsReadOnlyToolNames } from "./entities/refs/registry";
import { membersToolRegistry, getMembersReadOnlyToolNames } from "./entities/members/registry";
import { searchToolRegistry, getSearchReadOnlyToolNames } from "./entities/search/registry";
import { contextToolRegistry, getContextReadOnlyToolNames } from "./entities/context/registry";
import {
iterationsToolRegistry,
getIterationsReadOnlyToolNames,
} from "./entities/iterations/registry";
import {
GITLAB_READ_ONLY_MODE,
GITLAB_DENIED_TOOLS_REGEX,
GITLAB_CROSS_REFS,
USE_GITLAB_WIKI,
USE_MILESTONE,
USE_PIPELINE,
USE_WORKITEMS,
USE_LABELS,
USE_MRS,
USE_FILES,
USE_VARIABLES,
USE_SNIPPETS,
USE_WEBHOOKS,
USE_INTEGRATIONS,
USE_RELEASES,
USE_REFS,
USE_MEMBERS,
USE_SEARCH,
USE_ITERATIONS,
getToolDescriptionOverrides,
} from "./config";
import { ToolAvailability } from "./services/ToolAvailability";
import { ConnectionManager } from "./services/ConnectionManager";
import { isToolAvailableForScopes } from "./services/TokenScopeDetector";
import type { GitLabScope } from "./services/TokenScopeDetector";
import type { GitLabTier } from "./services/GitLabVersionDetector";
import { logDebug } from "./logger";
import {
transformToolSchema,
stripTierRestrictedParameters,
shouldRemoveTool,
extractActionsFromSchema,
} from "./utils/schema-utils";
import { resolveRelatedReferences, stripRelatedSection } from "./utils/description-utils";
/**
* Central registry manager that aggregates tools from all entity registries
* and provides a unified interface for tool discovery and execution
*/
class RegistryManager {
private static instance: RegistryManager;
private registries: Map<string, ToolRegistry> = new Map();
// Performance optimization caches
private toolLookupCache: Map<string, EnhancedToolDefinition> = new Map();
private toolDefinitionsCache: ToolDefinition[] | null = null;
private toolNamesCache: string[] | null = null;
// Tool description overrides from environment variables
private descriptionOverrides: Map<string, string> = new Map();
// Cached read-only tools list built from registries
private readOnlyToolsCache: string[] | null = null;
private constructor() {
this.initializeRegistries();
this.loadDescriptionOverrides();
this.buildToolLookupCache();
}
public static getInstance(): RegistryManager {
if (!RegistryManager.instance) {
RegistryManager.instance = new RegistryManager();
}
return RegistryManager.instance;
}
/**
* Initialize all entity registries based on configuration
*/
private initializeRegistries(): void {
// Always add core tools
this.registries.set("core", coreToolRegistry);
// Always add context tools (runtime context management)
this.registries.set("context", contextToolRegistry);
// Add tools based on feature flags
if (USE_LABELS) {
this.registries.set("labels", labelsToolRegistry);
}
if (USE_MRS) {
this.registries.set("mrs", mrsToolRegistry);
}
if (USE_FILES) {
this.registries.set("files", filesToolRegistry);
}
if (USE_MILESTONE) {
this.registries.set("milestones", milestonesToolRegistry);
}
if (USE_PIPELINE) {
this.registries.set("pipelines", pipelinesToolRegistry);
}
if (USE_VARIABLES) {
this.registries.set("variables", variablesToolRegistry);
}
if (USE_GITLAB_WIKI) {
this.registries.set("wiki", wikiToolRegistry);
}
if (USE_WORKITEMS) {
this.registries.set("workitems", workitemsToolRegistry);
}
if (USE_SNIPPETS) {
this.registries.set("snippets", snippetsToolRegistry);
}
if (USE_WEBHOOKS) {
this.registries.set("webhooks", webhooksToolRegistry);
}
if (USE_INTEGRATIONS) {
this.registries.set("integrations", integrationsToolRegistry);
}
if (USE_RELEASES) {
this.registries.set("releases", releasesToolRegistry);
}
if (USE_REFS) {
this.registries.set("refs", refsToolRegistry);
}
if (USE_MEMBERS) {
this.registries.set("members", membersToolRegistry);
}
if (USE_SEARCH) {
this.registries.set("search", searchToolRegistry);
}
Eif (USE_ITERATIONS) {
this.registries.set("iterations", iterationsToolRegistry);
}
// All entity registries have been migrated to the new pattern!
}
/**
* Load tool description overrides from environment variables
*/
private loadDescriptionOverrides(): void {
this.descriptionOverrides = getToolDescriptionOverrides();
if (this.descriptionOverrides.size > 0) {
logDebug("Loaded tool description overrides", { count: this.descriptionOverrides.size });
for (const [toolName, description] of this.descriptionOverrides) {
logDebug("Tool description override", { toolName, description });
}
}
}
/**
* Build read-only tools list from registries based on configuration
*/
private buildReadOnlyToolsList(): string[] {
const readOnlyTools: string[] = [];
// Always add core read-only tools
readOnlyTools.push(...getCoreReadOnlyToolNames());
// Always add context read-only tools
readOnlyTools.push(...getContextReadOnlyToolNames());
// Add read-only tools from enabled entities
if (USE_LABELS) {
readOnlyTools.push(...getLabelsReadOnlyToolNames());
}
if (USE_MRS) {
readOnlyTools.push(...getMrsReadOnlyToolNames());
}
if (USE_FILES) {
readOnlyTools.push(...getFilesReadOnlyToolNames());
}
if (USE_GITLAB_WIKI) {
readOnlyTools.push(...getWikiReadOnlyToolNames());
}
if (USE_MILESTONE) {
readOnlyTools.push(...getMilestonesReadOnlyToolNames());
}
if (USE_PIPELINE) {
readOnlyTools.push(...getPipelinesReadOnlyToolNames());
}
if (USE_WORKITEMS) {
readOnlyTools.push(...getWorkitemsReadOnlyToolNames());
}
if (USE_VARIABLES) {
readOnlyTools.push(...getVariablesReadOnlyToolNames());
}
if (USE_SNIPPETS) {
readOnlyTools.push(...getSnippetsReadOnlyToolNames());
}
if (USE_WEBHOOKS) {
readOnlyTools.push(...getWebhooksReadOnlyToolNames());
}
if (USE_INTEGRATIONS) {
readOnlyTools.push(...getIntegrationsReadOnlyToolNames());
}
Iif (USE_RELEASES) {
readOnlyTools.push(...getReleasesReadOnlyToolNames());
}
Iif (USE_REFS) {
readOnlyTools.push(...getRefsReadOnlyToolNames());
}
Iif (USE_MEMBERS) {
readOnlyTools.push(...getMembersReadOnlyToolNames());
}
Iif (USE_SEARCH) {
readOnlyTools.push(...getSearchReadOnlyToolNames());
}
Eif (USE_ITERATIONS) {
readOnlyTools.push(...getIterationsReadOnlyToolNames());
}
return readOnlyTools;
}
/**
* Get read-only tools list (cached for performance)
*/
private getReadOnlyTools(): string[] {
this.readOnlyToolsCache ??= this.buildReadOnlyToolsList();
return this.readOnlyToolsCache;
}
/**
* Build unified tool lookup cache for O(1) tool access with filtering applied
*/
private buildToolLookupCache(): void {
this.toolLookupCache.clear();
// Pre-fetch instance info once per cache build to avoid redundant calls
let instanceInfo: { tier: GitLabTier; version: string } | undefined;
try {
const info = ConnectionManager.getInstance().getInstanceInfo();
instanceInfo = { tier: info.tier, version: info.version };
} catch {
// Connection not initialized - parameter restrictions won't apply
}
// Pre-fetch token scope info for scope-based filtering
let tokenScopes: GitLabScope[] | undefined;
try {
const scopeInfo = ConnectionManager.getInstance().getTokenScopeInfo();
if (scopeInfo) {
tokenScopes = scopeInfo.scopes;
}
} catch {
// Connection not initialized - scope filtering won't apply
}
for (const registry of this.registries.values()) {
for (const [toolName, tool] of registry) {
// Apply GITLAB_READ_ONLY_MODE filtering at registry level
if (GITLAB_READ_ONLY_MODE && !this.getReadOnlyTools().includes(toolName)) {
logDebug("Tool filtered out: read-only mode", { toolName });
continue;
}
// Apply GITLAB_DENIED_TOOLS_REGEX filtering at registry level
if (GITLAB_DENIED_TOOLS_REGEX?.test(toolName)) {
logDebug("Tool filtered out: matches denied regex", { toolName });
continue;
}
// Apply token scope filtering - skip tools the token can't access
if (tokenScopes && !isToolAvailableForScopes(toolName, tokenScopes)) {
logDebug("Tool filtered out: insufficient token scopes", { toolName });
continue;
}
// Apply GitLab version/tier filtering at registry level
if (!ToolAvailability.isToolAvailable(toolName)) {
const reason = ToolAvailability.getUnavailableReason(toolName);
logDebug("Tool filtered out", { toolName, reason });
continue;
}
// Check if all actions are denied for this CQRS tool
const allActions = extractActionsFromSchema(tool.inputSchema);
Iif (allActions.length > 0 && shouldRemoveTool(toolName, allActions)) {
logDebug("Tool filtered out: all actions denied", { toolName });
continue;
}
// Tool passes all filters - apply schema transformation and description override
let finalTool = tool;
// Transform schema to remove denied actions and apply description overrides
let transformedSchema = transformToolSchema(toolName, tool.inputSchema);
// Strip tier-restricted parameters from schema (skip if connection not initialized)
if (instanceInfo) {
const restrictedParams = ToolAvailability.getRestrictedParameters(toolName, instanceInfo);
if (restrictedParams.length > 0) {
transformedSchema = stripTierRestrictedParameters(transformedSchema, restrictedParams);
}
}
// Apply tool-level description override if available
const customDescription = this.descriptionOverrides.get(toolName);
finalTool = {
...tool,
inputSchema: transformedSchema,
...(customDescription && { description: customDescription }),
};
if (customDescription) {
logDebug("Applied description override", { toolName, customDescription });
}
// Add to cache
this.toolLookupCache.set(toolName, finalTool);
}
}
// Second pass: handle Related references based on GITLAB_CROSS_REFS setting
if (GITLAB_CROSS_REFS) {
// Resolve Related references against available tools
const availableToolNames = new Set(this.toolLookupCache.keys());
for (const [toolName, tool] of this.toolLookupCache) {
// Skip tools with custom description overrides (user controls entire description)
if (this.descriptionOverrides.has(toolName)) continue;
const resolved = resolveRelatedReferences(tool.description, availableToolNames);
if (resolved !== tool.description) {
this.toolLookupCache.set(toolName, { ...tool, description: resolved });
}
}
} else {
// Cross-refs disabled: strip all "Related:" sections entirely
for (const [toolName, tool] of this.toolLookupCache) {
if (this.descriptionOverrides.has(toolName)) continue;
const stripped = stripRelatedSection(tool.description);
if (stripped !== tool.description) {
this.toolLookupCache.set(toolName, { ...tool, description: stripped });
}
}
}
logDebug("Registry manager built cache after filtering", {
toolCount: this.toolLookupCache.size,
});
}
/**
* Invalidate all caches - call when registries change
*/
private invalidateCaches(): void {
this.toolDefinitionsCache = null;
this.toolNamesCache = null;
this.readOnlyToolsCache = null;
this.buildToolLookupCache();
}
/**
* Get a tool by name from any registry - O(1) lookup using cache
*/
public getTool(toolName: string): EnhancedToolDefinition | null {
return this.toolLookupCache.get(toolName) ?? null;
}
/**
* Execute a tool by name
*/
public async executeTool(toolName: string, args: unknown): Promise<unknown> {
const tool = this.getTool(toolName);
if (!tool) {
throw new Error(`Tool '${toolName}' not found in any registry`);
}
return await tool.handler(args);
}
/**
* Clear all caches and rebuild (e.g., after ConnectionManager init provides tier/version)
*/
public refreshCache(): void {
this.invalidateCaches();
}
/**
* Get all tool definitions (for backward compatibility with tools.ts) - cached for performance
*/
public getAllToolDefinitions(): ToolDefinition[] {
if (this.toolDefinitionsCache === null) {
// Build cache
this.toolDefinitionsCache = [];
for (const tool of this.toolLookupCache.values()) {
this.toolDefinitionsCache.push({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema,
});
}
}
return this.toolDefinitionsCache;
}
/**
* Get tool definitions without GitLab tier/version filtering (for CLI tools, documentation, etc.)
* Dynamically checks environment filters at runtime to respect CLI-time environment variables
* but bypasses ToolAvailability tier/version checks since no GitLab connection exists
*/
public getAllToolDefinitionsTierless(): EnhancedToolDefinition[] {
const allTools: EnhancedToolDefinition[] = [];
// Dynamically check environment variables at runtime
const isReadOnly = process.env.GITLAB_READ_ONLY_MODE === "true";
const deniedRegex = process.env.GITLAB_DENIED_TOOLS_REGEX
? new RegExp(process.env.GITLAB_DENIED_TOOLS_REGEX)
: undefined;
// Dynamically check USE_* flags at runtime
const useLabels = process.env.USE_LABELS !== "false";
const useMrs = process.env.USE_MRS !== "false";
const useFiles = process.env.USE_FILES !== "false";
const useMilestone = process.env.USE_MILESTONE !== "false";
const usePipeline = process.env.USE_PIPELINE !== "false";
const useVariables = process.env.USE_VARIABLES !== "false";
const useWiki = process.env.USE_GITLAB_WIKI !== "false";
const useWorkitems = process.env.USE_WORKITEMS !== "false";
const useSnippets = process.env.USE_SNIPPETS !== "false";
const useWebhooks = process.env.USE_WEBHOOKS !== "false";
const useIntegrations = process.env.USE_INTEGRATIONS !== "false";
const useReleases = process.env.USE_RELEASES !== "false";
const useRefs = process.env.USE_REFS !== "false";
const useMembers = process.env.USE_MEMBERS !== "false";
const useSearch = process.env.USE_SEARCH !== "false";
const useIterations = process.env.USE_ITERATIONS !== "false";
// Build registries map based on dynamic feature flags
const registriesToUse = new Map<string, ToolRegistry>();
// Always add core tools
registriesToUse.set("core", coreToolRegistry);
// Always add context tools
registriesToUse.set("context", contextToolRegistry);
// Add tools based on dynamically checked feature flags
if (useLabels) registriesToUse.set("labels", labelsToolRegistry);
if (useMrs) registriesToUse.set("mrs", mrsToolRegistry);
if (useFiles) registriesToUse.set("files", filesToolRegistry);
if (useMilestone) registriesToUse.set("milestones", milestonesToolRegistry);
if (usePipeline) registriesToUse.set("pipelines", pipelinesToolRegistry);
if (useVariables) registriesToUse.set("variables", variablesToolRegistry);
if (useWiki) registriesToUse.set("wiki", wikiToolRegistry);
if (useWorkitems) registriesToUse.set("workitems", workitemsToolRegistry);
if (useSnippets) registriesToUse.set("snippets", snippetsToolRegistry);
if (useWebhooks) registriesToUse.set("webhooks", webhooksToolRegistry);
if (useIntegrations) registriesToUse.set("integrations", integrationsToolRegistry);
Eif (useReleases) registriesToUse.set("releases", releasesToolRegistry);
Eif (useRefs) registriesToUse.set("refs", refsToolRegistry);
Eif (useMembers) registriesToUse.set("members", membersToolRegistry);
Eif (useSearch) registriesToUse.set("search", searchToolRegistry);
Eif (useIterations) registriesToUse.set("iterations", iterationsToolRegistry);
// Dynamically load description overrides
const descOverrides = getToolDescriptionOverrides();
for (const registry of registriesToUse.values()) {
for (const [toolName, tool] of registry) {
// Apply dynamically checked GITLAB_READ_ONLY_MODE filtering
if (isReadOnly && !this.getReadOnlyTools().includes(toolName)) {
continue;
}
// Apply dynamically checked GITLAB_DENIED_TOOLS_REGEX filtering
if (deniedRegex?.test(toolName)) {
continue;
}
// Check if all actions are denied for this CQRS tool
const allActions = extractActionsFromSchema(tool.inputSchema);
Iif (allActions.length > 0 && shouldRemoveTool(toolName, allActions)) {
continue;
}
// Transform schema to remove denied actions and apply description overrides
const transformedSchema = transformToolSchema(toolName, tool.inputSchema);
// Apply dynamically loaded description override if available
const customDescription = descOverrides.get(toolName);
const finalTool: EnhancedToolDefinition = {
...tool,
inputSchema: transformedSchema,
...(customDescription && { description: customDescription }),
};
allTools.push(finalTool);
}
}
// Second pass: handle Related references based on GITLAB_CROSS_REFS setting
const crossRefsEnabled = process.env.GITLAB_CROSS_REFS !== "false";
if (crossRefsEnabled) {
// Resolve Related references against available tools
const availableToolNames = new Set(allTools.map(t => t.name));
for (let i = 0; i < allTools.length; i++) {
const tool = allTools[i];
// Skip tools with custom description overrides
Iif (descOverrides.has(tool.name)) continue;
const resolved = resolveRelatedReferences(tool.description, availableToolNames);
if (resolved !== tool.description) {
allTools[i] = { ...tool, description: resolved };
}
}
} else {
// Cross-refs disabled: strip all "Related:" sections entirely
for (let i = 0; i < allTools.length; i++) {
const tool = allTools[i];
Iif (descOverrides.has(tool.name)) continue;
const stripped = stripRelatedSection(tool.description);
if (stripped !== tool.description) {
allTools[i] = { ...tool, description: stripped };
}
}
}
return allTools;
}
/**
* Returns ALL tool definitions without any filtering or transformation.
* Used for documentation generation (--export) where we need:
* - Complete tool catalog regardless of environment configuration
* - Original discriminated union schemas for rich action descriptions
*/
public getAllToolDefinitionsUnfiltered(): EnhancedToolDefinition[] {
const allTools: EnhancedToolDefinition[] = [];
// All registries without any filtering
const allRegistries: ToolRegistry[] = [
coreToolRegistry,
contextToolRegistry,
labelsToolRegistry,
mrsToolRegistry,
filesToolRegistry,
milestonesToolRegistry,
pipelinesToolRegistry,
variablesToolRegistry,
wikiToolRegistry,
workitemsToolRegistry,
snippetsToolRegistry,
webhooksToolRegistry,
integrationsToolRegistry,
releasesToolRegistry,
refsToolRegistry,
membersToolRegistry,
searchToolRegistry,
iterationsToolRegistry,
];
for (const registry of allRegistries) {
for (const [, tool] of registry) {
// Return original schema without transformation
// This preserves discriminated union structure for documentation
allTools.push(tool);
}
}
return allTools;
}
/**
* Check if a tool exists in any registry - O(1) lookup using cache
*/
public hasToolHandler(toolName: string): boolean {
return this.toolLookupCache.has(toolName);
}
/**
* Get all available tool names - cached for performance
*/
public getAvailableToolNames(): string[] {
this.toolNamesCache ??= Array.from(this.toolLookupCache.keys());
return this.toolNamesCache;
}
/**
* Get filter statistics showing how tools were filtered
* Used by whoami action to explain tool availability
*/
public getFilterStats(): FilterStats {
// Count total tools across all registries
let totalTools = 0;
for (const registry of this.registries.values()) {
totalTools += registry.size;
}
const availableTools = this.toolLookupCache.size;
// Calculate filtered counts by re-running filter logic
let filteredByReadOnly = 0;
let filteredByDeniedRegex = 0;
let filteredByScopes = 0;
let filteredByTier = 0;
let filteredByActionDenial = 0;
// Get token scopes for scope filtering check
let tokenScopes: GitLabScope[] | undefined;
try {
const scopeInfo = ConnectionManager.getInstance().getTokenScopeInfo();
if (scopeInfo) {
tokenScopes = scopeInfo.scopes;
}
} catch {
// Connection not initialized
}
for (const registry of this.registries.values()) {
for (const [toolName, tool] of registry) {
// Check if already in cache (passed all filters)
if (this.toolLookupCache.has(toolName)) {
continue;
}
// Tool was filtered - determine why (in same order as buildToolLookupCache)
if (GITLAB_READ_ONLY_MODE && !this.getReadOnlyTools().includes(toolName)) {
filteredByReadOnly++;
continue;
}
if (GITLAB_DENIED_TOOLS_REGEX?.test(toolName)) {
filteredByDeniedRegex++;
continue;
}
if (tokenScopes && !isToolAvailableForScopes(toolName, tokenScopes)) {
filteredByScopes++;
continue;
}
Eif (!ToolAvailability.isToolAvailable(toolName)) {
filteredByTier++;
continue;
}
// Check if all actions are denied for this CQRS tool
const allActions = extractActionsFromSchema(tool.inputSchema);
if (allActions.length > 0 && shouldRemoveTool(toolName, allActions)) {
filteredByActionDenial++;
continue;
}
// Unknown filtering reason - count as tier
filteredByTier++;
}
}
return {
available: availableTools,
total: totalTools,
filteredByScopes,
filteredByReadOnly,
filteredByTier,
filteredByDeniedRegex,
filteredByActionDenial,
};
}
}
/**
* Filter statistics interface
*/
export interface FilterStats {
/** Number of tools available after filtering */
available: number;
/** Total number of registered tools */
total: number;
/** Tools filtered due to insufficient token scopes */
filteredByScopes: number;
/** Tools filtered due to read-only mode */
filteredByReadOnly: number;
/** Tools filtered due to GitLab tier/version restrictions */
filteredByTier: number;
/** Tools filtered due to denied tools regex */
filteredByDeniedRegex: number;
/** Tools filtered due to all actions being denied */
filteredByActionDenial: number;
}
export { RegistryManager };
|