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 "github.com/go-playground/validator/v10"
12)
13
14// Goal management requests
15
16// SetGoalRequest represents the request structure for project_management__set_goal
17type SetGoalRequest struct {
18 Title string `json:"title" validate:"required"`
19 Description string `json:"description" validate:"required"`
20}
21
22// ChangeGoalRequest represents the request structure for project_management__change_goal
23type ChangeGoalRequest struct {
24 Title string `json:"title" validate:"required"`
25 Description string `json:"description" validate:"required"`
26 Reason string `json:"reason" validate:"required"`
27}
28
29// Task management requests
30
31// AddTasksRequest represents the request structure for project_management__add_tasks
32type AddTasksRequest struct {
33 Tasks []MCPTaskInput `json:"tasks" validate:"required,min=1"`
34}
35
36// MCPTaskInput represents a single task input for adding tasks
37type MCPTaskInput struct {
38 Title string `json:"title" validate:"required"`
39 Description string `json:"description"`
40}
41
42// GetTasksRequest represents the request structure for project_management__get_tasks
43type GetTasksRequest struct {
44 Status string `json:"status,omitempty"`
45}
46
47// UpdateTaskStatusesRequest represents the request structure for project_management__update_task_statuses
48type UpdateTaskStatusesRequest struct {
49 Tasks []MCPTaskUpdateInput `json:"tasks" validate:"required,min=1"`
50}
51
52// MCPTaskUpdateInput represents a single task update input
53type MCPTaskUpdateInput struct {
54 TaskID string `json:"task_id" validate:"required"`
55 Status string `json:"status" validate:"required,oneof=pending in_progress completed cancelled failed"`
56}
57
58// DeleteTasksRequest represents the request structure for project_management__delete_tasks
59type DeleteTasksRequest struct {
60 TaskIDs []string `json:"task_ids" validate:"required,min=1"`
61}
62
63// validator instance for struct validation
64var validate *validator.Validate
65
66func init() {
67 validate = validator.New()
68}
69
70// parseAndValidate is a generic helper function to parse map[string]any to struct and validate
71func parseAndValidate[T any](arguments map[string]any, dest *T) error {
72 // Convert map to JSON then unmarshal to struct
73 jsonData, err := json.Marshal(arguments)
74 if err != nil {
75 return fmt.Errorf("failed to marshal arguments: %w", err)
76 }
77
78 if err := json.Unmarshal(jsonData, dest); err != nil {
79 return fmt.Errorf("failed to unmarshal request: %w", err)
80 }
81
82 // Validate the struct
83 if err := validate.Struct(dest); err != nil {
84 return fmt.Errorf("validation failed: %w", err)
85 }
86
87 return nil
88}