chore(worker): external MCP tools return explicit results instead of empty responses
set_task_config/set_list_config now echo which fields were set vs cleared, get_list_config/get_task_config return an explicit found=false instead of null, and delete_list/run_task_now/reset_failed_task/remove_task_attachment return a confirmation record — matching the found/ok convention already used by batch_get_tasks and get_task_log.
This commit is contained in:
+36
-12
@@ -7,6 +7,9 @@ using ModelContextProtocol.Server;
|
||||
namespace ClaudeDo.Worker.External;
|
||||
|
||||
public sealed record TaskConfigDto(string? Model, string? SystemPrompt, string? AgentPath, int? MaxTurns);
|
||||
public sealed record TaskConfigResult(bool Found, TaskConfigDto? Config);
|
||||
public sealed record SetListConfigResult(bool Ok, string ListId, TaskConfigDto? Config);
|
||||
public sealed record SetTaskConfigResult(bool Ok, string TaskId, TaskConfigDto? Config);
|
||||
|
||||
[McpServerToolType]
|
||||
public sealed class ConfigMcpTools
|
||||
@@ -22,15 +25,20 @@ public sealed class ConfigMcpTools
|
||||
_broadcaster = broadcaster;
|
||||
}
|
||||
|
||||
[McpServerTool, Description("Get a list's default config (model, system prompt, agent path). Returns null if no config is set.")]
|
||||
public async Task<TaskConfigDto?> GetListConfig(string listId, CancellationToken cancellationToken)
|
||||
[McpServerTool, Description("Get a list's default config (model, system prompt, agent path). Returns { found: false, config: null } if no config is set.")]
|
||||
public async Task<TaskConfigResult> GetListConfig(string listId, CancellationToken cancellationToken)
|
||||
{
|
||||
var cfg = await _lists.GetConfigAsync(listId, cancellationToken);
|
||||
return cfg is null ? null : new TaskConfigDto(cfg.Model, cfg.SystemPrompt, cfg.AgentPath, cfg.MaxTurns);
|
||||
return cfg is null
|
||||
? new TaskConfigResult(false, null)
|
||||
: new TaskConfigResult(true, new TaskConfigDto(cfg.Model, cfg.SystemPrompt, cfg.AgentPath, cfg.MaxTurns));
|
||||
}
|
||||
|
||||
[McpServerTool, Description("Set a list's default model/system prompt/agent path/max turns. Passing all four as null clears the list config.")]
|
||||
public async Task SetListConfig(
|
||||
[McpServerTool, Description(
|
||||
"Set a list's default model/system prompt/agent path/max turns. Passing all four as null clears the list " +
|
||||
"config. Returns { ok, listId, config } — config is null when the config was cleared, otherwise it echoes " +
|
||||
"the fields that were set (a field is null there if it was individually left unset/cleared).")]
|
||||
public async Task<SetListConfigResult> SetListConfig(
|
||||
string listId, string? model = null, string? systemPrompt = null, string? agentPath = null,
|
||||
int? maxTurns = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -41,36 +49,52 @@ public sealed class ConfigMcpTools
|
||||
var sp = systemPrompt.NullIfBlank();
|
||||
var ap = agentPath.NullIfBlank();
|
||||
|
||||
TaskConfigDto? config;
|
||||
if (m is null && sp is null && ap is null && maxTurns is null)
|
||||
{
|
||||
await _lists.DeleteConfigAsync(listId, cancellationToken);
|
||||
config = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
await _lists.SetConfigAsync(new ListConfigEntity
|
||||
{
|
||||
ListId = listId, Model = m, SystemPrompt = sp, AgentPath = ap, MaxTurns = maxTurns,
|
||||
}, cancellationToken);
|
||||
config = new TaskConfigDto(m, sp, ap, maxTurns);
|
||||
}
|
||||
|
||||
await _broadcaster.ListUpdated(listId);
|
||||
return new SetListConfigResult(true, listId, config);
|
||||
}
|
||||
|
||||
[McpServerTool, Description("Set per-task config overrides (model/system prompt/agent path/max turns). Pass null for any field to clear that override.")]
|
||||
public async Task SetTaskConfig(
|
||||
[McpServerTool, Description(
|
||||
"Set per-task config overrides (model/system prompt/agent path/max turns). Pass null for any field to " +
|
||||
"clear that override. Returns { ok, taskId, config } — config echoes the resulting overrides (a field is " +
|
||||
"null there if it was cleared or never set).")]
|
||||
public async Task<SetTaskConfigResult> SetTaskConfig(
|
||||
string taskId, string? model = null, string? systemPrompt = null, string? agentPath = null,
|
||||
int? maxTurns = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_ = await _tasks.GetByIdAsync(taskId, cancellationToken)
|
||||
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||
|
||||
await _tasks.UpdateAgentSettingsAsync(taskId, model.NullIfBlank(), systemPrompt.NullIfBlank(), agentPath.NullIfBlank(), maxTurns, ct: cancellationToken);
|
||||
var m = model.NullIfBlank();
|
||||
var sp = systemPrompt.NullIfBlank();
|
||||
var ap = agentPath.NullIfBlank();
|
||||
|
||||
await _tasks.UpdateAgentSettingsAsync(taskId, m, sp, ap, maxTurns, ct: cancellationToken);
|
||||
await _broadcaster.TaskUpdated(taskId);
|
||||
return new SetTaskConfigResult(true, taskId, new TaskConfigDto(m, sp, ap, maxTurns));
|
||||
}
|
||||
|
||||
[McpServerTool, Description("Get per-task config overrides (model/system prompt/agent path/max turns). Returns null if no override is set on this task.")]
|
||||
public async Task<TaskConfigDto?> GetTaskConfig(string taskId, CancellationToken cancellationToken)
|
||||
[McpServerTool, Description("Get per-task config overrides (model/system prompt/agent path/max turns). Returns { found: false, config: null } if no override is set on this task.")]
|
||||
public async Task<TaskConfigResult> GetTaskConfig(string taskId, CancellationToken cancellationToken)
|
||||
{
|
||||
var task = await _tasks.GetByIdAsync(taskId, cancellationToken)
|
||||
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||
if (task.Model is null && task.SystemPrompt is null && task.AgentPath is null && task.MaxTurns is null)
|
||||
return null;
|
||||
return new TaskConfigDto(task.Model, task.SystemPrompt, task.AgentPath, task.MaxTurns);
|
||||
return new TaskConfigResult(false, null);
|
||||
return new TaskConfigResult(true, new TaskConfigDto(task.Model, task.SystemPrompt, task.AgentPath, task.MaxTurns));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user