opencode-gitlab-plugin 2.8.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34199,6 +34199,450 @@ Examples:
34199
34199
  })
34200
34200
  };
34201
34201
 
34202
+ // src/tools/orbit.ts
34203
+ var z18 = tool.schema;
34204
+ function orbitRelTypes(entityType) {
34205
+ switch (entityType) {
34206
+ case "MergeRequest":
34207
+ return [
34208
+ "AUTHORED",
34209
+ "REVIEWER",
34210
+ "ASSIGNED",
34211
+ "CLOSES",
34212
+ "MENTIONS",
34213
+ "IN_PROJECT",
34214
+ "HAS_HEAD_PIPELINE",
34215
+ "TRIGGERED",
34216
+ "IN_MILESTONE",
34217
+ "HAS_LABEL"
34218
+ ];
34219
+ case "WorkItem":
34220
+ return [
34221
+ "AUTHORED",
34222
+ "ASSIGNED",
34223
+ "CLOSES",
34224
+ "MENTIONS",
34225
+ "RELATED_TO",
34226
+ "CONTAINS",
34227
+ "IN_PROJECT",
34228
+ "IN_GROUP",
34229
+ "IN_MILESTONE",
34230
+ "HAS_LABEL"
34231
+ ];
34232
+ case "User":
34233
+ return ["AUTHORED", "ASSIGNED", "REVIEWER", "MEMBER_OF", "OWNER", "CREATOR"];
34234
+ case "Project":
34235
+ return ["CONTAINS", "IN_PROJECT", "MEMBER_OF", "CREATOR"];
34236
+ case "Pipeline":
34237
+ return ["HAS_HEAD_PIPELINE", "TRIGGERED", "IN_PROJECT", "HAS_JOB", "HAS_STAGE"];
34238
+ case "File":
34239
+ return ["CONTAINS", "IMPORTS", "DEFINES", "CALLS", "ON_BRANCH"];
34240
+ case "Group":
34241
+ return ["CONTAINS", "MEMBER_OF", "OWNER", "IN_GROUP"];
34242
+ case "Commit":
34243
+ return ["MERGED_AT_COMMIT"];
34244
+ default:
34245
+ return ["AUTHORED", "ASSIGNED", "REVIEWER", "CLOSES", "MENTIONS", "RELATED_TO", "IN_PROJECT"];
34246
+ }
34247
+ }
34248
+ var orbitTools = {
34249
+ gitlab_orbit_status: tool({
34250
+ description: `Check GitLab Orbit Knowledge Graph API availability and health.
34251
+
34252
+ Returns the status of the Orbit API for the connected GitLab instance.
34253
+ Orbit is GitLab's Knowledge Graph API that provides rich SDLC graph data.
34254
+
34255
+ Note: Orbit is only available on Premium/Ultimate tiers and requires the feature flag to be enabled.
34256
+ If unavailable, returns an error with suggestions for REST API alternatives.`,
34257
+ args: {},
34258
+ execute: async (_args, _ctx) => {
34259
+ const client = getGitLabClient();
34260
+ try {
34261
+ const status = await client.fetch("GET", "/orbit/status");
34262
+ return JSON.stringify(
34263
+ {
34264
+ ...status,
34265
+ available: true,
34266
+ message: "Orbit Knowledge Graph API is available"
34267
+ },
34268
+ null,
34269
+ 2
34270
+ );
34271
+ } catch (error45) {
34272
+ const errorMessage = error45 instanceof Error ? error45.message : String(error45);
34273
+ if (errorMessage.includes("404") || errorMessage.includes("not found")) {
34274
+ return JSON.stringify(
34275
+ {
34276
+ available: false,
34277
+ error: "Orbit API not available",
34278
+ reason: "The Orbit Knowledge Graph API is not enabled on this GitLab instance. Orbit requires GitLab Premium/Ultimate tier and the feature flag to be enabled.",
34279
+ alternatives: [
34280
+ "Use REST API endpoints for MRs, issues, pipelines",
34281
+ "Use GraphQL API for complex queries",
34282
+ "Use gitlab_search for finding related entities"
34283
+ ]
34284
+ },
34285
+ null,
34286
+ 2
34287
+ );
34288
+ }
34289
+ if (errorMessage.includes("403") || errorMessage.includes("forbidden")) {
34290
+ return JSON.stringify(
34291
+ {
34292
+ available: false,
34293
+ error: "Orbit API access forbidden",
34294
+ reason: "Your access token does not have permission to use the Orbit API. This may require specific scopes or Premium/Ultimate tier.",
34295
+ alternatives: [
34296
+ "Check token scopes include api or read_api",
34297
+ "Verify your GitLab tier supports Orbit",
34298
+ "Use REST/GraphQL APIs as fallback"
34299
+ ]
34300
+ },
34301
+ null,
34302
+ 2
34303
+ );
34304
+ }
34305
+ if (errorMessage.includes("502")) {
34306
+ return JSON.stringify(
34307
+ {
34308
+ available: false,
34309
+ error: "Orbit API temporarily unavailable",
34310
+ reason: "The Orbit API returned a 502 error. This may be temporary.",
34311
+ suggestion: "Try again later or use REST/GraphQL APIs as fallback."
34312
+ },
34313
+ null,
34314
+ 2
34315
+ );
34316
+ }
34317
+ return JSON.stringify(
34318
+ {
34319
+ available: false,
34320
+ error: "Orbit API error",
34321
+ message: errorMessage,
34322
+ alternatives: ["Use REST/GraphQL APIs as fallback"]
34323
+ },
34324
+ null,
34325
+ 2
34326
+ );
34327
+ }
34328
+ }
34329
+ }),
34330
+ gitlab_orbit_schema: tool({
34331
+ description: `Get the Orbit Knowledge Graph schema.
34332
+
34333
+ Returns the available node types, relationship types, and their properties.
34334
+ Use this to understand what entities and relationships can be queried.
34335
+
34336
+ Node type domains include:
34337
+ - Core: Project, Group, User
34338
+ - Source Code: File, Definition, Commit
34339
+ - Code Review: MergeRequest, Diff, Review
34340
+ - CI/CD: Pipeline, Job, Deployment
34341
+ - Planning: WorkItem (issues, epics, tasks)
34342
+ - Security: Vulnerability
34343
+
34344
+ Note: Requires Orbit API to be available (Premium/Ultimate tier).`,
34345
+ args: {},
34346
+ execute: async (_args, _ctx) => {
34347
+ const client = getGitLabClient();
34348
+ try {
34349
+ const schema = await client.fetch("GET", "/orbit/schema");
34350
+ return JSON.stringify(schema, null, 2);
34351
+ } catch (error45) {
34352
+ const errorMessage = error45 instanceof Error ? error45.message : String(error45);
34353
+ if (errorMessage.includes("404") || errorMessage.includes("not found")) {
34354
+ return JSON.stringify(
34355
+ {
34356
+ error: "Orbit API not available",
34357
+ suggestion: "Use gitlab_orbit_status to check API availability"
34358
+ },
34359
+ null,
34360
+ 2
34361
+ );
34362
+ }
34363
+ if (errorMessage.includes("502")) {
34364
+ return JSON.stringify(
34365
+ {
34366
+ error: "Orbit API temporarily unavailable",
34367
+ suggestion: "The Orbit API returned a 502 error. This may be temporary - try again later."
34368
+ },
34369
+ null,
34370
+ 2
34371
+ );
34372
+ }
34373
+ throw error45;
34374
+ }
34375
+ }
34376
+ }),
34377
+ gitlab_orbit_query: tool({
34378
+ description: `Execute a query against the Orbit Knowledge Graph.
34379
+
34380
+ Query types:
34381
+ - traversal: Fetch matching nodes or follow relationships between nodes
34382
+ - neighbors: Return nodes connected to one bounded node
34383
+ - aggregation: Count/sum/avg/group graph results
34384
+ - path_finding: Find a bounded path between two nodes
34385
+
34386
+ QUERY SHAPE (current DSL, format_version 5.x):
34387
+ Every query has a "query_type" and a "nodes" array of node selectors (max 5).
34388
+ A node selector names an entity and is made SELECTIVE via "node_ids" (exact
34389
+ internal ids) or "filters" (natural properties). Relationships between selectors
34390
+ go in a "relationships" array referencing selector "id" aliases.
34391
+
34392
+ IMPORTANT changes from older docs:
34393
+ - Use a top-level "nodes" ARRAY, not a single "node" object.
34394
+ - Pin ids with "node_ids": [123], NOT filters:{id:{op:"eq",value:123}}.
34395
+ - Filters use {op: value}, e.g. {"state": "merged"} or {"created_at": {"gte": "2026-01-01"}}.
34396
+ - A "neighbors" query uses a 1-element "nodes" array plus a top-level
34397
+ "neighbors": {direction, rel_types:[...]} object. rel_types is REQUIRED to
34398
+ bound the lookup and is capped at 10 entries.
34399
+
34400
+ Example neighbors query (an MR's graph neighbours):
34401
+ {
34402
+ "query_type": "neighbors",
34403
+ "nodes": [{ "id": "mr", "entity": "MergeRequest", "node_ids": [507483917] }],
34404
+ "neighbors": {
34405
+ "direction": "both",
34406
+ "rel_types": ["AUTHORED", "REVIEWER", "IN_PROJECT", "CLOSES", "HAS_HEAD_PIPELINE"]
34407
+ },
34408
+ "limit": 30
34409
+ }
34410
+
34411
+ Example traversal (merged MRs in a project):
34412
+ {
34413
+ "query_type": "traversal",
34414
+ "nodes": [
34415
+ { "id": "project", "entity": "Project", "filters": {"full_path": "gitlab-org/gitlab"} },
34416
+ { "id": "mr", "entity": "MergeRequest", "filters": {"state": "merged"},
34417
+ "columns": ["iid", "title", "merged_at"] }
34418
+ ],
34419
+ "relationships": [{ "type": "IN_PROJECT", "from": "mr", "to": "project" }],
34420
+ "limit": 25
34421
+ }
34422
+
34423
+ Notes:
34424
+ - node_ids are GitLab *internal* numeric ids (not IIDs). For an MR, get it via
34425
+ gitlab_get_merge_request (the "id" field). For epics, use work_item_id.
34426
+ - Traversal/aggregation queries must include at least one selective node.
34427
+ - aggregation adds an "aggregations" array (e.g. [{"count":"mr"}]) with optional
34428
+ "group_by"; path_finding adds a "path":{from,to,max_depth} object between two
34429
+ node selectors. Both use the same envelope; see gitlab_orbit_schema and the
34430
+ Orbit query-language docs for the full grammar.
34431
+ - Use gitlab_orbit_schema to discover entities and relationship types.
34432
+ Returns nodes and edges arrays.`,
34433
+ args: {
34434
+ // Using a JSON string rather than a structured zod schema because the Orbit query
34435
+ // format is still evolving. This allows flexibility as the API changes without
34436
+ // requiring schema updates for each iteration.
34437
+ query: z18.string().describe(
34438
+ 'JSON string containing the full query object. Must include "query_type" and a top-level "nodes" array of selectors (each pinned by "node_ids" or "filters"); add "relationships"/"neighbors"/"aggregations"/"path" per the query_type. See the tool description for the current DSL and worked examples.'
34439
+ ),
34440
+ limit: z18.number().optional().describe("Maximum number of results (default: 30)")
34441
+ },
34442
+ execute: async (args, _ctx) => {
34443
+ const client = getGitLabClient();
34444
+ let queryObj;
34445
+ try {
34446
+ queryObj = JSON.parse(args.query);
34447
+ } catch {
34448
+ return JSON.stringify(
34449
+ {
34450
+ error: "Invalid JSON in query parameter",
34451
+ suggestion: "Ensure the query parameter is valid JSON"
34452
+ },
34453
+ null,
34454
+ 2
34455
+ );
34456
+ }
34457
+ if (typeof queryObj !== "object" || queryObj === null || Array.isArray(queryObj)) {
34458
+ return JSON.stringify(
34459
+ {
34460
+ error: "Invalid query parameter",
34461
+ suggestion: 'The query must be a JSON object with a "query_type" and a "nodes" array.'
34462
+ },
34463
+ null,
34464
+ 2
34465
+ );
34466
+ }
34467
+ if (args.limit !== void 0) {
34468
+ queryObj.limit = args.limit;
34469
+ }
34470
+ const requestBody = {
34471
+ query: queryObj,
34472
+ response_format: "raw"
34473
+ };
34474
+ try {
34475
+ const result = await client.fetch("POST", "/orbit/query", requestBody);
34476
+ if (result.code) {
34477
+ return JSON.stringify(
34478
+ {
34479
+ error: "Query compilation error",
34480
+ code: result.code,
34481
+ message: result.message,
34482
+ suggestion: 'Check query structure against the current DSL: top-level "nodes" array, pin ids with "node_ids", filters use {op: value}, and a "neighbors" query needs neighbors:{direction, rel_types} (max 10 rel_types).'
34483
+ },
34484
+ null,
34485
+ 2
34486
+ );
34487
+ }
34488
+ return JSON.stringify(result, null, 2);
34489
+ } catch (error45) {
34490
+ const errorMessage = error45 instanceof Error ? error45.message : String(error45);
34491
+ if (errorMessage.includes("404") || errorMessage.includes("not found")) {
34492
+ return JSON.stringify(
34493
+ {
34494
+ error: "Orbit API not available",
34495
+ suggestion: "Use gitlab_orbit_status to check API availability"
34496
+ },
34497
+ null,
34498
+ 2
34499
+ );
34500
+ }
34501
+ if (errorMessage.includes("502")) {
34502
+ return JSON.stringify(
34503
+ {
34504
+ error: "Orbit query failed",
34505
+ message: "The Orbit API returned a 502 error. This is a known issue with some entity types (e.g., source_code domain).",
34506
+ suggestion: "Try a different entity type or use REST/GraphQL APIs as fallback."
34507
+ },
34508
+ null,
34509
+ 2
34510
+ );
34511
+ }
34512
+ throw error45;
34513
+ }
34514
+ }
34515
+ }),
34516
+ gitlab_orbit_neighbors: tool({
34517
+ description: `Get immediate neighbors of a node in the Orbit Knowledge Graph.
34518
+
34519
+ This is a simplified wrapper that builds the query for you.
34520
+ Returns nodes directly connected to the specified node.
34521
+
34522
+ Common use cases:
34523
+ - Get all connections to a project (users, groups, pipelines, MRs)
34524
+ - Get pipelines for an MR
34525
+ - Get files changed in a commit
34526
+ - Get deployments from a pipeline
34527
+
34528
+ Note: Use GitLab internal numeric IDs (not IIDs).
34529
+ Example: For MR !123 in gitlab-org/gitlab, first get the internal ID via gitlab_get_merge_request,
34530
+ then use that ID (e.g., 377844873). For epics, use the work_item_id.`,
34531
+ args: {
34532
+ entity_type: z18.string().describe(
34533
+ "Type of the entity (e.g., Project, MergeRequest, User, Pipeline, Commit, WorkItem, Group)"
34534
+ ),
34535
+ entity_id: z18.number().describe(
34536
+ "GitLab internal numeric ID (not IID). Get this from REST/GraphQL API responses."
34537
+ ),
34538
+ direction: z18.enum(["incoming", "outgoing", "both"]).optional().describe("Direction of relationships to traverse (default: both)"),
34539
+ rel_types: z18.array(z18.string()).optional().describe(
34540
+ 'Relationship types to follow. Required by the API to bound the lookup; if omitted, a sensible default set for the entity type is used. The API caps this at 10 per selector, so more than 10 entries are truncated to the first 10 and the response includes a "warnings" field. See gitlab_orbit_schema for valid edge types.'
34541
+ ),
34542
+ limit: z18.number().optional().describe("Maximum number of neighbors to return (default: 30)")
34543
+ },
34544
+ execute: async (args, _ctx) => {
34545
+ const client = getGitLabClient();
34546
+ const direction = args.direction || "both";
34547
+ const requestedRelTypes = args.rel_types?.length ? args.rel_types : orbitRelTypes(args.entity_type);
34548
+ const relTypes = requestedRelTypes.slice(0, 10);
34549
+ const warnings = requestedRelTypes.length > relTypes.length ? [`rel_types truncated to 10 (got ${requestedRelTypes.length})`] : [];
34550
+ const queryObj = {
34551
+ query_type: "neighbors",
34552
+ nodes: [
34553
+ {
34554
+ id: "n",
34555
+ entity: args.entity_type,
34556
+ node_ids: [args.entity_id]
34557
+ }
34558
+ ],
34559
+ neighbors: {
34560
+ direction,
34561
+ rel_types: relTypes
34562
+ }
34563
+ };
34564
+ if (args.limit !== void 0) {
34565
+ queryObj.limit = args.limit;
34566
+ }
34567
+ const requestBody = {
34568
+ query: queryObj,
34569
+ response_format: "raw"
34570
+ };
34571
+ try {
34572
+ const result = await client.fetch("POST", "/orbit/query", requestBody);
34573
+ if (result.code) {
34574
+ return JSON.stringify(
34575
+ {
34576
+ error: "Query error",
34577
+ code: result.code,
34578
+ message: result.message,
34579
+ entity_type: args.entity_type,
34580
+ entity_id: args.entity_id,
34581
+ ...warnings.length > 0 && { warnings }
34582
+ },
34583
+ null,
34584
+ 2
34585
+ );
34586
+ }
34587
+ return JSON.stringify(warnings.length > 0 ? { ...result, warnings } : result, null, 2);
34588
+ } catch (error45) {
34589
+ const errorMessage = error45 instanceof Error ? error45.message : String(error45);
34590
+ if (errorMessage.includes("404") || errorMessage.includes("not found")) {
34591
+ return JSON.stringify(
34592
+ {
34593
+ error: "Orbit API not available",
34594
+ entity_type: args.entity_type,
34595
+ entity_id: args.entity_id,
34596
+ suggestion: "Use gitlab_orbit_status to check API availability"
34597
+ },
34598
+ null,
34599
+ 2
34600
+ );
34601
+ }
34602
+ if (errorMessage.includes("502")) {
34603
+ return JSON.stringify(
34604
+ {
34605
+ error: "Orbit query failed",
34606
+ entity_type: args.entity_type,
34607
+ entity_id: args.entity_id,
34608
+ message: "The Orbit API returned a 502 error. This is a known issue with some entity types.",
34609
+ suggestion: "Try a different entity type or use REST/GraphQL APIs as fallback."
34610
+ },
34611
+ null,
34612
+ 2
34613
+ );
34614
+ }
34615
+ throw error45;
34616
+ }
34617
+ }
34618
+ })
34619
+ };
34620
+
34621
+ // src/tools/index.ts
34622
+ var mcpTools = {
34623
+ ...mergeRequestTools,
34624
+ ...issueTools,
34625
+ ...epicTools,
34626
+ ...pipelineTools,
34627
+ ...repositoryTools,
34628
+ ...searchTools,
34629
+ ...projectTools,
34630
+ ...userTools,
34631
+ ...securityTools,
34632
+ ...todoTools,
34633
+ ...wikiTools,
34634
+ ...workItemTools,
34635
+ ...discussionsUnifiedTools,
34636
+ ...notesUnifiedTools,
34637
+ ...gitTools,
34638
+ ...auditTools,
34639
+ ...awardEmojiTools
34640
+ };
34641
+ var allTools = {
34642
+ ...mcpTools,
34643
+ ...orbitTools
34644
+ };
34645
+
34202
34646
  // src/mcp-adapter.ts
34203
34647
  function adaptToolsToMcp(server, tools) {
34204
34648
  for (const [name, def] of Object.entries(tools)) {
@@ -34224,31 +34668,12 @@ async function main() {
34224
34668
  `);
34225
34669
  process.exit(1);
34226
34670
  }
34227
- const allTools = {
34228
- ...mergeRequestTools,
34229
- ...issueTools,
34230
- ...epicTools,
34231
- ...pipelineTools,
34232
- ...repositoryTools,
34233
- ...searchTools,
34234
- ...projectTools,
34235
- ...userTools,
34236
- ...securityTools,
34237
- ...todoTools,
34238
- ...wikiTools,
34239
- ...workItemTools,
34240
- ...discussionsUnifiedTools,
34241
- ...notesUnifiedTools,
34242
- ...gitTools,
34243
- ...auditTools,
34244
- ...awardEmojiTools
34245
- };
34246
- const version2 = true ? "2.8.2" : "0.0.0";
34671
+ const version2 = true ? "3.0.1" : "0.0.0";
34247
34672
  const server = new McpServer({ name: "gitlab", version: version2 });
34248
- adaptToolsToMcp(server, allTools);
34673
+ adaptToolsToMcp(server, mcpTools);
34249
34674
  const transport = new StdioServerTransport();
34250
34675
  await server.connect(transport);
34251
- const toolCount = Object.keys(allTools).length;
34676
+ const toolCount = Object.keys(mcpTools).length;
34252
34677
  process.stderr.write(`gitlab MCP: serving ${toolCount} tools via stdio
34253
34678
  `);
34254
34679
  process.on("SIGINT", async () => {