[fix] Require config for MCP cleanup tools#298
Conversation
a475fbb to
6768d25
Compare
| return mcp.NewToolResultError("mode is required"), nil | ||
| } | ||
|
|
||
| cfg, cfgErr := hctx.requireConfig() |
There was a problem hiding this comment.
High — prune mode now unnecessarily requires config
mcpCleanPrune calls only git.Prune and git.PruneRemotes — it never reads cfg.DefaultSource. By placing requireConfig() before the switch, all three modes (including prune) now fail without an initialized repo, extending the blast radius beyond the issue scope.
prune was previously usable in any repo; this is a silent behavioral regression.
Suggested fix: move the config gate inside the merged and stale case arms, where cfg.DefaultSource is actually consumed:
switch mode {
case "prune":
return mcpCleanPrune(ctx, r, dryRun)
case "merged":
cfg, cfgErr := hctx.requireConfig()
if cfgErr != nil {
return mcp.NewToolResultError(cfgErr.Error()), nil
}
return mcpCleanMerged(ctx, r, cfg.DefaultSource, dryRun, force)
case "stale":
cfg, cfgErr := hctx.requireConfig()
if cfgErr != nil {
return mcp.NewToolResultError(cfgErr.Error()), nil
}
return mcpCleanStale(ctx, r, cfg.DefaultSource, dryRun, staleDays, force)Then update TestCleanToolRequiresConfig to use modeMerged or modeStale (since modePrune would no longer require config).
lugassawan
left a comment
There was a problem hiding this comment.
Review Decision: COMMENT
Reviewed by reviewer (swe-workbench). Posted 1 inline comment, deduped 0.
Informational (out-of-diff)
internal/mcp/tool_list.go — handleListArchived bypasses the config gate (pre-existing)
handleList short-circuits to handleListArchived before calling requireConfig() when archived=true. handleListArchived uses the nil-safe configDefault(hctx) helper, so list --archived still works without an initialized repo. This PR does not introduce or worsen it — it predates this change — but it is the same class of gap issue #267 addressed on the other three tools. Worth a follow-up issue.
Summary
clean,remove, andstatushandlers do any work.clean/statusmain-branch resolution.Test Plan
make test)make lint)make test-e2e)Additional focused checks run:
Risk and scope: scoped to MCP handler preflight checks and tests. Existing required-argument errors still run before the config gate, while valid tool calls now fail with the same friendly initialization message used by the other MCP tools when
.rimba/settings.tomlis unavailable.Issue
Closes #267