Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | 3x 3x 3x 3x 3x 13x 13x 15x 2x 2x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 13x 3x 34x 34x 34x 34x 34x 34x 34x 34x 34x 24x 24x 24x 5x 24x 24x 5x 19x 19x 19x 24x 3x 18x 1x 1x 1x 1x 1x 1x 1x 17x 17x 17x 17x 26x 17x 17x 1x 1x 7x 1x 1x 16x 16x 24x 24x 16x 16x 4x 14x 14x 14x 9x 2x 2x 5x 8x 5x 1x 1x 4x 7x 4x 4x 2x 2x 2x 2x 13x 1x 1x 1x 12x 22x 12x 12x 5x 5x 5x 5x 1x 1x 4x 2x 3x 2x 1x 1x 1x 10x 10x 10x 10x 12x 12x 10x 10x 10x 11x 11x 11x 11x 11x 1x 11x 10x 1x 1x 1x 1x 10x 10x 3x 7x 7x 2x 2x 2x 2x 2x 5x 5x 5x 2x 4x 5x 1x 1x 4x 4x 4x 4x 3x 3x 1x 1x 4x 3x 6x 6x 6x 6x 6x 1x 6x | /**
* Interactive install wizard for MCP clients
*/
import * as p from "@clack/prompts";
import {
InstallableClient,
InstallResult,
CLIENT_METADATA,
INSTALLABLE_CLIENTS,
ClientDetectionResult,
} from "./types";
import { detectAllClients, getDetectedClients } from "./detector";
import { installToClients, generateConfigPreview } from "./installers";
import { McpServerConfig } from "../init/types";
/**
* CLI flags for install command
*/
export interface InstallFlags {
claudeDesktop?: boolean;
claudeCode?: boolean;
cursor?: boolean;
vscode?: boolean;
cline?: boolean;
rooCode?: boolean;
windsurf?: boolean;
all?: boolean;
show?: boolean;
force?: boolean;
}
/**
* Parse install flags from CLI arguments
*/
export function parseInstallFlags(args: string[]): InstallFlags {
const flags: InstallFlags = {};
for (const arg of args) {
switch (arg) {
case "--claude-desktop":
flags.claudeDesktop = true;
break;
case "--claude-code":
flags.claudeCode = true;
break;
case "--cursor":
flags.cursor = true;
break;
case "--vscode":
flags.vscode = true;
break;
case "--cline":
flags.cline = true;
break;
case "--roo-code":
flags.rooCode = true;
break;
case "--windsurf":
flags.windsurf = true;
break;
case "--all":
flags.all = true;
break;
case "--show":
flags.show = true;
break;
case "--force":
flags.force = true;
break;
}
}
return flags;
}
/**
* Get clients from flags
*/
export function getClientsFromFlags(flags: InstallFlags): InstallableClient[] {
const clients: InstallableClient[] = [];
if (flags.claudeDesktop) clients.push("claude-desktop");
if (flags.claudeCode) clients.push("claude-code");
if (flags.cursor) clients.push("cursor");
if (flags.vscode) clients.push("vscode-copilot");
if (flags.cline) clients.push("cline");
if (flags.rooCode) clients.push("roo-code");
if (flags.windsurf) clients.push("windsurf");
return clients;
}
/**
* Format detection result for display
*/
function formatDetectionResult(result: ClientDetectionResult): string {
const metadata = CLIENT_METADATA[result.client];
let status = result.detected ? "✓" : "✗";
if (result.alreadyConfigured) {
status = "⚙"; // Already configured
}
let hint = "";
if (result.alreadyConfigured) {
hint = " (already configured)";
} else Iif (result.detected && result.configExists) {
hint = " (config exists)";
} else Eif (result.detected) {
hint = " (detected)";
}
return `${status} ${metadata.name}${hint}`;
}
/**
* Run interactive install wizard
*/
export async function runInstallWizard(
serverConfig: McpServerConfig,
flags: InstallFlags = {}
): Promise<InstallResult[]> {
// If --show flag is set, just display config
if (flags.show) {
p.intro("GitLab MCP Configuration Preview");
// Show config for first specified client or claude-desktop
const specifiedClients = getClientsFromFlags(flags);
const targetClient = specifiedClients[0] ?? "claude-desktop";
const preview = generateConfigPreview(targetClient, serverConfig);
p.note(preview, `Configuration for ${CLIENT_METADATA[targetClient].name}`);
p.outro("Use these settings to configure your MCP client manually.");
return [];
}
p.intro("Install GitLab MCP to your AI coding assistants");
// Detect installed clients
const spinner = p.spinner();
spinner.start("Detecting installed MCP clients...");
const detectionResults = detectAllClients();
const detectedClients = detectionResults.filter(r => r.detected);
spinner.stop(`Found ${detectedClients.length} MCP clients`);
if (detectedClients.length === 0) {
p.log.warn("No MCP clients detected on this system.");
p.note(
"Supported clients:\n" +
INSTALLABLE_CLIENTS.map(c => ` - ${CLIENT_METADATA[c].name}`).join("\n"),
"Install one of these clients first:"
);
p.outro("Setup cancelled.");
return [];
}
// Show detection results
p.log.info("Detected clients:");
for (const result of detectionResults) {
Eif (result.detected) {
console.log(` ${formatDetectionResult(result)}`);
}
}
// Determine target clients
let targetClients: InstallableClient[];
const specifiedClients = getClientsFromFlags(flags);
if (flags.all) {
// Install to all detected clients
targetClients = detectedClients.map(r => r.client);
} else if (specifiedClients.length > 0) {
// Use specified clients (filter to only detected ones)
targetClients = specifiedClients.filter(c => detectedClients.some(d => d.client === c));
// Warn about undetected clients
const undetected = specifiedClients.filter(c => !detectedClients.some(d => d.client === c));
if (undetected.length > 0) {
p.log.warn(
`Skipping undetected clients: ${undetected.map(c => CLIENT_METADATA[c].name).join(", ")}`
);
}
} else {
// Interactive selection
const selectedClients = await p.multiselect({
message: "Select clients to install to:",
options: detectedClients.map(result => ({
value: result.client,
label: CLIENT_METADATA[result.client].name,
hint: result.alreadyConfigured ? "already configured" : undefined,
})),
required: true,
});
if (p.isCancel(selectedClients)) {
p.cancel("Installation cancelled");
return [];
}
// Validate selected clients at runtime
const isInstallableClient = (value: unknown): value is InstallableClient =>
typeof value === "string" && INSTALLABLE_CLIENTS.includes(value as InstallableClient);
const validatedClients = (selectedClients as unknown[]).filter(isInstallableClient);
if (validatedClients.length !== (selectedClients as unknown[]).length) {
p.log.error("Invalid client selection received.");
p.cancel("Installation cancelled");
return [];
}
targetClients = validatedClients;
}
if (targetClients.length === 0) {
p.log.warn("No clients selected for installation.");
p.outro("Setup cancelled.");
return [];
}
// Check for already configured clients
const alreadyConfigured = targetClients.filter(
c => detectionResults.find(r => r.client === c)?.alreadyConfigured
);
// Track if user confirmed overwrite
let userConfirmedOverwrite = false;
if (alreadyConfigured.length > 0 && !flags.force) {
p.log.warn(
`Some clients already have gitlab-mcp configured: ${alreadyConfigured.map(c => CLIENT_METADATA[c].name).join(", ")}`
);
const overwrite = await p.confirm({
message: "Overwrite existing configurations?",
initialValue: false,
});
if (p.isCancel(overwrite)) {
p.cancel("Installation cancelled");
return [];
}
if (overwrite) {
userConfirmedOverwrite = true;
} else {
// Remove already configured clients from target list
targetClients = targetClients.filter(c => !alreadyConfigured.includes(c));
if (targetClients.length === 0) {
p.log.info("No new clients to configure.");
p.outro("Configuration unchanged.");
return [];
}
}
}
// Install to selected clients
spinner.start("Installing configuration...");
// Force install only if explicitly requested OR if user confirmed overwrite
const forceInstall = flags.force === true || userConfirmedOverwrite;
const results = installToClients(targetClients, serverConfig, forceInstall);
spinner.stop("Installation complete!");
// Display results
const successful = results.filter(r => r.success);
const failed = results.filter(r => !r.success);
Eif (successful.length > 0) {
p.log.success(`Installed to ${successful.length} clients:`);
for (const result of successful) {
const metadata = CLIENT_METADATA[result.client];
let info = ` ✓ ${metadata.name}`;
Eif (result.configPath) {
info += ` (${result.configPath})`;
}
if (result.backupPath) {
info += `\n Backup: ${result.backupPath}`;
}
console.log(info);
}
}
if (failed.length > 0) {
p.log.error(`Failed for ${failed.length} clients:`);
for (const result of failed) {
const metadata = CLIENT_METADATA[result.client];
console.log(` ✗ ${metadata.name}: ${result.error}`);
}
}
p.outro(
successful.length > 0
? "Installation complete! Restart your MCP clients to apply changes."
: "Installation failed."
);
return results;
}
/**
* Run install command (non-interactive mode)
*/
export async function runInstallCommand(
serverConfig: McpServerConfig,
flags: InstallFlags
): Promise<InstallResult[]> {
const specifiedClients = getClientsFromFlags(flags);
// If --show mode, display config and exit
if (flags.show) {
const targetClient = specifiedClients[0] ?? "claude-desktop";
const preview = generateConfigPreview(targetClient, serverConfig);
console.log(`Configuration for ${CLIENT_METADATA[targetClient].name}:\n`);
console.log(preview);
return [];
}
// If specific clients or --all specified, run non-interactively
Eif (specifiedClients.length > 0 || flags.all) {
const detected = getDetectedClients();
let targetClients: InstallableClient[];
if (flags.all) {
targetClients = detected.map(r => r.client);
} else {
targetClients = specifiedClients.filter(c => detected.some(d => d.client === c));
}
if (targetClients.length === 0) {
console.error("No supported MCP clients detected.");
return [];
}
const results = installToClients(targetClients, serverConfig, flags.force ?? false);
// Display results
for (const result of results) {
const metadata = CLIENT_METADATA[result.client];
if (result.success) {
console.log(`✓ Installed to ${metadata.name}`);
if (result.backupPath) {
console.log(` Backup created: ${result.backupPath}`);
}
} else {
console.error(`✗ Failed for ${metadata.name}: ${result.error}`);
}
}
return results;
}
// Otherwise, run interactive wizard
return runInstallWizard(serverConfig, flags);
}
/**
* Build server config from environment/defaults
*/
export function buildServerConfigFromEnv(): McpServerConfig {
const instanceUrl = process.env.GITLAB_URL ?? "https://gitlab.com";
const token = process.env.GITLAB_TOKEN ?? "";
const preset = process.env.GITLAB_MCP_PRESET;
const env: Record<string, string> = {
GITLAB_URL: instanceUrl,
GITLAB_TOKEN: token,
};
if (preset) {
env.GITLAB_MCP_PRESET = preset;
}
return {
command: "npx",
args: ["-y", "@structured-world/gitlab-mcp"],
env,
};
}
|