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

Function handleGraph

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

Source from the content-addressed store, hash-verified

29}
30
31func handleGraph(_ context.Context, _ *gomcp.CallToolRequest, input GraphInput) (*gomcp.CallToolResult, any, error) {
32 taskDir := input.TaskDir
33 if taskDir == "" {
34 taskDir = "."
35 }
36
37 taskScanner := scanner.NewScanner(taskDir, false, nil)
38 result, err := taskScanner.Scan()
39 if err != nil {
40 return nil, nil, fmt.Errorf("scan failed: %w", err)
41 }
42
43 tasks := result.Tasks
44
45 if len(input.Filters) > 0 {
46 tasks, err = filter.Apply(tasks, input.Filters)
47 if err != nil {
48 return nil, nil, fmt.Errorf("filter error: %w", err)
49 }
50 }
51
52 if len(input.ExcludeStatus) > 0 {
53 tasks = excludeByStatus(tasks, input.ExcludeStatus)
54 }
55
56 g := graph.NewGraph(tasks)
57
58 if input.RootTaskID != "" {
59 if _, ok := g.TaskMap[input.RootTaskID]; !ok {
60 return nil, nil, fmt.Errorf("root task not found: %s", input.RootTaskID)
61 }
62 upstream := g.GetUpstream(input.RootTaskID)
63 downstream := g.GetDownstream(input.RootTaskID)
64 combined := make(map[string]bool, len(upstream)+len(downstream)+1)
65 for id := range upstream {
66 combined[id] = true
67 }
68 for id := range downstream {
69 combined[id] = true
70 }
71 combined[input.RootTaskID] = true
72 g = g.FilterTasks(combined)
73 }
74
75 graphJSON := g.ToJSON()
76
77 data, err := json.Marshal(graphJSON)
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 excludeByStatus(tasks []*model.Task, statuses []string) []*model.Task {
88 excludeMap := make(map[string]bool, len(statuses))

Callers

nothing calls this directly

Calls 6

ScanMethod · 0.95
GetUpstreamMethod · 0.95
GetDownstreamMethod · 0.95
FilterTasksMethod · 0.95
ToJSONMethod · 0.95
excludeByStatusFunction · 0.85

Tested by

no test coverage detected