1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package task
6
7import (
8 "context"
9 "time"
10
11 "git.secluded.site/go-lunatask"
12 "git.secluded.site/lune/internal/mcp/shared"
13 "github.com/modelcontextprotocol/go-sdk/mcp"
14)
15
16// ShowToolName is the name of the show task tool.
17const ShowToolName = "show_task"
18
19// ShowToolDescription describes the show task tool for LLMs.
20const ShowToolDescription = `Shows details of a specific task from Lunatask.
21
22Required:
23- id: Task UUID or lunatask:// deep link
24
25Note: Due to end-to-end encryption, task name and note content are not available.
26Only metadata (ID, status, dates, priority, etc.) is returned.`
27
28// ShowInput is the input schema for showing a task.
29type ShowInput struct {
30 ID string `json:"id" jsonschema:"required"`
31}
32
33// ShowOutput is the output schema for showing a task.
34type ShowOutput struct {
35 ID string `json:"id"`
36 DeepLink string `json:"deep_link"`
37 Status *string `json:"status,omitempty"`
38 Priority *int `json:"priority,omitempty"`
39 Estimate *int `json:"estimate,omitempty"`
40 ScheduledOn *string `json:"scheduled_on,omitempty"`
41 CompletedAt *string `json:"completed_at,omitempty"`
42 CreatedAt string `json:"created_at"`
43 UpdatedAt string `json:"updated_at"`
44 AreaID *string `json:"area_id,omitempty"`
45 GoalID *string `json:"goal_id,omitempty"`
46 Important *bool `json:"important,omitempty"`
47 Urgent *bool `json:"urgent,omitempty"`
48}
49
50// HandleShow shows a task's details.
51func (h *Handler) HandleShow(
52 ctx context.Context,
53 _ *mcp.CallToolRequest,
54 input ShowInput,
55) (*mcp.CallToolResult, ShowOutput, error) {
56 _, id, err := lunatask.ParseReference(input.ID)
57 if err != nil {
58 return shared.ErrorResult("invalid ID: expected UUID or lunatask:// deep link"), ShowOutput{}, nil
59 }
60
61 task, err := h.client.GetTask(ctx, id)
62 if err != nil {
63 return shared.ErrorResult(err.Error()), ShowOutput{}, nil
64 }
65
66 output := ShowOutput{
67 ID: task.ID,
68 CreatedAt: task.CreatedAt.Format(time.RFC3339),
69 UpdatedAt: task.UpdatedAt.Format(time.RFC3339),
70 AreaID: task.AreaID,
71 GoalID: task.GoalID,
72 }
73
74 output.DeepLink, _ = lunatask.BuildDeepLink(lunatask.ResourceTask, task.ID)
75
76 if task.Status != nil {
77 s := string(*task.Status)
78 output.Status = &s
79 }
80
81 if task.Priority != nil {
82 p := int(*task.Priority)
83 output.Priority = &p
84 }
85
86 if task.Estimate != nil {
87 output.Estimate = task.Estimate
88 }
89
90 if task.ScheduledOn != nil {
91 s := task.ScheduledOn.Format("2006-01-02")
92 output.ScheduledOn = &s
93 }
94
95 if task.CompletedAt != nil {
96 s := task.CompletedAt.Format(time.RFC3339)
97 output.CompletedAt = &s
98 }
99
100 if task.Eisenhower != nil {
101 important := task.Eisenhower.IsImportant()
102 urgent := task.Eisenhower.IsUrgent()
103 output.Important = &important
104 output.Urgent = &urgent
105 }
106
107 return nil, output, nil
108}