MCPcopy Create free account
hub / github.com/driangle/taskmd / handleSet

Function handleSet

apps/cli/internal/mcp/set.go:39–85  ·  view source on GitHub ↗
(_ context.Context, _ *gomcp.CallToolRequest, input SetInput)

Source from the content-addressed store, hash-verified

37}
38
39func handleSet(_ context.Context, _ *gomcp.CallToolRequest, input SetInput) (*gomcp.CallToolResult, any, error) {
40 if input.TaskID == "" {
41 return nil, nil, fmt.Errorf("task_id is required")
42 }
43
44 req := buildUpdateRequest(input)
45
46 if errs := taskfile.ValidateUpdateRequest(req); len(errs) > 0 {
47 return nil, nil, fmt.Errorf("validation failed: %s", strings.Join(errs, "; "))
48 }
49
50 if isEmptyRequest(req) {
51 return nil, nil, fmt.Errorf("no fields to update")
52 }
53
54 taskDir := input.TaskDir
55 if taskDir == "" {
56 taskDir = "."
57 }
58
59 taskScanner := scanner.NewScanner(taskDir, false, nil)
60 result, err := taskScanner.Scan()
61 if err != nil {
62 return nil, nil, fmt.Errorf("scan failed: %w", err)
63 }
64
65 task := findTaskByID(input.TaskID, result.Tasks)
66 if task == nil {
67 return nil, nil, fmt.Errorf("task not found: %s", input.TaskID)
68 }
69
70 applyStatusTransitionDates(&req, task)
71
72 if err := taskfile.UpdateTaskFile(task.FilePath, req); err != nil {
73 return nil, nil, fmt.Errorf("update failed: %w", err)
74 }
75
76 out := buildSetOutput(input, req, task.FilePath)
77 data, err := json.Marshal(out)
78 if err != nil {
79 return nil, nil, fmt.Errorf("json marshal failed: %w", err)
80 }
81
82 return &gomcp.CallToolResult{
83 Content: []gomcp.Content{&gomcp.TextContent{Text: string(data)}},
84 }, nil, nil
85}
86
87func applyStatusTransitionDates(req *taskfile.UpdateRequest, task *model.Task) {
88 if req.Status == nil {

Callers

nothing calls this directly

Calls 6

ScanMethod · 0.95
buildUpdateRequestFunction · 0.85
isEmptyRequestFunction · 0.85
buildSetOutputFunction · 0.85
findTaskByIDFunction · 0.70

Tested by

no test coverage detected