gitlab-mcp-setup 1.0.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 ADDED
@@ -0,0 +1,92 @@
1
+ # u-frontend-skills
2
+
3
+
4
+
5
+ ## Getting started
6
+
7
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
+
9
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
+
11
+ ## Add your files
12
+
13
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
15
+
16
+ ```
17
+ cd existing_repo
18
+ git remote add origin https://git.ucloudadmin.com/Leo/u-frontend-skills.git
19
+ git branch -M main
20
+ git push -uf origin main
21
+ ```
22
+
23
+ ## Integrate with your tools
24
+
25
+ - [ ] [Set up project integrations](https://git.ucloudadmin.com/Leo/u-frontend-skills/-/settings/integrations)
26
+
27
+ ## Collaborate with your team
28
+
29
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33
+ - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34
+
35
+ ## Test and Deploy
36
+
37
+ Use the built-in continuous integration in GitLab.
38
+
39
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44
+
45
+ ***
46
+
47
+ # Editing this README
48
+
49
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
+
51
+ ## Suggestions for a good README
52
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
53
+
54
+ ## Name
55
+ Choose a self-explaining name for your project.
56
+
57
+ ## Description
58
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
59
+
60
+ ## Badges
61
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
62
+
63
+ ## Visuals
64
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
65
+
66
+ ## Installation
67
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
68
+
69
+ ## Usage
70
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
71
+
72
+ ## Support
73
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
74
+
75
+ ## Roadmap
76
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
77
+
78
+ ## Contributing
79
+ State if you are open to contributions and what your requirements are for accepting them.
80
+
81
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
82
+
83
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
84
+
85
+ ## Authors and acknowledgment
86
+ Show your appreciation to those who have contributed to the project.
87
+
88
+ ## License
89
+ For open source projects, say how it is licensed.
90
+
91
+ ## Project status
92
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const readline = __importStar(require("readline"));
38
+ const detector_1 = require("./detector");
39
+ const writer_1 = require("./writer");
40
+ const GREEN = '\x1b[32m';
41
+ const YELLOW = '\x1b[33m';
42
+ const RED = '\x1b[31m';
43
+ const CYAN = '\x1b[36m';
44
+ const BOLD = '\x1b[1m';
45
+ const RESET = '\x1b[0m';
46
+ function log(message) {
47
+ console.log(message);
48
+ }
49
+ function success(message) {
50
+ console.log(`${GREEN}✓${RESET} ${message}`);
51
+ }
52
+ function warn(message) {
53
+ console.log(`${YELLOW}⚠${RESET} ${message}`);
54
+ }
55
+ function error(message) {
56
+ console.log(`${RED}✗${RESET} ${message}`);
57
+ }
58
+ function header(message) {
59
+ console.log(`\n${CYAN}${BOLD}${message}${RESET}`);
60
+ }
61
+ function checkNodeVersion() {
62
+ const version = process.version;
63
+ const major = parseInt(version.slice(1).split('.')[0], 10);
64
+ if (major < 14) {
65
+ error(`Node.js 版本过低: ${version}`);
66
+ log(' 请升级到 Node.js 14.0.0 或更高版本');
67
+ return false;
68
+ }
69
+ success(`Node.js ${version}`);
70
+ return true;
71
+ }
72
+ async function prompt(question) {
73
+ const rl = readline.createInterface({
74
+ input: process.stdin,
75
+ output: process.stdout,
76
+ });
77
+ return new Promise((resolve) => {
78
+ rl.question(question, (answer) => {
79
+ rl.close();
80
+ resolve(answer.trim());
81
+ });
82
+ });
83
+ }
84
+ function displayTools(tools) {
85
+ tools.forEach((tool, index) => {
86
+ const status = tool.exists ? `${GREEN}已安装${RESET}` : `${YELLOW}未检测到${RESET}`;
87
+ log(` [${index + 1}] ${tool.name} (${status})`);
88
+ log(` ${tool.configPath}`);
89
+ });
90
+ log(` [${tools.length + 1}] 全部配置`);
91
+ log(` [0] 退出`);
92
+ }
93
+ function displayResults(results) {
94
+ header('[3/3] 配置结果');
95
+ const successful = results.filter(r => r.success);
96
+ const failed = results.filter(r => !r.success);
97
+ successful.forEach(r => {
98
+ success(r.message);
99
+ if (r.backupPath) {
100
+ log(` 原配置已备份到: ${r.backupPath}`);
101
+ }
102
+ });
103
+ failed.forEach(r => {
104
+ error(r.message);
105
+ });
106
+ if (successful.length > 0) {
107
+ header('🎉 配置完成!');
108
+ log('');
109
+ log(' 下一步:');
110
+ log(' 1. 重启你的 AI 工具');
111
+ log(' 2. 首次使用时,浏览器会弹出 GitLab 登录页');
112
+ log(' 3. 使用公司账号登录并点击授权');
113
+ log(' 4. 授权后即可使用,后续无需再次登录');
114
+ log('');
115
+ }
116
+ }
117
+ async function main() {
118
+ log('');
119
+ log(`${CYAN}${BOLD}🔧 UCloud GitLab MCP 配置工具${RESET}`);
120
+ log('═'.repeat(40));
121
+ header('[1/3] 检测环境...');
122
+ if (!checkNodeVersion()) {
123
+ process.exit(1);
124
+ }
125
+ header('[2/3] 检测 AI 工具...');
126
+ const tools = (0, detector_1.detectAITools)();
127
+ const installedTools = tools.filter(t => t.exists);
128
+ if (installedTools.length === 0) {
129
+ warn('未检测到已安装的 AI 工具');
130
+ log(' 将显示所有支持的工具,你可以选择手动配置');
131
+ }
132
+ else {
133
+ success(`检测到 ${installedTools.length} 个已安装的 AI 工具`);
134
+ }
135
+ log('');
136
+ log(' 请选择要配置的工具:');
137
+ displayTools(tools);
138
+ const answer = await prompt('\n 请输入选项: ');
139
+ const choice = parseInt(answer, 10);
140
+ if (choice === 0 || isNaN(choice)) {
141
+ log('\n 已退出');
142
+ process.exit(0);
143
+ }
144
+ let selectedTools;
145
+ if (choice === tools.length + 1) {
146
+ selectedTools = tools;
147
+ }
148
+ else if (choice >= 1 && choice <= tools.length) {
149
+ selectedTools = [tools[choice - 1]];
150
+ }
151
+ else {
152
+ error('无效的选项');
153
+ process.exit(1);
154
+ }
155
+ log('');
156
+ log(` 正在配置 ${selectedTools.length} 个工具...`);
157
+ const results = (0, writer_1.writeConfigToTools)(selectedTools);
158
+ displayResults(results);
159
+ }
160
+ main().catch((err) => {
161
+ error(`发生错误: ${err.message}`);
162
+ process.exit(1);
163
+ });
@@ -0,0 +1,19 @@
1
+ export declare const GITLAB_CONFIG: {
2
+ OAUTH_CLIENT_ID: string;
3
+ OAUTH_REDIRECT_URI: string;
4
+ API_URL: string;
5
+ };
6
+ export declare const MCP_SERVER_CONFIG: {
7
+ mcpServers: {
8
+ 'ucloud-gitlab': {
9
+ command: string;
10
+ args: string[];
11
+ env: {
12
+ GITLAB_USE_OAUTH: string;
13
+ GITLAB_OAUTH_CLIENT_ID: string;
14
+ GITLAB_OAUTH_REDIRECT_URI: string;
15
+ GITLAB_API_URL: string;
16
+ };
17
+ };
18
+ };
19
+ };
package/dist/config.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_SERVER_CONFIG = exports.GITLAB_CONFIG = void 0;
4
+ exports.GITLAB_CONFIG = {
5
+ OAUTH_CLIENT_ID: '4cc64d7325e8271d5c2425ea02e61199957ddd471f95fc39af951cb19eda1214',
6
+ OAUTH_REDIRECT_URI: 'http://127.0.0.1:8888/callback',
7
+ API_URL: 'https://git.ucloudadmin.com/api/v4',
8
+ };
9
+ exports.MCP_SERVER_CONFIG = {
10
+ mcpServers: {
11
+ 'ucloud-gitlab': {
12
+ command: 'npx',
13
+ args: ['-y', '@zereight/mcp-gitlab'],
14
+ env: {
15
+ GITLAB_USE_OAUTH: 'true',
16
+ GITLAB_OAUTH_CLIENT_ID: exports.GITLAB_CONFIG.OAUTH_CLIENT_ID,
17
+ GITLAB_OAUTH_REDIRECT_URI: exports.GITLAB_CONFIG.OAUTH_REDIRECT_URI,
18
+ GITLAB_API_URL: exports.GITLAB_CONFIG.API_URL,
19
+ },
20
+ },
21
+ },
22
+ };
@@ -0,0 +1,14 @@
1
+ export interface AITool {
2
+ name: string;
3
+ configPath: string;
4
+ exists: boolean;
5
+ configType: 'json' | 'yaml';
6
+ }
7
+ /**
8
+ * 检测已安装的AI工具
9
+ */
10
+ export declare function detectAITools(): AITool[];
11
+ /**
12
+ * 获取已安装的AI工具列表
13
+ */
14
+ export declare function getInstalledTools(): AITool[];
@@ -0,0 +1,94 @@
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.detectAITools = detectAITools;
37
+ exports.getInstalledTools = getInstalledTools;
38
+ const os = __importStar(require("os"));
39
+ const path = __importStar(require("path"));
40
+ const fs = __importStar(require("fs"));
41
+ /**
42
+ * 获取各AI工具的配置文件路径
43
+ */
44
+ function getConfigPaths() {
45
+ const home = os.homedir();
46
+ const platform = os.platform();
47
+ return {
48
+ cursor: platform === 'darwin'
49
+ ? path.join(home, '.cursor', 'mcp.json')
50
+ : platform === 'win32'
51
+ ? path.join(home, 'AppData', 'Roaming', 'Cursor', 'mcp.json')
52
+ : path.join(home, '.config', 'cursor', 'mcp.json'),
53
+ 'claude-code': path.join(home, '.claude', 'settings.json'),
54
+ 'vscode': path.join(home, '.vscode', 'mcp.json'),
55
+ 'opencode': path.join(home, '.config', 'opencode', 'mcp.json'),
56
+ 'claude-desktop': platform === 'darwin'
57
+ ? path.join(home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json')
58
+ : platform === 'win32'
59
+ ? path.join(home, 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json')
60
+ : path.join(home, '.config', 'claude', 'claude_desktop_config.json'),
61
+ };
62
+ }
63
+ /**
64
+ * 检测已安装的AI工具
65
+ */
66
+ function detectAITools() {
67
+ const configPaths = getConfigPaths();
68
+ const tools = [];
69
+ const toolNames = {
70
+ 'cursor': 'Cursor',
71
+ 'claude-code': 'Claude Code',
72
+ 'vscode': 'VS Code',
73
+ 'opencode': 'OpenCode',
74
+ 'claude-desktop': 'Claude Desktop',
75
+ };
76
+ for (const [key, configPath] of Object.entries(configPaths)) {
77
+ // 检查配置文件是否存在,或者其父目录是否存在(表示工具已安装)
78
+ const configDir = path.dirname(configPath);
79
+ const exists = fs.existsSync(configPath) || fs.existsSync(configDir);
80
+ tools.push({
81
+ name: toolNames[key] || key,
82
+ configPath,
83
+ exists,
84
+ configType: 'json',
85
+ });
86
+ }
87
+ return tools;
88
+ }
89
+ /**
90
+ * 获取已安装的AI工具列表
91
+ */
92
+ function getInstalledTools() {
93
+ return detectAITools().filter(tool => tool.exists);
94
+ }
@@ -0,0 +1,3 @@
1
+ export { detectAITools, getInstalledTools, AITool } from './detector';
2
+ export { writeConfigToTool, writeConfigToTools, WriteResult } from './writer';
3
+ export { GITLAB_CONFIG, MCP_SERVER_CONFIG } from './config';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_SERVER_CONFIG = exports.GITLAB_CONFIG = exports.writeConfigToTools = exports.writeConfigToTool = exports.getInstalledTools = exports.detectAITools = void 0;
4
+ var detector_1 = require("./detector");
5
+ Object.defineProperty(exports, "detectAITools", { enumerable: true, get: function () { return detector_1.detectAITools; } });
6
+ Object.defineProperty(exports, "getInstalledTools", { enumerable: true, get: function () { return detector_1.getInstalledTools; } });
7
+ var writer_1 = require("./writer");
8
+ Object.defineProperty(exports, "writeConfigToTool", { enumerable: true, get: function () { return writer_1.writeConfigToTool; } });
9
+ Object.defineProperty(exports, "writeConfigToTools", { enumerable: true, get: function () { return writer_1.writeConfigToTools; } });
10
+ var config_1 = require("./config");
11
+ Object.defineProperty(exports, "GITLAB_CONFIG", { enumerable: true, get: function () { return config_1.GITLAB_CONFIG; } });
12
+ Object.defineProperty(exports, "MCP_SERVER_CONFIG", { enumerable: true, get: function () { return config_1.MCP_SERVER_CONFIG; } });
@@ -0,0 +1,9 @@
1
+ import { AITool } from './detector';
2
+ export interface WriteResult {
3
+ tool: AITool;
4
+ success: boolean;
5
+ message: string;
6
+ backupPath?: string;
7
+ }
8
+ export declare function writeConfigToTool(tool: AITool): WriteResult;
9
+ export declare function writeConfigToTools(tools: AITool[]): WriteResult[];
package/dist/writer.js ADDED
@@ -0,0 +1,103 @@
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.writeConfigToTool = writeConfigToTool;
37
+ exports.writeConfigToTools = writeConfigToTools;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const config_1 = require("./config");
41
+ function ensureDirectoryExists(filePath) {
42
+ const dir = path.dirname(filePath);
43
+ if (!fs.existsSync(dir)) {
44
+ fs.mkdirSync(dir, { recursive: true });
45
+ }
46
+ }
47
+ function backupExistingConfig(filePath) {
48
+ if (fs.existsSync(filePath)) {
49
+ const backupPath = `${filePath}.backup.${Date.now()}`;
50
+ fs.copyFileSync(filePath, backupPath);
51
+ return backupPath;
52
+ }
53
+ return undefined;
54
+ }
55
+ function readExistingConfig(filePath) {
56
+ if (fs.existsSync(filePath)) {
57
+ try {
58
+ const content = fs.readFileSync(filePath, 'utf-8');
59
+ return JSON.parse(content);
60
+ }
61
+ catch {
62
+ return {};
63
+ }
64
+ }
65
+ return {};
66
+ }
67
+ function mergeConfigs(existing, newConfig) {
68
+ const merged = { ...existing };
69
+ if (!merged.mcpServers) {
70
+ merged.mcpServers = {};
71
+ }
72
+ const existingServers = merged.mcpServers;
73
+ const newServers = newConfig.mcpServers;
74
+ for (const [key, value] of Object.entries(newServers)) {
75
+ existingServers[key] = value;
76
+ }
77
+ return merged;
78
+ }
79
+ function writeConfigToTool(tool) {
80
+ try {
81
+ ensureDirectoryExists(tool.configPath);
82
+ const backupPath = backupExistingConfig(tool.configPath);
83
+ const existingConfig = readExistingConfig(tool.configPath);
84
+ const mergedConfig = mergeConfigs(existingConfig, config_1.MCP_SERVER_CONFIG);
85
+ fs.writeFileSync(tool.configPath, JSON.stringify(mergedConfig, null, 2), 'utf-8');
86
+ return {
87
+ tool,
88
+ success: true,
89
+ message: `已配置 ${tool.name}`,
90
+ backupPath,
91
+ };
92
+ }
93
+ catch (error) {
94
+ return {
95
+ tool,
96
+ success: false,
97
+ message: `配置 ${tool.name} 失败: ${error instanceof Error ? error.message : String(error)}`,
98
+ };
99
+ }
100
+ }
101
+ function writeConfigToTools(tools) {
102
+ return tools.map(writeConfigToTool);
103
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "gitlab-mcp-setup",
3
+ "version": "1.0.0",
4
+ "description": "One-click setup tool for GitLab MCP Server - Configure AI tools (Cursor, Claude, VS Code, OpenCode) to work with GitLab",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "gitlab-mcp-setup": "./dist/cli.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "ts-node src/cli.ts",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "keywords": [
15
+ "gitlab",
16
+ "mcp",
17
+ "model-context-protocol",
18
+ "setup",
19
+ "ai",
20
+ "cursor",
21
+ "claude",
22
+ "vscode",
23
+ "opencode"
24
+ ],
25
+ "author": "UCloud Frontend Team",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/anthropics/gitlab-mcp-setup"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^20.0.0",
33
+ "typescript": "^5.0.0"
34
+ },
35
+ "dependencies": {
36
+ "chalk": "^4.1.2",
37
+ "inquirer": "^8.2.6"
38
+ },
39
+ "engines": {
40
+ "node": ">=14.0.0"
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ]
45
+ }