gitlab-mcp 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/build/index.js +4 -45
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -19,11 +19,12 @@ import { GitLabForkSchema, GitLabReferenceSchema, GitLabRepositorySchema, GitLab
19
19
  GitLabDiscussionNoteSchema, // Added
20
20
  GitLabDiscussionSchema, UpdateMergeRequestNoteSchema, // Added
21
21
  ListMergeRequestDiscussionsSchema, } from "./schemas.js";
22
- // Load .env from the current working directory
23
- config({ path: path.resolve(process.cwd(), ".env") });
24
22
  const argv = yargs(hideBin(process.argv)).argv;
25
23
  const isSSE = argv.mode === "sse";
26
24
  const port = argv.port ?? 3044;
25
+ const envFile = argv.envFile ?? ".env";
26
+ // Load .env from the current working directory
27
+ config({ path: envFile ?? path.resolve(process.cwd(), ".env") });
27
28
  /**
28
29
  * Read version from package.json
29
30
  */
@@ -271,7 +272,6 @@ if (!GITLAB_PERSONAL_ACCESS_TOKEN) {
271
272
  }
272
273
  /**
273
274
  * Common headers for GitLab API requests
274
- * GitLab API 공통 헤더 (Common headers for GitLab API)
275
275
  */
276
276
  const DEFAULT_HEADERS = {
277
277
  Accept: "application/json",
@@ -280,7 +280,6 @@ const DEFAULT_HEADERS = {
280
280
  };
281
281
  /**
282
282
  * Utility function for handling GitLab API errors
283
- * API 에러 처리를 위한 유틸리티 함수 (Utility function for handling API errors)
284
283
  *
285
284
  * @param {import("node-fetch").Response} response - The response from GitLab API
286
285
  * @throws {Error} Throws an error with response details if the request failed
@@ -303,14 +302,12 @@ async function handleGitLabError(response) {
303
302
  }
304
303
  /**
305
304
  * Create a fork of a GitLab project
306
- * 프로젝트 포크 생성 (Create a project fork)
307
305
  *
308
306
  * @param {string} projectId - The ID or URL-encoded path of the project
309
307
  * @param {string} [namespace] - The namespace to fork the project to
310
308
  * @returns {Promise<GitLabFork>} The created fork
311
309
  */
312
310
  async function forkProject(projectId, namespace) {
313
- // API 엔드포인트 URL 생성
314
311
  const url = new URL(`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/fork`);
315
312
  if (namespace) {
316
313
  url.searchParams.append("namespace", namespace);
@@ -319,7 +316,6 @@ async function forkProject(projectId, namespace) {
319
316
  method: "POST",
320
317
  headers: DEFAULT_HEADERS,
321
318
  });
322
- // 이미 존재하는 프로젝트인 경우 처리
323
319
  if (response.status === 409) {
324
320
  throw new Error("Project already exists in the target namespace");
325
321
  }
@@ -329,7 +325,6 @@ async function forkProject(projectId, namespace) {
329
325
  }
330
326
  /**
331
327
  * Create a new branch in a GitLab project
332
- * 새로운 브랜치 생성 (Create a new branch)
333
328
  *
334
329
  * @param {string} projectId - The ID or URL-encoded path of the project
335
330
  * @param {z.infer<typeof CreateBranchOptionsSchema>} options - Branch creation options
@@ -350,7 +345,6 @@ async function createBranch(projectId, options) {
350
345
  }
351
346
  /**
352
347
  * Get the default branch for a GitLab project
353
- * 프로젝트의 기본 브랜치 조회 (Get the default branch of a project)
354
348
  *
355
349
  * @param {string} projectId - The ID or URL-encoded path of the project
356
350
  * @returns {Promise<string>} The name of the default branch
@@ -366,7 +360,6 @@ async function getDefaultBranchRef(projectId) {
366
360
  }
367
361
  /**
368
362
  * Get the contents of a file from a GitLab project
369
- * 파일 내용 조회 (Get file contents)
370
363
  *
371
364
  * @param {string} projectId - The ID or URL-encoded path of the project
372
365
  * @param {string} filePath - The path of the file to get
@@ -375,7 +368,6 @@ async function getDefaultBranchRef(projectId) {
375
368
  */
376
369
  async function getFileContents(projectId, filePath, ref) {
377
370
  const encodedPath = encodeURIComponent(filePath);
378
- // ref가 없는 경우 default branch를 가져옴
379
371
  if (!ref) {
380
372
  ref = await getDefaultBranchRef(projectId);
381
373
  }
@@ -384,14 +376,12 @@ async function getFileContents(projectId, filePath, ref) {
384
376
  const response = await fetch(url.toString(), {
385
377
  headers: DEFAULT_HEADERS,
386
378
  });
387
- // 파일을 찾을 수 없는 경우 처리
388
379
  if (response.status === 404) {
389
380
  throw new Error(`File not found: ${filePath}`);
390
381
  }
391
382
  await handleGitLabError(response);
392
383
  const data = await response.json();
393
384
  const parsedData = GitLabContentSchema.parse(data);
394
- // Base64로 인코딩된 파일 내용을 UTF-8로 디코딩
395
385
  if (!Array.isArray(parsedData) && parsedData.content) {
396
386
  parsedData.content = Buffer.from(parsedData.content, "base64").toString("utf8");
397
387
  parsedData.encoding = "utf8";
@@ -400,7 +390,6 @@ async function getFileContents(projectId, filePath, ref) {
400
390
  }
401
391
  /**
402
392
  * Create a new issue in a GitLab project
403
- * 이슈 생성 (Create an issue)
404
393
  *
405
394
  * @param {string} projectId - The ID or URL-encoded path of the project
406
395
  * @param {z.infer<typeof CreateIssueOptionsSchema>} options - Issue creation options
@@ -419,7 +408,6 @@ async function createIssue(projectId, options) {
419
408
  labels: options.labels?.join(","),
420
409
  }),
421
410
  });
422
- // 잘못된 요청 처리
423
411
  if (response.status === 400) {
424
412
  const errorBody = await response.text();
425
413
  throw new Error(`Invalid request: ${errorBody}`);
@@ -430,7 +418,6 @@ async function createIssue(projectId, options) {
430
418
  }
431
419
  /**
432
420
  * List issues in a GitLab project
433
- * 프로젝트의 이슈 목록 조회
434
421
  *
435
422
  * @param {string} projectId - The ID or URL-encoded path of the project
436
423
  * @param {Object} options - Options for listing issues
@@ -459,7 +446,6 @@ async function listIssues(projectId, options = {}) {
459
446
  }
460
447
  /**
461
448
  * Get a single issue from a GitLab project
462
- * 단일 이슈 조회
463
449
  *
464
450
  * @param {string} projectId - The ID or URL-encoded path of the project
465
451
  * @param {number} issueIid - The internal ID of the project issue
@@ -476,7 +462,6 @@ async function getIssue(projectId, issueIid) {
476
462
  }
477
463
  /**
478
464
  * Update an issue in a GitLab project
479
- * 이슈 업데이트
480
465
  *
481
466
  * @param {string} projectId - The ID or URL-encoded path of the project
482
467
  * @param {number} issueIid - The internal ID of the project issue
@@ -501,7 +486,6 @@ async function updateIssue(projectId, issueIid, options) {
501
486
  }
502
487
  /**
503
488
  * Delete an issue from a GitLab project
504
- * 이슈 삭제
505
489
  *
506
490
  * @param {string} projectId - The ID or URL-encoded path of the project
507
491
  * @param {number} issueIid - The internal ID of the project issue
@@ -517,7 +501,6 @@ async function deleteIssue(projectId, issueIid) {
517
501
  }
518
502
  /**
519
503
  * List all issue links for a specific issue
520
- * 이슈 관계 목록 조회
521
504
  *
522
505
  * @param {string} projectId - The ID or URL-encoded path of the project
523
506
  * @param {number} issueIid - The internal ID of the project issue
@@ -534,7 +517,6 @@ async function listIssueLinks(projectId, issueIid) {
534
517
  }
535
518
  /**
536
519
  * Get a specific issue link
537
- * 특정 이슈 관계 조회
538
520
  *
539
521
  * @param {string} projectId - The ID or URL-encoded path of the project
540
522
  * @param {number} issueIid - The internal ID of the project issue
@@ -552,7 +534,6 @@ async function getIssueLink(projectId, issueIid, issueLinkId) {
552
534
  }
553
535
  /**
554
536
  * Create an issue link between two issues
555
- * 이슈 관계 생성
556
537
  *
557
538
  * @param {string} projectId - The ID or URL-encoded path of the project
558
539
  * @param {number} issueIid - The internal ID of the project issue
@@ -578,7 +559,6 @@ async function createIssueLink(projectId, issueIid, targetProjectId, targetIssue
578
559
  }
579
560
  /**
580
561
  * Delete an issue link
581
- * 이슈 관계 삭제
582
562
  *
583
563
  * @param {string} projectId - The ID or URL-encoded path of the project
584
564
  * @param {number} issueIid - The internal ID of the project issue
@@ -595,7 +575,6 @@ async function deleteIssueLink(projectId, issueIid, issueLinkId) {
595
575
  }
596
576
  /**
597
577
  * Create a new merge request in a GitLab project
598
- * 병합 요청 생성
599
578
  *
600
579
  * @param {string} projectId - The ID or URL-encoded path of the project
601
580
  * @param {z.infer<typeof CreateMergeRequestOptionsSchema>} options - Merge request creation options
@@ -632,7 +611,6 @@ async function createMergeRequest(projectId, options) {
632
611
  }
633
612
  /**
634
613
  * List merge request discussion items
635
- * 병합 요청 토론 목록 조회
636
614
  *
637
615
  * @param {string} projectId - The ID or URL-encoded path of the project
638
616
  * @param {number} mergeRequestIid - The IID of a merge request
@@ -650,7 +628,6 @@ async function listMergeRequestDiscussions(projectId, mergeRequestIid) {
650
628
  }
651
629
  /**
652
630
  * Modify an existing merge request thread note
653
- * 병합 요청 토론 노트 수정
654
631
  *
655
632
  * @param {string} projectId - The ID or URL-encoded path of the project
656
633
  * @param {number} mergeRequestIid - The IID of a merge request
@@ -677,7 +654,6 @@ async function updateMergeRequestNote(projectId, mergeRequestIid, discussionId,
677
654
  }
678
655
  /**
679
656
  * Create or update a file in a GitLab project
680
- * 파일 생성 또는 업데이트
681
657
  *
682
658
  * @param {string} projectId - The ID or URL-encoded path of the project
683
659
  * @param {string} filePath - The path of the file to create or update
@@ -751,7 +727,6 @@ async function createOrUpdateFile(projectId, filePath, content, commitMessage, b
751
727
  }
752
728
  /**
753
729
  * Create a tree structure in a GitLab project repository
754
- * 저장소에 트리 구조 생성
755
730
  *
756
731
  * @param {string} projectId - The ID or URL-encoded path of the project
757
732
  * @param {FileOperation[]} files - Array of file operations
@@ -791,7 +766,6 @@ async function createTree(projectId, files, ref) {
791
766
  }
792
767
  /**
793
768
  * Create a commit in a GitLab project repository
794
- * 저장소에 커밋 생성
795
769
  *
796
770
  * @param {string} projectId - The ID or URL-encoded path of the project
797
771
  * @param {string} message - The commit message
@@ -902,7 +876,6 @@ async function createRepository(options) {
902
876
  }
903
877
  /**
904
878
  * Get merge request details
905
- * MR 조회 함수 (Function to retrieve merge request)
906
879
  *
907
880
  * @param {string} projectId - The ID or URL-encoded path of the project
908
881
  * @param {number} mergeRequestIid - The internal ID of the merge request
@@ -939,7 +912,6 @@ async function getMergeRequestDiffs(projectId, mergeRequestIid, view) {
939
912
  }
940
913
  /**
941
914
  * Update a merge request
942
- * MR 업데이트 함수 (Function to update merge request)
943
915
  *
944
916
  * @param {string} projectId - The ID or URL-encoded path of the project
945
917
  * @param {number} mergeRequestIid - The internal ID of the merge request
@@ -958,7 +930,6 @@ async function updateMergeRequest(projectId, mergeRequestIid, options) {
958
930
  }
959
931
  /**
960
932
  * Create a new note (comment) on an issue or merge request
961
- * 📦 새로운 함수: createNote - 이슈 또는 병합 요청에 노트(댓글)를 추가하는 함수
962
933
  * (New function: createNote - Function to add a note (comment) to an issue or merge request)
963
934
  *
964
935
  * @param {string} projectId - The ID or URL-encoded path of the project
@@ -967,9 +938,7 @@ async function updateMergeRequest(projectId, mergeRequestIid, options) {
967
938
  * @param {string} body - The content of the note
968
939
  * @returns {Promise<any>} The created note
969
940
  */
970
- async function createNote(projectId, noteableType, // 'issue' 또는 'merge_request' 타입 명시
971
- noteableIid, body) {
972
- // ⚙️ 응답 타입은 GitLab API 문서에 따라 조정 가능
941
+ async function createNote(projectId, noteableType, noteableIid, body) {
973
942
  const url = new URL(`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/${noteableType}s/${noteableIid}/notes` // Using plural form (issues/merge_requests) as per GitLab API documentation
974
943
  );
975
944
  const response = await fetch(url.toString(), {
@@ -985,7 +954,6 @@ noteableIid, body) {
985
954
  }
986
955
  /**
987
956
  * List all namespaces
988
- * 사용 가능한 모든 네임스페이스 목록 조회
989
957
  *
990
958
  * @param {Object} options - Options for listing namespaces
991
959
  * @param {string} [options.search] - Search query to filter namespaces
@@ -1013,7 +981,6 @@ async function listNamespaces(options) {
1013
981
  }
1014
982
  /**
1015
983
  * Get details on a namespace
1016
- * 네임스페이스 상세 정보 조회
1017
984
  *
1018
985
  * @param {string} id - The ID or URL-encoded path of the namespace
1019
986
  * @returns {Promise<GitLabNamespace>} The namespace details
@@ -1029,7 +996,6 @@ async function getNamespace(id) {
1029
996
  }
1030
997
  /**
1031
998
  * Verify if a namespace exists
1032
- * 네임스페이스 존재 여부 확인
1033
999
  *
1034
1000
  * @param {string} namespacePath - The path of the namespace to check
1035
1001
  * @param {number} [parentId] - The ID of the parent namespace
@@ -1049,7 +1015,6 @@ async function verifyNamespaceExistence(namespacePath, parentId) {
1049
1015
  }
1050
1016
  /**
1051
1017
  * Get a single project
1052
- * 단일 프로젝트 조회
1053
1018
  *
1054
1019
  * @param {string} projectId - The ID or URL-encoded path of the project
1055
1020
  * @param {Object} options - Options for getting project details
@@ -1078,7 +1043,6 @@ async function getProject(projectId, options = {}) {
1078
1043
  }
1079
1044
  /**
1080
1045
  * List projects
1081
- * 프로젝트 목록 조회
1082
1046
  *
1083
1047
  * @param {Object} options - Options for listing projects
1084
1048
  * @returns {Promise<GitLabProject[]>} List of projects
@@ -1637,7 +1601,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1637
1601
  });
1638
1602
  /**
1639
1603
  * Initialize and run the server
1640
- * 서버 초기화 및 실행
1641
1604
  */
1642
1605
  async function runServer() {
1643
1606
  if (isSSE) {
@@ -1647,10 +1610,6 @@ async function runServer() {
1647
1610
  console.log("Establishing new SSE connection");
1648
1611
  transport = new SSEServerTransport("/messages", res);
1649
1612
  await server.connect(transport);
1650
- server.onclose = async () => {
1651
- await server.close();
1652
- process.exit(0);
1653
- };
1654
1613
  });
1655
1614
  app.post("/messages", async (req, res) => {
1656
1615
  await transport?.handlePostMessage(req, res);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitlab-mcp",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Model Context Protocol server for GitLab integration",
5
5
  "main": "./build/index.js",
6
6
  "type": "module",