@structured-world/gitlab-mcp 9.0.0 → 9.1.0

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.
package/README.md CHANGED
@@ -1,13 +1,20 @@
1
1
  # Advanced GitLab MCP server
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![npm downloads](https://img.shields.io/npm/dm/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Release](https://github.com/structured-world/gitlab-mcp/workflows/Release/badge.svg)](https://github.com/structured-world/gitlab-mcp/actions) [![Coverage](https://codecov.io/gh/structured-world/gitlab-mcp/graph/badge.svg)](https://codecov.io/gh/structured-world/gitlab-mcp) [![Coverage Report](https://img.shields.io/badge/Coverage-Live%20Report-brightgreen?logo=github)](https://gitlab-mcp.sw.foundation/coverage/)
3
+ [![npm version](https://img.shields.io/npm/v/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![npm downloads](https://img.shields.io/npm/dm/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](../../LICENSE) [![Release](https://github.com/structured-world/gitlab-mcp/workflows/Release/badge.svg)](https://github.com/structured-world/gitlab-mcp/actions) [![Coverage](https://codecov.io/gh/structured-world/gitlab-mcp/graph/badge.svg)](https://codecov.io/gh/structured-world/gitlab-mcp) [![Coverage Report](https://img.shields.io/badge/Coverage-Live%20Report-brightgreen?logo=github)](https://gitlab-mcp.sw.foundation/coverage/)
4
4
 
5
5
  Advanced GitLab MCP server — 58 CQRS tools exposing 230 GitLab operations across 26 entity types. The tool catalog and parameters are filtered to each instance's GitLab version, tier, and token scopes, so the agent sees only what the connected instance actually supports.
6
6
 
7
- [![Install in Claude Desktop](https://img.shields.io/badge/Claude_Desktop-Install_Extension-F97316?style=for-the-badge)](https://gitlab-mcp.sw.foundation/downloads/gitlab-mcp-9.0.0.mcpb)
7
+ [![Install in Claude Desktop](https://img.shields.io/badge/Claude_Desktop-Install_Extension-F97316?style=for-the-badge)](https://gitlab-mcp.sw.foundation/downloads/gitlab-mcp-9.1.0.mcpb)
8
8
  [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_MCP_Server-007ACC?style=for-the-badge&logo=visualstudiocode&logoColor=white)](vscode:mcp/install?%7B%22name%22%3A%22gitlab-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40structured-world%2Fgitlab-mcp%22%5D%7D)
9
9
  [![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install_MCP_Server-24bfa5?style=for-the-badge&logo=visualstudiocode&logoColor=white)](vscode-insiders:mcp/install?%7B%22name%22%3A%22gitlab-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40structured-world%2Fgitlab-mcp%22%5D%7D)
10
10
 
11
+ ## Packages
12
+
13
+ This is a monorepo with two npm packages:
14
+
15
+ - **[`@structured-world/gitlab-mcp`](https://www.npmjs.com/package/@structured-world/gitlab-mcp)** — the MCP server. In-memory and file OAuth-session storage, no database dependency. This is all most users need.
16
+ - **[`@structured-world/gitlab-mcp-db`](https://www.npmjs.com/package/@structured-world/gitlab-mcp-db)** — optional PostgreSQL/Prisma OAuth-session backend for running multiple replicas behind a load balancer. Enable it with `OAUTH_STORAGE_TYPE=postgresql`; see the [PostgreSQL deployment guide](https://gitlab-mcp.sw.foundation/deployment/docker-postgres) for the full setup.
17
+
11
18
  ## Quick Start
12
19
 
13
20
  ```json
@@ -154,13 +161,13 @@ The server handles GitLab connectivity issues gracefully:
154
161
 
155
162
  ## Contributing
156
163
 
157
- See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, testing, and PR guidelines.
164
+ See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development setup, testing, and PR guidelines.
158
165
 
159
166
  ## Support the Project
160
167
 
161
168
  <div align="center">
162
169
 
163
- ![USDT TRC-20 Donation QR Code](assets/usdt-qr.svg)
170
+ ![USDT TRC-20 Donation QR Code](../../packages/gitlab-mcp/assets/usdt-qr.svg)
164
171
 
165
172
  USDT (TRC-20): `TFDsezHa1cBkoeZT5q2T49Wp66K8t2DmdA`
166
173
 
@@ -168,6 +175,6 @@ USDT (TRC-20): `TFDsezHa1cBkoeZT5q2T49Wp66K8t2DmdA`
168
175
 
169
176
  ## License
170
177
 
171
- Apache License 2.0 — see [LICENSE](LICENSE) for details.
178
+ Apache License 2.0 — see [LICENSE](../../LICENSE) for details.
172
179
 
173
- Based on [zereight/gitlab-mcp](https://github.com/zereight/gitlab-mcp) (MIT). See [LICENSE.MIT](LICENSE.MIT).
180
+ Based on [zereight/gitlab-mcp](https://github.com/zereight/gitlab-mcp) (MIT). See [LICENSE.MIT](../../LICENSE.MIT).
package/README.md.in CHANGED
@@ -1,6 +1,6 @@
1
1
  # Advanced GitLab MCP server
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![npm downloads](https://img.shields.io/npm/dm/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Release](https://github.com/structured-world/gitlab-mcp/workflows/Release/badge.svg)](https://github.com/structured-world/gitlab-mcp/actions) [![Coverage](https://codecov.io/gh/structured-world/gitlab-mcp/graph/badge.svg)](https://codecov.io/gh/structured-world/gitlab-mcp) [![Coverage Report](https://img.shields.io/badge/Coverage-Live%20Report-brightgreen?logo=github)](https://gitlab-mcp.sw.foundation/coverage/)
3
+ [![npm version](https://img.shields.io/npm/v/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![npm downloads](https://img.shields.io/npm/dm/@structured-world/gitlab-mcp)](https://www.npmjs.com/package/@structured-world/gitlab-mcp) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](__REPO_BASE__/LICENSE) [![Release](https://github.com/structured-world/gitlab-mcp/workflows/Release/badge.svg)](https://github.com/structured-world/gitlab-mcp/actions) [![Coverage](https://codecov.io/gh/structured-world/gitlab-mcp/graph/badge.svg)](https://codecov.io/gh/structured-world/gitlab-mcp) [![Coverage Report](https://img.shields.io/badge/Coverage-Live%20Report-brightgreen?logo=github)](https://gitlab-mcp.sw.foundation/coverage/)
4
4
 
5
5
  Advanced GitLab MCP server — __TOOL_COUNT__ CQRS tools exposing __ACTION_COUNT__ GitLab operations across __ENTITY_COUNT__ entity types. The tool catalog and parameters are filtered to each instance's GitLab version, tier, and token scopes, so the agent sees only what the connected instance actually supports.
6
6
 
@@ -8,6 +8,13 @@ Advanced GitLab MCP server — __TOOL_COUNT__ CQRS tools exposing __ACTION_COUNT
8
8
  [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_MCP_Server-007ACC?style=for-the-badge&logo=visualstudiocode&logoColor=white)](vscode:mcp/install?%7B%22name%22%3A%22gitlab-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40structured-world%2Fgitlab-mcp%22%5D%7D)
9
9
  [![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install_MCP_Server-24bfa5?style=for-the-badge&logo=visualstudiocode&logoColor=white)](vscode-insiders:mcp/install?%7B%22name%22%3A%22gitlab-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40structured-world%2Fgitlab-mcp%22%5D%7D)
10
10
 
11
+ ## Packages
12
+
13
+ This is a monorepo with two npm packages:
14
+
15
+ - **[`@structured-world/gitlab-mcp`](https://www.npmjs.com/package/@structured-world/gitlab-mcp)** — the MCP server. In-memory and file OAuth-session storage, no database dependency. This is all most users need.
16
+ - **[`@structured-world/gitlab-mcp-db`](https://www.npmjs.com/package/@structured-world/gitlab-mcp-db)** — optional PostgreSQL/Prisma OAuth-session backend for running multiple replicas behind a load balancer. Enable it with `OAUTH_STORAGE_TYPE=postgresql`; see the [PostgreSQL deployment guide](https://gitlab-mcp.sw.foundation/deployment/docker-postgres) for the full setup.
17
+
11
18
  ## Quick Start
12
19
 
13
20
  ```json
@@ -154,13 +161,13 @@ The server handles GitLab connectivity issues gracefully:
154
161
 
155
162
  ## Contributing
156
163
 
157
- See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, testing, and PR guidelines.
164
+ See [CONTRIBUTING.md](__REPO_BASE__/CONTRIBUTING.md) for development setup, testing, and PR guidelines.
158
165
 
159
166
  ## Support the Project
160
167
 
161
168
  <div align="center">
162
169
 
163
- ![USDT TRC-20 Donation QR Code](assets/usdt-qr.svg)
170
+ ![USDT TRC-20 Donation QR Code](__REPO_BASE__/packages/gitlab-mcp/assets/usdt-qr.svg)
164
171
 
165
172
  USDT (TRC-20): `TFDsezHa1cBkoeZT5q2T49Wp66K8t2DmdA`
166
173
 
@@ -168,6 +175,6 @@ USDT (TRC-20): `TFDsezHa1cBkoeZT5q2T49Wp66K8t2DmdA`
168
175
 
169
176
  ## License
170
177
 
171
- Apache License 2.0 — see [LICENSE](LICENSE) for details.
178
+ Apache License 2.0 — see [LICENSE](__REPO_BASE__/LICENSE) for details.
172
179
 
173
- Based on [zereight/gitlab-mcp](https://github.com/zereight/gitlab-mcp) (MIT). See [LICENSE.MIT](LICENSE.MIT).
180
+ Based on [zereight/gitlab-mcp](https://github.com/zereight/gitlab-mcp) (MIT). See [LICENSE.MIT](__REPO_BASE__/LICENSE.MIT).
@@ -0,0 +1,8 @@
1
+ import type { JobState, WatchEvent } from './watch';
2
+ export declare function parseToolResult(result: unknown): unknown;
3
+ export declare function parseJobs(result: unknown): JobState[];
4
+ export declare function parseDeployments(result: unknown): JobState[];
5
+ export declare function formatEvent(event: WatchEvent): {
6
+ content: string;
7
+ meta: Record<string, string>;
8
+ };
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseToolResult = parseToolResult;
37
+ exports.parseJobs = parseJobs;
38
+ exports.parseDeployments = parseDeployments;
39
+ exports.formatEvent = formatEvent;
40
+ const z = __importStar(require("zod"));
41
+ const JobSchema = z.object({
42
+ id: z.number(),
43
+ name: z.string(),
44
+ stage: z.string(),
45
+ status: z.string(),
46
+ });
47
+ const DeploymentSchema = z.object({
48
+ id: z.number(),
49
+ status: z.string(),
50
+ environment: z.object({ name: z.string() }).optional(),
51
+ });
52
+ function parseToolResult(result) {
53
+ if (result && typeof result === 'object' && 'content' in result) {
54
+ const content = result.content;
55
+ const text = Array.isArray(content) ? content.find((c) => c.type === 'text')?.text : undefined;
56
+ if (typeof text === 'string') {
57
+ try {
58
+ return JSON.parse(text);
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
64
+ }
65
+ return result;
66
+ }
67
+ function parseJobs(result) {
68
+ const data = parseToolResult(result);
69
+ if (!Array.isArray(data))
70
+ return [];
71
+ const out = [];
72
+ for (const item of data) {
73
+ const parsed = JobSchema.safeParse(item);
74
+ if (parsed.success)
75
+ out.push(parsed.data);
76
+ }
77
+ return out;
78
+ }
79
+ function parseDeployments(result) {
80
+ const data = parseToolResult(result);
81
+ if (!Array.isArray(data))
82
+ return [];
83
+ const out = [];
84
+ for (const item of data) {
85
+ const parsed = DeploymentSchema.safeParse(item);
86
+ if (parsed.success) {
87
+ out.push({
88
+ id: parsed.data.id,
89
+ name: parsed.data.environment?.name ?? `deployment-${parsed.data.id}`,
90
+ stage: 'deploy',
91
+ status: parsed.data.status,
92
+ });
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+ function formatEvent(event) {
98
+ const { target, pipelineState, jobs, transitions, terminal } = event;
99
+ const jobsLine = jobs.map((j) => `${j.name}:${j.status}`).join(' ');
100
+ const label = target.kind === 'deployment' ? 'Deployment' : 'Pipeline';
101
+ const idKey = target.kind === 'deployment' ? 'deployment_id' : 'pipeline_id';
102
+ const content = terminal
103
+ ? `${label} #${target.id} (project ${target.projectId}) finished: ${pipelineState}. Jobs: ${jobsLine}`
104
+ : `${label} #${target.id} (project ${target.projectId}) ${transitions
105
+ .map((t) => `${t.name} ${t.from ?? 'new'}->${t.to}`)
106
+ .join(', ')}. Now: ${jobsLine}`;
107
+ const meta = {
108
+ [idKey]: String(target.id),
109
+ project_id: target.projectId,
110
+ kind: target.kind,
111
+ state: pipelineState,
112
+ terminal: String(terminal),
113
+ };
114
+ return { content, meta };
115
+ }
116
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+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I,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export interface ForwardPolicy {
2
+ isRead: (name: string) => boolean;
3
+ isConnected: () => boolean;
4
+ waitForConnection: () => Promise<void>;
5
+ call: (name: string, args: unknown) => Promise<unknown>;
6
+ }
7
+ export declare function forwardWithPolicy(policy: ForwardPolicy, name: string, args: unknown): Promise<unknown>;
8
+ export declare function isReadCall(name: string): boolean;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.forwardWithPolicy = forwardWithPolicy;
4
+ exports.isReadCall = isReadCall;
5
+ async function forwardWithPolicy(policy, name, args) {
6
+ if (!policy.isConnected()) {
7
+ await policy.waitForConnection();
8
+ }
9
+ try {
10
+ return await policy.call(name, args);
11
+ }
12
+ catch (err) {
13
+ if (policy.isRead(name)) {
14
+ await policy.waitForConnection();
15
+ return await policy.call(name, args);
16
+ }
17
+ throw err;
18
+ }
19
+ }
20
+ function isReadCall(name) {
21
+ return name.startsWith('browse_') || name.startsWith('get_') || name.startsWith('list_');
22
+ }
23
+ //# sourceMappingURL=forwarding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forwarding.js","sourceRoot":"","sources":["../../../src/channel-gateway/forwarding.ts"],"names":[],"mappings":";;AAmCA,8CAmBC;AAGD,gCAEC;AAxBM,KAAK,UAAU,iBAAiB,CACrC,MAAqB,EACrB,IAAY,EACZ,IAAa;IAGb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;QAC1B,MAAM,MAAM,CAAC,iBAAiB,EAAE,CAAC;IACnC,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAEb,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,MAAM,CAAC,iBAAiB,EAAE,CAAC;YACjC,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvC,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAGD,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,35 @@
1
+ export interface GatewayConfig {
2
+ downstreamCommand: string;
3
+ downstreamArgs: string[];
4
+ downstreamEnv?: Record<string, string>;
5
+ pollMs?: number;
6
+ maxBackoffMs?: number;
7
+ maxQueued?: number;
8
+ connectTimeoutMs?: number;
9
+ name?: string;
10
+ version?: string;
11
+ }
12
+ export declare class ChannelGateway {
13
+ private readonly config;
14
+ private readonly server;
15
+ private client;
16
+ private transport?;
17
+ private readonly interceptor;
18
+ private connected;
19
+ private reconnecting;
20
+ private closing;
21
+ private pendingWaiters;
22
+ constructor(config: GatewayConfig);
23
+ start(): Promise<void>;
24
+ stop(): Promise<void>;
25
+ private newClient;
26
+ private registerHandlers;
27
+ private connectDownstream;
28
+ private handleDownstreamClose;
29
+ private waitForConnection;
30
+ private forward;
31
+ private callDownstream;
32
+ private emit;
33
+ private notifyLink;
34
+ private sleep;
35
+ }
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChannelGateway = void 0;
4
+ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
5
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
6
+ const index_js_2 = require("@modelcontextprotocol/sdk/server/index.js");
7
+ const stdio_js_2 = require("@modelcontextprotocol/sdk/server/stdio.js");
8
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
9
+ const interceptor_1 = require("./interceptor");
10
+ const format_1 = require("./format");
11
+ const forwarding_1 = require("./forwarding");
12
+ const CHANNEL_NOTIFICATION = 'notifications/claude/channel';
13
+ class ChannelGateway {
14
+ config;
15
+ server;
16
+ client;
17
+ transport;
18
+ interceptor;
19
+ connected = false;
20
+ reconnecting = false;
21
+ closing = false;
22
+ pendingWaiters = 0;
23
+ constructor(config) {
24
+ this.config = config;
25
+ this.server = new index_js_2.Server({ name: config.name ?? 'gitlab-ci-gateway', version: config.version ?? '0.1.0' }, {
26
+ capabilities: {
27
+ tools: {},
28
+ experimental: { 'claude/channel': {} },
29
+ },
30
+ instructions: 'Forwards the full gitlab-mcp tool catalog. When a CI pipeline/job is ' +
31
+ 'still running, it is watched in the background and a <channel> event ' +
32
+ 'is pushed on each state change and on completion.',
33
+ });
34
+ this.client = this.newClient();
35
+ this.interceptor = new interceptor_1.Interceptor({
36
+ forward: (name, args) => this.forward(name, args),
37
+ emit: (event) => this.emit(event),
38
+ pollMs: config.pollMs,
39
+ });
40
+ this.registerHandlers();
41
+ }
42
+ async start() {
43
+ await this.connectDownstream();
44
+ await this.server.connect(new stdio_js_2.StdioServerTransport());
45
+ }
46
+ async stop() {
47
+ this.closing = true;
48
+ this.interceptor.shutdown();
49
+ await this.transport?.close().catch(() => { });
50
+ }
51
+ newClient() {
52
+ return new index_js_1.Client({ name: this.config.name ?? 'gitlab-ci-gateway', version: '0.1.0' });
53
+ }
54
+ registerHandlers() {
55
+ this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
56
+ const { tools } = (await (0, forwarding_1.forwardWithPolicy)({
57
+ isRead: () => true,
58
+ isConnected: () => this.connected,
59
+ waitForConnection: () => this.waitForConnection(),
60
+ call: () => this.client.listTools(),
61
+ }, 'tools/list', undefined));
62
+ return { tools };
63
+ });
64
+ this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
65
+ const { name, arguments: args } = request.params;
66
+ return (await this.interceptor.handleCall(name, args ?? {}));
67
+ });
68
+ }
69
+ async connectDownstream() {
70
+ const maxBackoff = this.config.maxBackoffMs ?? 30_000;
71
+ let backoff = 500;
72
+ for (;;) {
73
+ if (this.closing)
74
+ return;
75
+ try {
76
+ this.transport = new stdio_js_1.StdioClientTransport({
77
+ command: this.config.downstreamCommand,
78
+ args: this.config.downstreamArgs,
79
+ env: this.config.downstreamEnv,
80
+ });
81
+ this.transport.onclose = () => this.handleDownstreamClose();
82
+ this.client = this.newClient();
83
+ await this.client.connect(this.transport);
84
+ if (this.closing) {
85
+ await this.transport.close().catch(() => { });
86
+ return;
87
+ }
88
+ this.connected = true;
89
+ if (this.reconnecting)
90
+ this.notifyLink('restored');
91
+ return;
92
+ }
93
+ catch {
94
+ if (this.closing)
95
+ return;
96
+ await this.sleep(backoff);
97
+ backoff = Math.min(backoff * 2, maxBackoff);
98
+ }
99
+ }
100
+ }
101
+ handleDownstreamClose() {
102
+ this.connected = false;
103
+ if (this.closing || this.reconnecting)
104
+ return;
105
+ this.reconnecting = true;
106
+ this.notifyLink('lost');
107
+ void this.connectDownstream().finally(() => {
108
+ this.reconnecting = false;
109
+ });
110
+ }
111
+ async waitForConnection() {
112
+ if (this.connected)
113
+ return;
114
+ const maxQueued = this.config.maxQueued ?? 100;
115
+ if (this.pendingWaiters >= maxQueued) {
116
+ throw new Error(`downstream unavailable: request buffer full (${maxQueued})`);
117
+ }
118
+ this.pendingWaiters++;
119
+ try {
120
+ const deadline = Date.now() + (this.config.connectTimeoutMs ?? 30_000);
121
+ while (!this.connected && !this.closing && Date.now() < deadline) {
122
+ await this.sleep(100);
123
+ }
124
+ if (!this.connected) {
125
+ throw new Error('downstream unavailable: reconnect timed out');
126
+ }
127
+ }
128
+ finally {
129
+ this.pendingWaiters--;
130
+ }
131
+ }
132
+ forward(name, args) {
133
+ return (0, forwarding_1.forwardWithPolicy)({
134
+ isRead: forwarding_1.isReadCall,
135
+ isConnected: () => this.connected,
136
+ waitForConnection: () => this.waitForConnection(),
137
+ call: (n, a) => this.callDownstream(n, a),
138
+ }, name, args);
139
+ }
140
+ async callDownstream(name, args) {
141
+ return await this.client.callTool({
142
+ name,
143
+ arguments: (args ?? {}),
144
+ });
145
+ }
146
+ emit(event) {
147
+ const { content, meta } = (0, format_1.formatEvent)(event);
148
+ void this.server.notification({ method: CHANNEL_NOTIFICATION, params: { content, meta } });
149
+ }
150
+ notifyLink(state) {
151
+ const content = state === 'lost'
152
+ ? 'gitlab-mcp link lost - reconnecting; reads will retry, writes will surface errors'
153
+ : 'gitlab-mcp link restored';
154
+ void this.server.notification({
155
+ method: CHANNEL_NOTIFICATION,
156
+ params: { content, meta: { kind: 'link', state } },
157
+ });
158
+ }
159
+ sleep(ms) {
160
+ return new Promise((r) => setTimeout(r, ms));
161
+ }
162
+ }
163
+ exports.ChannelGateway = ChannelGateway;
164
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../../src/channel-gateway/gateway.ts"],"names":[],"mappings":";;;AAYA,wEAAmE;AACnE,wEAAiF;AACjF,wEAAmE;AACnE,wEAAiF;AACjF,iEAI4C;AAC5C,+CAA4C;AAC5C,qCAAuC;AACvC,6CAA6D;AAI7D,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAuB5D,MAAa,cAAc;IAUI;IATZ,MAAM,CAAS;IACxB,MAAM,CAAS;IACf,SAAS,CAAwB;IACxB,WAAW,CAAc;IAClC,SAAS,GAAG,KAAK,CAAC;IAClB,YAAY,GAAG,KAAK,CAAC;IACrB,OAAO,GAAG,KAAK,CAAC;IAChB,cAAc,GAAG,CAAC,CAAC;IAE3B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAM,CACtB,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,mBAAmB,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO,EAAE,EAChF;YACE,YAAY,EAAE;gBACZ,KAAK,EAAE,EA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B,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAW,EAAC,KAAK,CAAC,CAAC;QAE7C,KAAK,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7F,CAAC;IAGO,UAAU,CAAC,KAA0B;QAC3C,MAAM,OAAO,GACX,KAAK,KAAK,MAAM;YACd,CAAC,CAAC,mFAAmF;YACrF,CAAC,CAAC,0BAA0B,CAAC;QACjC,KAAK,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAC5B,MAAM,EAAE,oBAAoB;YAC5B,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;SACnD,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;CACF;AA3LD,wCA2LC"}
@@ -0,0 +1,19 @@
1
+ import { type WatchEvent } from './watch';
2
+ export interface InterceptorDeps {
3
+ forward: (name: string, args: unknown) => Promise<unknown>;
4
+ emit: (event: WatchEvent) => void;
5
+ pollMs?: number;
6
+ maxDurationMs?: number;
7
+ }
8
+ export declare function extractProjectId(args: unknown): string;
9
+ export declare class Interceptor {
10
+ private readonly deps;
11
+ private readonly watches;
12
+ private readonly pollMs;
13
+ private readonly maxDurationMs;
14
+ constructor(deps: InterceptorDeps);
15
+ get activeWatches(): number;
16
+ private pollJobs;
17
+ handleCall(name: string, args: unknown): Promise<unknown>;
18
+ shutdown(): void;
19
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Interceptor = void 0;
4
+ exports.extractProjectId = extractProjectId;
5
+ const watch_1 = require("./watch");
6
+ const format_1 = require("./format");
7
+ function extractProjectId(args) {
8
+ if (args && typeof args === 'object') {
9
+ const p = args.project_id;
10
+ if (typeof p === 'string')
11
+ return p;
12
+ if (typeof p === 'number')
13
+ return String(p);
14
+ }
15
+ return '';
16
+ }
17
+ class Interceptor {
18
+ deps;
19
+ watches;
20
+ pollMs;
21
+ maxDurationMs;
22
+ constructor(deps) {
23
+ this.deps = deps;
24
+ this.pollMs = deps.pollMs ?? 10_000;
25
+ this.maxDurationMs = deps.maxDurationMs ?? 3_600_000;
26
+ this.watches = new watch_1.WatchManager({
27
+ pollJobs: (t) => this.pollJobs(t),
28
+ emit: deps.emit,
29
+ onError: (t, error) => {
30
+ process.stderr.write(`[channel-gateway] watch ${watch_1.WatchManager.key(t)} stopped on poll error: ${String(error)}\n`);
31
+ },
32
+ });
33
+ }
34
+ get activeWatches() {
35
+ return this.watches.size;
36
+ }
37
+ async pollJobs(target) {
38
+ if (target.kind === 'deployment') {
39
+ const result = await this.deps.forward('browse_environments', {
40
+ action: 'list_deployments',
41
+ project_id: target.projectId,
42
+ order_by: 'id',
43
+ sort: 'desc',
44
+ });
45
+ return (0, format_1.parseDeployments)(result).filter((d) => d.id === target.id);
46
+ }
47
+ const result = await this.deps.forward('browse_pipelines', {
48
+ action: 'jobs',
49
+ project_id: target.projectId,
50
+ pipeline_id: target.id,
51
+ });
52
+ return (0, format_1.parseJobs)(result);
53
+ }
54
+ async handleCall(name, args) {
55
+ const result = await this.deps.forward(name, args);
56
+ const target = (0, watch_1.detectWatchable)(extractProjectId(args), (0, format_1.parseToolResult)(result));
57
+ if (target && !this.watches.has(target)) {
58
+ this.watches
59
+ .watch(target, { pollMs: this.pollMs, maxDurationMs: this.maxDurationMs })
60
+ .catch((error) => {
61
+ process.stderr.write(`[channel-gateway] watch ${watch_1.WatchManager.key(target)} failed: ${String(error)}\n`);
62
+ });
63
+ }
64
+ return result;
65
+ }
66
+ shutdown() {
67
+ this.watches.cancelAll();
68
+ }
69
+ }
70
+ exports.Interceptor = Interceptor;
71
+ //# sourceMappingURL=interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../../src/channel-gateway/interceptor.ts"],"names":[],"mappings":";;;AA6BA,4CAOC;AA7BD,mCAMiB;AACjB,qCAAwE;AAexE,SAAgB,gBAAgB,CAAC,IAAa;IAC5C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,CAAC,GAAI,IAAgC,CAAC,UAAU,CAAC;QACvD,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC;QACpC,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAa,WAAW;IAKO;IAJZ,OAAO,CAAe;IACtB,MAAM,CAAS;IACf,aAAa,CAAS;IAEvC,YAA6B,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,SAAS,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,oBAAY,CAAC;YAC9B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACjC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,2BAA2B,oBAAY,CAAC,GAAG,CAAC,CAAC,CAAC,2BAA2B,MAAM,CAAC,KAAK,CAAC,IAAI,CAC3F,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAGD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AC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;iBACzE,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,2BAA2B,oBAAY,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,MAAM,CAAC,KAAK,CAAC,IAAI,CACjF,CAAC;YACJ,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAGD,QAAQ;QACN,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;IAC3B,CAAC;CACF;AA3ED,kCA2EC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const node_path_1 = require("node:path");
5
+ const gateway_1 = require("./gateway");
6
+ function cleanEnv(env) {
7
+ const out = {};
8
+ for (const [k, v] of Object.entries(env))
9
+ if (typeof v === 'string')
10
+ out[k] = v;
11
+ return out;
12
+ }
13
+ const MIN_POLL_MS = 1_000;
14
+ const DEFAULT_POLL_MS = 10_000;
15
+ function parsePollMs(raw) {
16
+ if (raw === undefined)
17
+ return DEFAULT_POLL_MS;
18
+ const n = Number(raw);
19
+ return Number.isFinite(n) && n >= MIN_POLL_MS ? n : DEFAULT_POLL_MS;
20
+ }
21
+ async function main() {
22
+ const args = process.env.GATEWAY_DOWNSTREAM_ARGS
23
+ ? process.env.GATEWAY_DOWNSTREAM_ARGS.split(' ').filter(Boolean)
24
+ : [(0, node_path_1.join)(__dirname, '..', 'main.js'), 'stdio'];
25
+ const gateway = new gateway_1.ChannelGateway({
26
+ downstreamCommand: process.env.GATEWAY_DOWNSTREAM_COMMAND ?? 'node',
27
+ downstreamArgs: args,
28
+ downstreamEnv: cleanEnv(process.env),
29
+ pollMs: parsePollMs(process.env.GATEWAY_POLL_MS),
30
+ });
31
+ const stop = () => {
32
+ void gateway.stop().finally(() => process.exit(0));
33
+ };
34
+ process.on('SIGINT', stop);
35
+ process.on('SIGTERM', stop);
36
+ await gateway.start();
37
+ }
38
+ main().catch((err) => {
39
+ process.stderr.write(`channel-gateway failed: ${String(err)}\n`);
40
+ process.exit(1);
41
+ });
42
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/channel-gateway/main.ts"],"names":[],"mappings":";;;AAcA,yCAAiC;AACjC,uCAA2C;AAG3C,SAAS,QAAQ,CAAC,GAAsB;IACtC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAChF,OAAO,GAAG,CAAC;AACb,CAAC;AAGD,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,eAAe,GAAG,MAAM,CAAC;AAO/B,SAAS,WAAW,CAAC,GAAuB;IAC1C,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC;IAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;AACtE,CAAC;AAED,KAAK,UAAU,IAAI;IAGjB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB;QAC9C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;QAChE,CAAC,CAAC,CAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,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