@zereight/mcp-gitlab 2.0.32 → 2.0.34

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
@@ -336,7 +336,7 @@ docker run -i --rm \
336
336
  - `GITLAB_OAUTH_REDIRECT_URI`: The OAuth callback URL. Default: `http://127.0.0.1:8888/callback`
337
337
  - `GITLAB_OAUTH_TOKEN_PATH`: Custom path to store the OAuth token. Default: `~/.gitlab-mcp-token.json`
338
338
  - `REMOTE_AUTHORIZATION`: When set to 'true', enables remote per-session authorization via HTTP headers. In this mode:
339
- - The server accepts GitLab PAT tokens from HTTP headers (`Authorization: Bearer <token>` or `Private-Token: <token>`) on a per-session basis
339
+ - The server accepts GitLab PAT tokens from HTTP headers (`Authorization: Bearer <token>`, `Private-Token: <token>` or `Job-Token: <token>`) on a per-session basis
340
340
  - `GITLAB_PERSONAL_ACCESS_TOKEN` environment variable is **not required** and ignored
341
341
  - Only works with **Streamable HTTP transport** (`STREAMABLE_HTTP=true`) because session management was already handled by the transport layer
342
342
  - **SSE transport is disabled** - attempting to use SSE with remote authorization will cause the server to exit with an error
@@ -400,6 +400,7 @@ docker run -i --rm \
400
400
  - `SSE`: When set to 'true', enables the Server-Sent Events transport.
401
401
  - `STREAMABLE_HTTP`: When set to 'true', enables the Streamable HTTP transport. If both **SSE** and **STREAMABLE_HTTP** are set to 'true', the server will prioritize Streamable HTTP over SSE transport.
402
402
  - `GITLAB_COMMIT_FILES_PER_PAGE`: The number of files per page that GitLab returns for commit diffs. This value should match the server-side GitLab setting. Adjust this if your GitLab instance uses a custom per-page value for commit diffs.
403
+ - `GITLAB_REPO_FILE_ENCODING`: Encoding for repository file create/update and related commit payloads sent to the GitLab API. Use `text` (default) or `base64`. Equivalent CLI: `--repo-file-encoding=text|base64`.
403
404
 
404
405
  #### Performance & Security Configuration
405
406
 
@@ -407,6 +408,16 @@ docker run -i --rm \
407
408
  - `MAX_SESSIONS`: Maximum number of concurrent sessions allowed. Default: `1000`. Valid range: 1-10000. When limit is reached, new connections are rejected with HTTP 503.
408
409
  - `MAX_REQUESTS_PER_MINUTE`: Rate limit per session in requests per minute. Default: `60`. Valid range: 1-1000. Exceeded requests return HTTP 429.
409
410
  - `PORT`: Server port. Default: `3002`. Valid range: 1-65535.
411
+ - `HTTP_PROXY`: HTTP proxy server URL for outgoing requests. Example: `http://proxy.example.com:8080`. Supports HTTP/HTTPS and SOCKS proxies (URLs starting with `socks://` or `socks5://`). CLI arg: `--http-proxy`
412
+ - `HTTPS_PROXY`: HTTPS proxy server URL for outgoing requests. Example: `https://proxy.example.com:8080`. Supports HTTP/HTTPS and SOCKS proxies. CLI arg: `--https-proxy`
413
+ - `NO_PROXY`: Comma-separated list of hosts that should bypass the proxy. Supports:
414
+ - Exact hostname matches (e.g., `localhost`, `gitlab.internal.com`)
415
+ - Domain suffix matches (e.g., `.internal.com` matches any subdomain)
416
+ - IP addresses (e.g., `127.0.0.1`, `192.168.1.1`)
417
+ - Port-specific matches (e.g., `example.com:443`)
418
+ - Wildcard `*` to bypass proxy for all hosts
419
+ - Example: `NO_PROXY=localhost,127.0.0.1,.internal.com`
420
+ - CLI arg: `--no-proxy`
410
421
 
411
422
  #### Monitoring Endpoints
412
423
 
@@ -4,6 +4,64 @@ import { HttpProxyAgent } from "http-proxy-agent";
4
4
  import { HttpsProxyAgent } from "https-proxy-agent";
5
5
  import { SocksProxyAgent } from "socks-proxy-agent";
6
6
  import fs from "fs";
7
+ /**
8
+ * Checks if a URL should bypass the proxy based on NO_PROXY patterns.
9
+ * Supports:
10
+ * - Exact hostname matches (e.g., "localhost", "gitlab.example.com")
11
+ * - Domain suffix matches (e.g., ".example.com" matches "gitlab.example.com")
12
+ * - IP addresses (e.g., "127.0.0.1", "192.168.1.1")
13
+ * - Wildcard "*" to bypass all proxies
14
+ * - Port-specific matches (e.g., "example.com:8080")
15
+ *
16
+ * @param url The URL to check
17
+ * @param noProxy Comma-separated list of patterns from NO_PROXY
18
+ * @returns true if the URL should bypass the proxy, false otherwise
19
+ */
20
+ function shouldBypassProxy(url, noProxy) {
21
+ if (!noProxy) {
22
+ return false;
23
+ }
24
+ // Parse URL to get hostname and port
25
+ let hostname;
26
+ let port;
27
+ let protocol;
28
+ try {
29
+ const parsedUrl = new URL(url);
30
+ hostname = parsedUrl.hostname.toLowerCase();
31
+ protocol = parsedUrl.protocol;
32
+ // Use explicit port if provided, otherwise use default port based on protocol
33
+ port = parsedUrl.port || (protocol === 'https:' ? '443' : '80');
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ // Split NO_PROXY into patterns and trim whitespace
39
+ const patterns = noProxy.split(',').map(p => p.trim().toLowerCase()).filter(p => p.length > 0);
40
+ for (const pattern of patterns) {
41
+ // Wildcard matches everything
42
+ if (pattern === '*') {
43
+ return true;
44
+ }
45
+ // Handle port-specific patterns (e.g., "example.com:8080")
46
+ const [patternHost, patternPort] = pattern.split(':');
47
+ // If pattern specifies a port, check if it matches
48
+ if (patternPort && port !== patternPort) {
49
+ continue;
50
+ }
51
+ // Check for domain suffix match (e.g., ".example.com")
52
+ if (patternHost.startsWith('.')) {
53
+ const suffix = patternHost.substring(1);
54
+ if (hostname === suffix || hostname.endsWith('.' + suffix)) {
55
+ return true;
56
+ }
57
+ }
58
+ // Check for exact hostname match
59
+ else if (hostname === patternHost) {
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ }
7
65
  /**
8
66
  * Manages a pool of HTTP/HTTPS agents for different GitLab API URLs.
9
67
  * This allows the server to efficiently handle requests to multiple GitLab instances
@@ -23,7 +81,7 @@ export class GitLabClientPool {
23
81
  * @returns A `ClientAgents` object containing the configured agents.
24
82
  */
25
83
  createAgentsForUrl(apiUrl) {
26
- const { httpProxy, httpsProxy, rejectUnauthorized, caCertPath } = this.options;
84
+ const { httpProxy, httpsProxy, noProxy, rejectUnauthorized, caCertPath } = this.options;
27
85
  const url = new URL(apiUrl);
28
86
  let sslOptions = {};
29
87
  if (rejectUnauthorized === false) {
@@ -38,10 +96,12 @@ export class GitLabClientPool {
38
96
  throw new Error(`Failed to read CA certificate: ${caCertPath}`);
39
97
  }
40
98
  }
99
+ // Check if this URL should bypass the proxy
100
+ const bypassProxy = shouldBypassProxy(apiUrl, noProxy);
41
101
  let httpAgent;
42
102
  let httpsAgent;
43
- // Configure HTTP agent with proxy if specified
44
- if (httpProxy) {
103
+ // Configure HTTP agent with proxy if specified and not bypassed
104
+ if (httpProxy && !bypassProxy) {
45
105
  httpAgent = httpProxy.startsWith("socks")
46
106
  ? new SocksProxyAgent(httpProxy)
47
107
  : new HttpProxyAgent(httpProxy);
@@ -49,8 +109,8 @@ export class GitLabClientPool {
49
109
  else {
50
110
  httpAgent = new Agent({ keepAlive: true });
51
111
  }
52
- // Configure HTTPS agent with proxy and SSL options if specified
53
- if (httpsProxy) {
112
+ // Configure HTTPS agent with proxy and SSL options if specified and not bypassed
113
+ if (httpsProxy && !bypassProxy) {
54
114
  httpsAgent = httpsProxy.startsWith("socks")
55
115
  // The `as any` cast is used here to bypass a TypeScript type mismatch error.
56
116
  // The `socks-proxy-agent` documentation indicates that TLS options like
@@ -72,6 +132,31 @@ export class GitLabClientPool {
72
132
  * @returns The corresponding `Agent` for the URL's protocol.
73
133
  */
74
134
  getOrCreateAgentForUrl(apiUrl) {
135
+ const agents = this.getOrCreateAgentsForUrl(apiUrl);
136
+ const url = new URL(apiUrl);
137
+ return url.protocol === "https:" ? agents.httpsAgent : agents.httpAgent;
138
+ }
139
+ /**
140
+ * Returns an agent-selection function for use with node-fetch's `agent` option.
141
+ * The returned function picks the correct HTTP or HTTPS agent based on the
142
+ * request URL's protocol. This is critical for self-hosted GitLab instances
143
+ * where the server may redirect between HTTP and HTTPS (e.g., when
144
+ * `external_url` differs from the actual internal protocol).
145
+ * @param apiUrl The base API URL used to look up or create the agent pair.
146
+ * @returns A function `(parsedURL: URL) => Agent` suitable for node-fetch.
147
+ */
148
+ getAgentFunctionForUrl(apiUrl) {
149
+ const agents = this.getOrCreateAgentsForUrl(apiUrl);
150
+ return (parsedURL) => {
151
+ return parsedURL.protocol === "https:" ? agents.httpsAgent : agents.httpAgent;
152
+ };
153
+ }
154
+ /**
155
+ * Ensures agents exist for the given API URL and returns the pair.
156
+ * @param apiUrl The full URL of the request.
157
+ * @returns The `ClientAgents` (both HTTP and HTTPS agents) for the URL.
158
+ */
159
+ getOrCreateAgentsForUrl(apiUrl) {
75
160
  const url = new URL(apiUrl);
76
161
  const baseUrl = `${url.protocol}//${url.host}${url.pathname.substring(0, url.pathname.lastIndexOf('/api/v4') + '/api/v4'.length)}`;
77
162
  if (!this.clients.has(baseUrl)) {
@@ -86,7 +171,7 @@ export class GitLabClientPool {
86
171
  // This should not happen given the logic above, but it satisfies TypeScript
87
172
  throw new Error(`Failed to create or get client for URL: ${baseUrl}`);
88
173
  }
89
- return url.protocol === "https:" ? agents.httpsAgent : agents.httpAgent;
174
+ return agents;
90
175
  }
91
176
  /**
92
177
  * Retrieves the client agents for a specific base API URL.
@@ -110,4 +195,21 @@ export class GitLabClientPool {
110
195
  }
111
196
  return this.clients.get(defaultUrl);
112
197
  }
198
+ /**
199
+ * Destroy all pooled agents and clear pool state.
200
+ * This should be called on graceful shutdown so sockets are closed
201
+ * and the process can exit cleanly.
202
+ */
203
+ closeAll() {
204
+ for (const [, agents] of this.clients) {
205
+ const destroyIfSupported = (agent) => {
206
+ if (agent && typeof agent.destroy === "function") {
207
+ agent.destroy();
208
+ }
209
+ };
210
+ destroyIfSupported(agents.httpAgent);
211
+ destroyIfSupported(agents.httpsAgent);
212
+ }
213
+ this.clients.clear();
214
+ }
113
215
  }