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 | 3x 3x 3x 3x 3x 3x 3x 9x 9x 9x 9x 9x 9x 7x 7x 7x 5x 1x 4x 3x 3x 1x 2x 1x 1x 3x 1x 7x 2x 2x 7x 6x 6x 6x 6x 1x 6x 6x 6x 4x 4x 4x 3x 1x 2x 2x 2x 2x 2x 2x 4x 2x 2x 5x 5x 5x 5x 5x 40x 35x 5x 5x 4x 2x 2x 2x 1x 1x 2x 2x 2x 7x 7x 7x 7x 7x 24x 9x 7x 7x 1x 7x 7x 7x 5x 5x 5x 4x 1x 3x 3x 3x 1x 2x 1x 1x 3x 1x 5x 2x 2x 7x 7x 7x 7x 7x 1x 7x 7x 7x 5x 5x 5x 4x 1x 3x 3x 3x 1x 2x 1x 1x 3x 1x 5x 2x 2x 3x 13x 3x 2x 3x 3x 2x 2x 10x 1x | /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { zodToJsonSchema } from "zod-to-json-schema"; import { ListVariablesSchema, GetVariableSchema } from "./schema-readonly"; import { CreateVariableSchema, UpdateVariableSchema, DeleteVariableSchema } from "./schema"; import { enhancedFetch } from "../../utils/fetch"; import { cleanGidsFromObject } from "../../utils/idConversion"; // GitLab API error response interface interface GitLabErrorResponse { message?: string | { value?: string[] }; error?: string; errors?: Record<string, string | string[]>; } import { resolveNamespaceForAPI } from "../../utils/namespace"; import { ToolRegistry, EnhancedToolDefinition } from "../../types"; /** * Variables tools registry - unified registry containing all variable operation tools with their handlers */ export const variablesToolRegistry: ToolRegistry = new Map<string, EnhancedToolDefinition>([ // Read-only tools [ "list_variables", { name: "list_variables", description: "View all CI/CD environment variables configured for pipelines. Use to audit secrets, review configuration, or understand pipeline environment. Shows variable keys (values are masked for security). Returns protection status, masking, and environment scopes. Group variables are inherited by all projects.", inputSchema: zodToJsonSchema(ListVariablesSchema), handler: async (args: unknown): Promise<unknown> => { const options = ListVariablesSchema.parse(args); const { namespace } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/variables`; const response = await enhancedFetch(apiUrl, { headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, }, }); if (!response.ok) { let errorMessage = `GitLab API error: ${response.status} ${response.statusText}`; try { const text = await response.text(); if (!text.trim()) { throw new Error(errorMessage); } const errorResponse = JSON.parse(text) as GitLabErrorResponse; Eif (errorResponse.message) { if (typeof errorResponse.message === "string") { errorMessage += ` - ${errorResponse.message}`; } else if ( errorResponse.message.value && Array.isArray(errorResponse.message.value) ) { errorMessage += ` - ${errorResponse.message.value.join(", ")}`; } else { errorMessage += ` - ${JSON.stringify(errorResponse.message)}`; } } if (errorResponse.error) { errorMessage += ` - ${errorResponse.error}`; } } catch { // If error response can't be parsed, use the basic message } throw new Error(errorMessage); } const variables = await response.json(); return cleanGidsFromObject(variables); }, }, ], [ "get_variable", { name: "get_variable", description: "Retrieve specific CI/CD variable details including value (if not masked), type, and security settings. Use for debugging pipeline issues, verifying configuration, or checking environment-specific values. Supports scoped variables for different environments (production/staging).", inputSchema: zodToJsonSchema(GetVariableSchema), handler: async (args: unknown): Promise<unknown> => { const options = GetVariableSchema.parse(args); const { namespace, key, filter } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const queryParams = new URLSearchParams(); if (filter?.environment_scope) { queryParams.set("filter[environment_scope]", filter.environment_scope); } const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/variables/${encodeURIComponent(key)}?${queryParams}`; const response = await enhancedFetch(apiUrl, { headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, }, }); if (!response.ok) { let errorMessage = `GitLab API error: ${response.status} ${response.statusText}`; try { const text = await response.text(); if (!text.trim()) { throw new Error(errorMessage); } const errorResponse = JSON.parse(text) as GitLabErrorResponse; Eif (errorResponse.message) { if (typeof errorResponse.message === "string") { errorMessage += ` - ${errorResponse.message}`; } else Eif ( errorResponse.message.value && Array.isArray(errorResponse.message.value) ) { errorMessage += ` - ${errorResponse.message.value.join(", ")}`; } else { errorMessage += ` - ${JSON.stringify(errorResponse.message)}`; } } Eif (errorResponse.error) { errorMessage += ` - ${errorResponse.error}`; } } catch { // If error response can't be parsed, use the basic message } throw new Error(errorMessage); } const variable = await response.json(); return cleanGidsFromObject(variable); }, }, ], // Write tools [ "create_variable", { name: "create_variable", description: "Add new CI/CD environment variable for pipeline configuration, secrets, or deployment settings. Use for API keys, database URLs, feature flags. Supports masking sensitive values, protection for specific branches, environment scoping, and file type for certificates/configs. Group variables apply to all child projects.", inputSchema: zodToJsonSchema(CreateVariableSchema), handler: async (args: unknown): Promise<unknown> => { const options = CreateVariableSchema.parse(args); const { namespace } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const body: Record<string, unknown> = {}; Object.entries(options).forEach(([key, value]) => { if (value !== undefined && value !== null && key !== "namespace") { body[key] = value; } }); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/variables`; const response = await enhancedFetch(apiUrl, { method: "POST", headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { let errorMessage = `GitLab API error: ${response.status} ${response.statusText}`; try { const text = await response.text(); Eif (!text.trim()) { throw new Error(errorMessage); } const errorResponse = JSON.parse(text) as GitLabErrorResponse; if (errorResponse.message) { if (typeof errorResponse.message === "string") { errorMessage += ` - ${errorResponse.message}`; } else if ( errorResponse.message.value && Array.isArray(errorResponse.message.value) ) { errorMessage += ` - ${errorResponse.message.value.join(", ")}`; } else { errorMessage += ` - ${JSON.stringify(errorResponse.message)}`; } } if (errorResponse.error) { errorMessage += ` - ${errorResponse.error}`; } } catch { // If error response can't be parsed, use the basic message } throw new Error(errorMessage); } const variable = await response.json(); return cleanGidsFromObject(variable); }, }, ], [ "update_variable", { name: "update_variable", description: "Modify CI/CD variable value or configuration. Use to rotate secrets, update endpoints, change security settings, or adjust environment scopes. Can convert between env_var and file types. Changes take effect in next pipeline run. Be cautious with production variables.", inputSchema: zodToJsonSchema(UpdateVariableSchema), handler: async (args: unknown): Promise<unknown> => { const options = UpdateVariableSchema.parse(args); const { namespace, key, filter } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const body: Record<string, unknown> = {}; Object.entries(options).forEach(([k, value]) => { if ( value !== undefined && value !== null && k !== "namespace" && k !== "key" && k !== "filter" ) { body[k] = value; } }); // Add filter as query parameter if provided const queryParams = new URLSearchParams(); if (filter?.environment_scope) { queryParams.set("filter[environment_scope]", filter.environment_scope); } const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/variables/${encodeURIComponent(key)}?${queryParams}`; const response = await enhancedFetch(apiUrl, { method: "PUT", headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { let errorMessage = `GitLab API error: ${response.status} ${response.statusText}`; try { const text = await response.text(); if (!text.trim()) { throw new Error(errorMessage); } const errorResponse = JSON.parse(text) as GitLabErrorResponse; Eif (errorResponse.message) { if (typeof errorResponse.message === "string") { errorMessage += ` - ${errorResponse.message}`; } else if ( errorResponse.message.value && Array.isArray(errorResponse.message.value) ) { errorMessage += ` - ${errorResponse.message.value.join(", ")}`; } else { errorMessage += ` - ${JSON.stringify(errorResponse.message)}`; } } if (errorResponse.error) { errorMessage += ` - ${errorResponse.error}`; } } catch { // If error response can't be parsed, use the basic message } throw new Error(errorMessage); } const variable = await response.json(); return cleanGidsFromObject(variable); }, }, ], [ "delete_variable", { name: "delete_variable", description: "Delete CI/CD variable permanently from configuration. Use to remove unused secrets, clean up after migrations, or revoke access. Can target specific environment-scoped variants. Warning: may break pipelines depending on the variable. Cannot be undone.", inputSchema: zodToJsonSchema(DeleteVariableSchema), handler: async (args: unknown): Promise<unknown> => { const options = DeleteVariableSchema.parse(args); const { namespace, key, filter } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); // Add filter as query parameter if provided const queryParams = new URLSearchParams(); if (filter?.environment_scope) { queryParams.set("filter[environment_scope]", filter.environment_scope); } const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/variables/${encodeURIComponent(key)}?${queryParams}`; const response = await enhancedFetch(apiUrl, { method: "DELETE", headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, }, }); if (!response.ok) { let errorMessage = `GitLab API error: ${response.status} ${response.statusText}`; try { const text = await response.text(); if (!text.trim()) { throw new Error(errorMessage); } const errorResponse = JSON.parse(text) as GitLabErrorResponse; Eif (errorResponse.message) { if (typeof errorResponse.message === "string") { errorMessage += ` - ${errorResponse.message}`; } else if ( errorResponse.message.value && Array.isArray(errorResponse.message.value) ) { errorMessage += ` - ${errorResponse.message.value.join(", ")}`; } else { errorMessage += ` - ${JSON.stringify(errorResponse.message)}`; } } if (errorResponse.error) { errorMessage += ` - ${errorResponse.error}`; } } catch { // If error response can't be parsed, use the basic message } throw new Error(errorMessage); } const result = await response.json(); return cleanGidsFromObject(result); }, }, ], ]); /** * Get read-only tool names from the registry */ export function getVariablesReadOnlyToolNames(): string[] { return ["list_variables", "get_variable"]; } /** * Get all tool definitions from the registry (for backward compatibility) */ export function getVariablesToolDefinitions(): EnhancedToolDefinition[] { return Array.from(variablesToolRegistry.values()); } /** * Get filtered tools based on read-only mode */ export function getFilteredVariablesTools(readOnlyMode: boolean = false): EnhancedToolDefinition[] { if (readOnlyMode) { const readOnlyNames = getVariablesReadOnlyToolNames(); return Array.from(variablesToolRegistry.values()).filter(tool => readOnlyNames.includes(tool.name) ); } return getVariablesToolDefinitions(); } |