1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package mcp
6
7import (
8 "encoding/json"
9 "fmt"
10)
11
12// Goal management requests
13
14// SetGoalRequest represents the request structure for set_goal
15type SetGoalRequest struct {
16 Title string `json:"title" validate:"required"`
17 Description string `json:"description" validate:"required"`
18}
19
20// ChangeGoalRequest represents the request structure for change_goal
21type ChangeGoalRequest struct {
22 Title string `json:"title" validate:"required"`
23 Description string `json:"description" validate:"required"`
24 Reason string `json:"reason" validate:"required"`
25}
26
27// Task management requests
28
29// AddTasksRequest represents the request structure for add_tasks
30type AddTasksRequest struct {
31 Tasks []MCPTaskInput `json:"tasks" validate:"required,min=1"`
32}
33
34// MCPTaskInput represents a single task input for adding tasks
35type MCPTaskInput struct {
36 Title string `json:"title" validate:"required"`
37 Description string `json:"description"`
38}
39
40// GetTasksRequest represents the request structure for get_tasks
41type GetTasksRequest struct {
42 Status string `json:"status,omitempty"`
43}
44
45// UpdateTaskStatusesRequest represents the request structure for update_task_statuses
46type UpdateTaskStatusesRequest struct {
47 Tasks []MCPTaskUpdateInput `json:"tasks" validate:"required,min=1"`
48}
49
50// MCPTaskUpdateInput represents a single task update input
51type MCPTaskUpdateInput struct {
52 TaskID string `json:"task_id" validate:"required"`
53 Status string `json:"status" validate:"required,oneof=pending in_progress completed cancelled failed"`
54}
55
56// DeleteTasksRequest represents the request structure for delete_tasks
57type DeleteTasksRequest struct {
58 TaskIDs []string `json:"task_ids" validate:"required,min=1"`
59}
60
61// ModifyTaskRequest represents the request structure for modify_task
62type ModifyTaskRequest struct {
63 TaskID string `json:"task_id" validate:"required"`
64 Title string `json:"title,omitempty"`
65 Description string `json:"description,omitempty"`
66}
67
68// parseRequest is a generic helper function to parse map[string]any to struct without validation
69func parseRequest[T any](arguments map[string]any, dest *T) error {
70 // Convert map to JSON then unmarshal to struct
71 jsonData, err := json.Marshal(arguments)
72 if err != nil {
73 return fmt.Errorf("failed to marshal arguments: %w", err)
74 }
75
76 if err := json.Unmarshal(jsonData, dest); err != nil {
77 return fmt.Errorf("failed to unmarshal request: %w", err)
78 }
79
80 return nil
81}