@zereight/mcp-gitlab 1.0.77 → 2.0.2

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.
@@ -0,0 +1,103 @@
1
+ import { config } from "./config.js";
2
+ import nodeFetch from "node-fetch";
3
+ import { SocksProxyAgent } from "socks-proxy-agent";
4
+ import { HttpsProxyAgent } from "https-proxy-agent";
5
+ import { HttpProxyAgent } from "http-proxy-agent";
6
+ import { Agent } from "http";
7
+ import { Agent as HttpsAgent } from "https";
8
+ import { readFileSync } from "fs";
9
+ import fetchCookie from "fetch-cookie";
10
+ export class GitlabSession {
11
+ authToken;
12
+ cookieJar;
13
+ defaultConfig;
14
+ defaultHeaders;
15
+ constructor(authToken, cookieJar) {
16
+ this.authToken = authToken;
17
+ this.cookieJar = cookieJar;
18
+ // Configure proxy agents if proxies are set
19
+ let httpAgent = undefined;
20
+ let httpsAgent = undefined;
21
+ let sslOptions = undefined;
22
+ if (config.NODE_TLS_REJECT_UNAUTHORIZED === "0") {
23
+ sslOptions = { rejectUnauthorized: false };
24
+ }
25
+ else if (config.GITLAB_CA_CERT_PATH) {
26
+ const ca = readFileSync(config.GITLAB_CA_CERT_PATH);
27
+ sslOptions = { ca };
28
+ }
29
+ if (config.HTTP_PROXY) {
30
+ if (config.HTTP_PROXY.startsWith("socks")) {
31
+ httpAgent = new SocksProxyAgent(config.HTTP_PROXY);
32
+ }
33
+ else {
34
+ httpAgent = new HttpProxyAgent(config.HTTP_PROXY);
35
+ }
36
+ }
37
+ if (config.HTTPS_PROXY) {
38
+ if (config.HTTPS_PROXY.startsWith("socks")) {
39
+ httpsAgent = new SocksProxyAgent(config.HTTPS_PROXY);
40
+ }
41
+ else {
42
+ httpsAgent = new HttpsProxyAgent(config.HTTPS_PROXY, sslOptions);
43
+ }
44
+ }
45
+ httpsAgent = httpsAgent || new HttpsAgent(sslOptions);
46
+ httpAgent = httpAgent || new Agent();
47
+ this.defaultHeaders = {
48
+ Accept: "application/json",
49
+ "Content-Type": "application/json",
50
+ };
51
+ if (config.IS_OLD) {
52
+ this.defaultHeaders["Private-Token"] = `${this.authToken}`;
53
+ }
54
+ else {
55
+ this.defaultHeaders["Authorization"] = `Bearer ${this.authToken}`;
56
+ }
57
+ this.defaultConfig = {
58
+ headers: this.defaultHeaders,
59
+ agent: (parsedUrl) => {
60
+ if (parsedUrl.protocol === "https:") {
61
+ return httpsAgent;
62
+ }
63
+ return httpAgent;
64
+ },
65
+ };
66
+ }
67
+ async ensureSessionForCookieJar() {
68
+ if (!this.cookieJar || !config.GITLAB_AUTH_COOKIE_PATH)
69
+ return;
70
+ // Extract the base URL from GITLAB_API_URL
71
+ const apiUrl = new URL(config.GITLAB_API_URL);
72
+ const baseUrl = `${apiUrl.protocol}//${apiUrl.hostname}`;
73
+ // Check if we already have GitLab session cookies
74
+ const gitlabCookies = this.cookieJar.getCookiesSync(baseUrl);
75
+ const hasSessionCookie = gitlabCookies.some(cookie => cookie.key === '_gitlab_session' || cookie.key === 'remember_user_token');
76
+ if (!hasSessionCookie) {
77
+ try {
78
+ // Establish session with a lightweight request
79
+ await fetch(`${config.GITLAB_API_URL}/user`, {
80
+ redirect: 'follow'
81
+ }).catch(() => {
82
+ // Ignore errors - the important thing is that cookies get set during redirects
83
+ });
84
+ // Small delay to ensure cookies are fully processed
85
+ await new Promise(resolve => setTimeout(resolve, 100));
86
+ }
87
+ catch (error) {
88
+ // Ignore session establishment errors
89
+ }
90
+ }
91
+ }
92
+ async fetch(url, init) {
93
+ const fullInit = { ...this.defaultConfig, ...init, headers: {
94
+ ...this.defaultHeaders,
95
+ ...init?.headers
96
+ } };
97
+ let fetcher = nodeFetch;
98
+ if (this.cookieJar) {
99
+ fetcher = fetchCookie(fetcher, this.cookieJar);
100
+ }
101
+ return fetcher(url, fullInit);
102
+ }
103
+ }
@@ -0,0 +1,11 @@
1
+ import { pino } from 'pino';
2
+ export const logger = pino({
3
+ level: process.env.LOG_LEVEL || 'info',
4
+ transport: {
5
+ target: 'pino-pretty',
6
+ options: {
7
+ colorize: true,
8
+ levelFirst: true,
9
+ },
10
+ },
11
+ });