feat(mcp): add SuggestImprovement tool (server-stamped, one layer deep)

This commit is contained in:
mika kuns
2026-06-04 15:51:57 +02:00
parent 7542bc2058
commit 9d133e227b
2 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
using System.ComponentModel;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Worker.Hub;
using ModelContextProtocol.Server;
namespace ClaudeDo.Worker.Runner;
public sealed record SuggestedImprovementDto(string ChildTaskId);
[McpServerToolType]
public sealed class TaskRunMcpService
{
private readonly TaskRepository _tasks;
private readonly TaskRunMcpContextAccessor _ctx;
private readonly HubBroadcaster _broadcaster;
public TaskRunMcpService(TaskRepository tasks, TaskRunMcpContextAccessor ctx, HubBroadcaster broadcaster)
{
_tasks = tasks;
_ctx = ctx;
_broadcaster = broadcaster;
}
[McpServerTool, Description(
"File an out-of-scope improvement as a child task of the current task. The child runs " +
"automatically after this task finishes and is surfaced for review alongside it. Use ONLY " +
"for work that is genuinely outside this task's scope (a refactor, follow-up, or tech debt) " +
"— never for work that belongs to the current task.")]
public async Task<SuggestedImprovementDto> SuggestImprovement(
string title,
string description,
CancellationToken cancellationToken)
{
var callerId = _ctx.Current.CallerTaskId;
var caller = await _tasks.GetByIdAsync(callerId, cancellationToken)
?? throw new InvalidOperationException("Calling task not found.");
if (caller.ParentTaskId is not null)
throw new InvalidOperationException(
"A child task cannot suggest further improvements (improvements are one layer deep).");
var child = await _tasks.CreateChildAsync(
callerId, title, description, commitType: null, createdBy: callerId, cancellationToken);
await _broadcaster.TaskUpdated(child.Id);
await _broadcaster.TaskUpdated(callerId);
return new SuggestedImprovementDto(child.Id);
}
}