All files / src/entities/pipelines registry.ts

79.58% Statements 152/191
67.02% Branches 63/94
90.9% Functions 20/22
80% Lines 152/190

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  3x 3x             3x               3x 3x 3x 3x           3x                   4x   4x 4x 11x 7x       4x 4x           4x 2x     2x 2x                       3x 3x   3x 3x           3x 1x     1x 1x                       2x 2x   2x 2x 7x           3x       2x 2x           2x       2x 2x                       1x 1x   1x 1x 3x           1x       1x 1x           1x       1x 1x                       1x 1x   1x 1x           1x       1x 1x                       5x 5x   5x 5x           5x       5x 5x 5x     5x 5x     5x 5x 1x 4x   2x       5x   5x   1x 1x 1x   4x   1x         1x 1x               3x       5x     5x         5x 4x 4x         5x   5x                         3x 3x     3x 3x     3x 3x 1x     3x   3x         3x           3x   3x   2x                                                                                                                         2x 2x                       1x 1x   1x 1x             1x       1x 1x                       1x 1x   1x 1x             1x       1x 1x                       2x 2x   2x 2x 5x 1x       2x 2x                 2x       2x 2x                       1x 1x   1x 1x             1x       1x 1x                       1x 1x   1x 1x             1x       1x 1x                 3x 18x                         3x 6x           3x 7x 5x 5x 60x     2x    
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { zodToJsonSchema } from "zod-to-json-schema";
import {
  ListPipelinesSchema,
  GetPipelineSchema,
  ListPipelineJobsSchema,
  ListPipelineTriggerJobsSchema,
  GetPipelineJobOutputSchema,
} from "./schema-readonly";
import {
  CreatePipelineSchema,
  RetryPipelineSchema,
  CancelPipelineSchema,
  PlayPipelineJobSchema,
  RetryPipelineJobSchema,
  CancelPipelineJobSchema,
} from "./schema";
import { enhancedFetch } from "../../utils/fetch";
import { normalizeProjectId } from "../../utils/projectIdentifier";
import { cleanGidsFromObject } from "../../utils/idConversion";
import { logger } from "../../logger";
import { ToolRegistry, EnhancedToolDefinition } from "../../types";
 
/**
 * Pipelines tools registry - unified registry containing all pipeline operation tools with their handlers
 */
export const pipelinesToolRegistry: ToolRegistry = new Map<string, EnhancedToolDefinition>([
  // Read-only tools
  [
    "list_pipelines",
    {
      name: "list_pipelines",
      description:
        "BROWSE: Search and monitor CI/CD pipelines in a project. Use when: Monitoring build/deployment status, Finding specific pipeline runs, Analyzing CI/CD history and trends. Supports filtering by status, branch, user, and date range. Returns pipeline ID, status, ref, commit SHA, and timing information.",
      inputSchema: zodToJsonSchema(ListPipelinesSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = ListPipelinesSchema.parse(args);
 
        const queryParams = new URLSearchParams();
        Object.entries(options).forEach(([key, value]) => {
          if (value !== undefined && value !== null && key !== "project_id") {
            queryParams.set(key, String(value));
          }
        });
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(options.project_id)}/pipelines?${queryParams}`;
        const response = await enhancedFetch(apiUrl, {
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        if (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const pipelines = await response.json();
        return cleanGidsFromObject(pipelines);
      },
    },
  ],
  [
    "get_pipeline",
    {
      name: "get_pipeline",
      description:
        "ANALYZE: Get comprehensive details about a specific pipeline run. Use when: Debugging CI/CD failures and issues, Inspecting pipeline configuration and timing, Understanding what triggered the run. Returns commit details, branch/tag info, duration metrics, and failure reasons. Essential for pipeline troubleshooting.",
      inputSchema: zodToJsonSchema(GetPipelineSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = GetPipelineSchema.parse(args);
        const { project_id, pipeline_id } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/pipelines/${pipeline_id}`;
        const response = await enhancedFetch(apiUrl, {
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        if (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const pipeline = await response.json();
        return cleanGidsFromObject(pipeline);
      },
    },
  ],
  [
    "list_pipeline_jobs",
    {
      name: "list_pipeline_jobs",
      description:
        "INSPECT: Get all CI/CD jobs within a pipeline run. Use when: Identifying failed jobs and stages, Understanding pipeline job structure, Analyzing job timing and performance. Returns job names, stages, status, duration, and runner info. Supports filtering by scope (failed, success, manual) for targeted troubleshooting.",
      inputSchema: zodToJsonSchema(ListPipelineJobsSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = ListPipelineJobsSchema.parse(args);
        const { project_id, pipeline_id } = options;
 
        const queryParams = new URLSearchParams();
        Object.entries(options).forEach(([key, value]) => {
          if (
            value !== undefined &&
            value !== null &&
            key !== "project_id" &&
            key !== "pipeline_id"
          ) {
            queryParams.set(key, String(value));
          }
        });
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/pipelines/${pipeline_id}/jobs?${queryParams}`;
        const response = await enhancedFetch(apiUrl, {
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const jobs = await response.json();
        return cleanGidsFromObject(jobs);
      },
    },
  ],
  [
    "list_pipeline_trigger_jobs",
    {
      name: "list_pipeline_trigger_jobs",
      description:
        "BRIDGE: List jobs that trigger downstream pipelines in multi-project setups. Use when: Understanding cross-project CI/CD flows, Debugging pipeline dependencies, Analyzing parent-child pipeline connections. Bridge jobs link projects together. Returns trigger configuration and downstream pipeline status.",
      inputSchema: zodToJsonSchema(ListPipelineTriggerJobsSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = ListPipelineTriggerJobsSchema.parse(args);
        const { project_id, pipeline_id } = options;
 
        const queryParams = new URLSearchParams();
        Object.entries(options).forEach(([key, value]) => {
          if (
            value !== undefined &&
            value !== null &&
            key !== "project_id" &&
            key !== "pipeline_id"
          ) {
            queryParams.set(key, String(value));
          }
        });
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/pipelines/${pipeline_id}/bridges?${queryParams}`;
        const response = await enhancedFetch(apiUrl, {
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const bridges = await response.json();
        return cleanGidsFromObject(bridges);
      },
    },
  ],
  [
    "get_pipeline_job",
    {
      name: "get_pipeline_job",
      description:
        "DETAILS: Get detailed information about a specific CI/CD job. Use when: Debugging individual job failures, Inspecting job configuration and variables, Understanding job dependencies and artifacts. Shows job script, runner tags, artifact paths, and failure details. Essential for job-level troubleshooting.",
      inputSchema: zodToJsonSchema(GetPipelineJobOutputSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = GetPipelineJobOutputSchema.parse(args);
        const { project_id, job_id } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/jobs/${job_id}`;
        const response = await enhancedFetch(apiUrl, {
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const job = await response.json();
        return cleanGidsFromObject(job);
      },
    },
  ],
  [
    "get_pipeline_job_output",
    {
      name: "get_pipeline_job_output",
      description:
        "LOGS: Fetch console output/logs from a CI/CD job execution. Use when: Debugging job failures and errors, Reviewing test results and build output, Analyzing command execution traces. Supports output limiting for large logs. Returns raw text showing all commands and output. Critical for troubleshooting CI/CD issues.",
      inputSchema: zodToJsonSchema(GetPipelineJobOutputSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = GetPipelineJobOutputSchema.parse(args);
        const { project_id, job_id, limit, max_lines, start } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/jobs/${job_id}/trace`;
        const response = await enhancedFetch(apiUrl, {
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        let trace = await response.text();
        const lines = trace.split("\n");
        const totalLines = lines.length;
 
        // Default to 200 lines if no limit specified (to prevent token overflow)
        const defaultMaxLines = 200;
        let processedLines: string[] = [];
 
        // Determine the number of lines to show
        let maxLinesToShow = defaultMaxLines;
        if (max_lines !== undefined) {
          maxLinesToShow = max_lines;
        } else if (limit !== undefined) {
          // Always treat limit as line count, not character count
          maxLinesToShow = limit;
        }
 
        // Apply start and limit logic
        let outOfBoundsMessage = "";
 
        if (start !== undefined && start < 0) {
          // Negative start means from end
          processedLines = lines.slice(start);
          Eif (processedLines.length > maxLinesToShow) {
            processedLines = processedLines.slice(-maxLinesToShow);
          }
        } else if (start !== undefined && start >= 0) {
          // Positive start means from beginning
          Iif (start >= totalLines) {
            // Start position is beyond available lines
            processedLines = [];
            outOfBoundsMessage = `[OUT OF BOUNDS: Start position ${start} exceeds total lines ${totalLines}. Available range: 0-${totalLines - 1}]`;
          } else {
            processedLines = lines.slice(start, start + maxLinesToShow);
            Iif (start + maxLinesToShow > totalLines) {
              // Requested range partially out of bounds
              const availableFromStart = totalLines - start;
              outOfBoundsMessage = `[PARTIAL REQUEST: Requested ${maxLinesToShow} lines from position ${start}, but only ${availableFromStart} lines available]`;
            }
          }
        } else {
          // No start, just take last maxLinesToShow
          processedLines = lines.slice(-maxLinesToShow);
        }
 
        // Store the actual data lines count before adding info headers
        const actualDataLines = processedLines.length;
 
        // Add out-of-bounds info if applicable
        Iif (outOfBoundsMessage) {
          processedLines.unshift(outOfBoundsMessage);
        }
 
        // Add truncation info if we truncated (and not already out of bounds)
        if (processedLines.length < totalLines && !outOfBoundsMessage) {
          const truncatedCount = totalLines - actualDataLines;
          processedLines.unshift(
            `[LOG TRUNCATED: Showing last ${actualDataLines} of ${totalLines} lines - ${truncatedCount} lines hidden]`
          );
        }
 
        trace = processedLines.join("\n");
 
        return { trace, totalLines, shownLines: actualDataLines };
      },
    },
  ],
  // Write tools
  [
    "create_pipeline",
    {
      name: "create_pipeline",
      description:
        "CREATE: Trigger a new CI/CD pipeline run on demand. Use when: Manually starting builds or deployments, Running tests on specific branches, Initiating custom pipeline workflows. Requires ref (branch/tag) specification. Can pass variables to customize pipeline behavior. Returns created pipeline details immediately.",
      inputSchema: zodToJsonSchema(CreatePipelineSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = CreatePipelineSchema.parse(args);
        const { project_id, ref, variables } = options;
 
        // Build query parameters - ref is required in query string
        const queryParams = new URLSearchParams();
        queryParams.set("ref", ref);
 
        // Build request body - variables go in body if provided
        const body: Record<string, unknown> = {};
        if (variables && variables.length > 0) {
          body.variables = variables;
        }
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/pipeline?${queryParams}`;
 
        const headers: Record<string, string> = {
          Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          "Content-Type": "application/json",
        };
 
        const requestOptions: RequestInit = {
          method: "POST",
          headers,
        };
 
        // Always send body as JSON, even if empty
        requestOptions.body = JSON.stringify(body);
 
        const response = await enhancedFetch(apiUrl, requestOptions);
 
        Iif (!response.ok) {
          let errorMessage = `GitLab API error: ${response.status} ${response.statusText}`;
          try {
            const errorBody = (await response.json()) as Record<string, unknown>;
 
            // Handle different error message formats from GitLab API
            if (errorBody.message) {
              if (typeof errorBody.message === "string") {
                errorMessage += ` - ${errorBody.message}`;
              } else if (typeof errorBody.message === "object" && errorBody.message !== null) {
                // Handle structured error messages like { base: ["error1", "error2"] }
                const errorDetails: string[] = [];
                const messageObj = errorBody.message as Record<string, unknown>;
 
                Object.keys(messageObj).forEach(key => {
                  const value = messageObj[key];
                  if (Array.isArray(value)) {
                    errorDetails.push(`${key}: ${value.join(", ")}`);
                  } else {
                    errorDetails.push(`${key}: ${String(value)}`);
                  }
                });
 
                if (errorDetails.length > 0) {
                  errorMessage += ` - ${errorDetails.join("; ")}`;
                }
              }
            }
            if (typeof errorBody.error === "string") {
              errorMessage += ` - ${errorBody.error}`;
            }
            if (Array.isArray(errorBody.errors)) {
              const errors = errorBody.errors.map(e => String(e));
              errorMessage += ` - ${errors.join(", ")}`;
            }
 
            logger.error(
              {
                status: response.status,
                statusText: response.statusText,
                errorBody,
                url: apiUrl,
                requestBody: body,
              },
              "create_pipeline failed"
            );
          } catch {
            // If parsing error response fails, use the basic error message
            logger.error(
              {
                status: response.status,
                statusText: response.statusText,
                url: apiUrl,
                requestBody: body,
              },
              "create_pipeline failed (could not parse error response)"
            );
          }
          throw new Error(errorMessage);
        }
 
        const pipeline = await response.json();
        return cleanGidsFromObject(pipeline);
      },
    },
  ],
  [
    "retry_pipeline",
    {
      name: "retry_pipeline",
      description:
        "RETRY: Re-run a previously failed or canceled pipeline with same configuration. Use when: Retrying after fixing flaky tests, Recovering from temporary failures, Re-running without losing successful job results. Retries failed/canceled jobs while preserving successful ones. More efficient than creating new pipeline.",
      inputSchema: zodToJsonSchema(RetryPipelineSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = RetryPipelineSchema.parse(args);
        const { project_id, pipeline_id } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/pipelines/${pipeline_id}/retry`;
        const response = await enhancedFetch(apiUrl, {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const pipeline = await response.json();
        return cleanGidsFromObject(pipeline);
      },
    },
  ],
  [
    "cancel_pipeline",
    {
      name: "cancel_pipeline",
      description:
        'CANCEL: Stop a currently executing pipeline and all its jobs. Use when: Halting unnecessary or incorrect runs, Stopping problematic deployments, Freeing up busy runners. Cancels all pending and running jobs immediately. Pipeline status changes to "canceled" and cannot be resumed.',
      inputSchema: zodToJsonSchema(CancelPipelineSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = CancelPipelineSchema.parse(args);
        const { project_id, pipeline_id } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/pipelines/${pipeline_id}/cancel`;
        const response = await enhancedFetch(apiUrl, {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const pipeline = await response.json();
        return cleanGidsFromObject(pipeline);
      },
    },
  ],
  [
    "play_pipeline_job",
    {
      name: "play_pipeline_job",
      description:
        "PLAY: Trigger a manual job that requires user intervention. Use when: Executing deployment gates and approvals, Running optional or conditional jobs, Proceeding with manual pipeline steps. Manual jobs pause pipeline flow until explicitly triggered. Can pass job variables for runtime configuration.",
      inputSchema: zodToJsonSchema(PlayPipelineJobSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = PlayPipelineJobSchema.parse(args);
        const { project_id, job_id } = options;
 
        const body: Record<string, unknown> = {};
        Object.entries(options).forEach(([key, value]) => {
          if (value !== undefined && value !== null && key !== "project_id" && key !== "job_id") {
            body[key] = value;
          }
        });
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/jobs/${job_id}/play`;
        const response = await enhancedFetch(apiUrl, {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
            "Content-Type": "application/json",
          },
          body: JSON.stringify(body),
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const job = await response.json();
        return cleanGidsFromObject(job);
      },
    },
  ],
  [
    "retry_pipeline_job",
    {
      name: "retry_pipeline_job",
      description:
        "RETRY JOB: Re-run a specific failed or canceled job within a pipeline. Use when: Retrying individual job failures, Avoiding full pipeline re-run, Fixing targeted job issues. Preserves pipeline context and job dependencies. More efficient and targeted than full pipeline retry.",
      inputSchema: zodToJsonSchema(RetryPipelineJobSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = RetryPipelineJobSchema.parse(args);
        const { project_id, job_id } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/jobs/${job_id}/retry`;
        const response = await enhancedFetch(apiUrl, {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const job = await response.json();
        return cleanGidsFromObject(job);
      },
    },
  ],
  [
    "cancel_pipeline_job",
    {
      name: "cancel_pipeline_job",
      description:
        'CANCEL JOB: Stop a specific running job without affecting other pipeline jobs. Use when: Canceling long-running or stuck jobs, Stopping problematic jobs while preserving others, Freeing specific job resources. Job status changes to "canceled". Pipeline continues if other jobs can proceed.',
      inputSchema: zodToJsonSchema(CancelPipelineJobSchema),
      handler: async (args: unknown): Promise<unknown> => {
        const options = CancelPipelineJobSchema.parse(args);
        const { project_id, job_id } = options;
 
        const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/projects/${normalizeProjectId(project_id)}/jobs/${job_id}/cancel`;
        const response = await enhancedFetch(apiUrl, {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.GITLAB_TOKEN}`,
          },
        });
 
        Iif (!response.ok) {
          throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
        }
 
        const job = await response.json();
        return cleanGidsFromObject(job);
      },
    },
  ],
]);
 
/**
 * Get read-only tool names from the registry
 */
export function getPipelinesReadOnlyToolNames(): string[] {
  return [
    "list_pipelines",
    "get_pipeline",
    "list_pipeline_jobs",
    "list_pipeline_trigger_jobs",
    "get_pipeline_job",
    "get_pipeline_job_output",
  ];
}
 
/**
 * Get all tool definitions from the registry (for backward compatibility)
 */
export function getPipelinesToolDefinitions(): EnhancedToolDefinition[] {
  return Array.from(pipelinesToolRegistry.values());
}
 
/**
 * Get filtered tools based on read-only mode
 */
export function getFilteredPipelinesTools(readOnlyMode: boolean = false): EnhancedToolDefinition[] {
  if (readOnlyMode) {
    const readOnlyNames = getPipelinesReadOnlyToolNames();
    return Array.from(pipelinesToolRegistry.values()).filter(tool =>
      readOnlyNames.includes(tool.name)
    );
  }
  return getPipelinesToolDefinitions();
}