Add an install step and welcome-page opt-in that registers the ClaudeDo external MCP server with the Claude CLI. Failures are non-fatal and surface the manual command so a missing or old CLI never blocks the install. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using ClaudeDo.Installer.Core;
|
|
|
|
namespace ClaudeDo.Installer.Steps;
|
|
|
|
public sealed class RegisterMcpStep : IInstallStep
|
|
{
|
|
private const string ServerName = "claudedo";
|
|
|
|
public string Name => "Register MCP with Claude";
|
|
|
|
public async Task<StepResult> ExecuteAsync(InstallContext ctx, IProgress<string> progress, CancellationToken ct)
|
|
{
|
|
if (!ctx.RegisterMcpWithClaude)
|
|
{
|
|
progress.Report("Skipped (not selected)");
|
|
return StepResult.Ok();
|
|
}
|
|
|
|
var url = $"http://127.0.0.1:{ctx.ExternalMcpPort}/mcp";
|
|
|
|
// Drop any prior registration first so a re-run (e.g. update, changed port)
|
|
// overwrites cleanly instead of erroring on a duplicate name.
|
|
progress.Report($"Removing existing '{ServerName}' MCP registration (if any)...");
|
|
await ProcessRunner.RunAsync(ctx.ClaudeBin, $"mcp remove --scope user {ServerName}", null, progress, ct);
|
|
|
|
progress.Report($"Registering '{ServerName}' MCP server at {url}...");
|
|
var (exit, output) = await ProcessRunner.RunAsync(
|
|
ctx.ClaudeBin,
|
|
$"mcp add --transport http --scope user {ServerName} {url}",
|
|
null, progress, ct);
|
|
|
|
// Non-fatal: a missing/old Claude CLI must never block the install. Surface the
|
|
// manual command so the user can register it themselves later.
|
|
if (exit != 0)
|
|
{
|
|
progress.Report(
|
|
$"Could not register MCP automatically (claude exited {exit}). " +
|
|
$"Run manually: claude mcp add --transport http --scope user {ServerName} {url}");
|
|
}
|
|
else
|
|
{
|
|
progress.Report("MCP server registered with Claude.");
|
|
}
|
|
|
|
return StepResult.Ok();
|
|
}
|
|
}
|