diff --git a/lunatask/habits.go b/lunatask/habits.go index c979e77eb4b1b490b0dcff4e58ce0ea9e8d7a795..1ad56897d57b0e375ab95a616716132e8b8add7a 100644 --- a/lunatask/habits.go +++ b/lunatask/habits.go @@ -8,13 +8,12 @@ import ( "context" "fmt" "net/http" - "time" ) // TrackHabitActivityRequest represents the request to track a habit activity. type TrackHabitActivityRequest struct { - // PerformedOn is the ISO-8601 date when the activity was performed (e.g., "2024-08-26"). - PerformedOn string `json:"performed_on"` + // PerformedOn is the date when the activity was performed. + PerformedOn Date `json:"performed_on"` } // TrackHabitActivityResponse represents the response from Lunatask API when tracking a habit activity. @@ -29,15 +28,10 @@ func (c *Client) TrackHabitActivity(ctx context.Context, habitID string, request if habitID == "" { return nil, fmt.Errorf("%w: habit ID cannot be empty", ErrBadRequest) } - if request.PerformedOn == "" { + if request.PerformedOn.IsZero() { return nil, fmt.Errorf("%w: performed_on is required", ErrBadRequest) } - // Validate date format (YYYY-MM-DD) - if _, err := time.Parse("2006-01-02", request.PerformedOn); err != nil { - return nil, fmt.Errorf("%w: performed_on must be a valid ISO-8601 date (YYYY-MM-DD)", ErrBadRequest) - } - resp, _, err := doJSON[TrackHabitActivityResponse](c, ctx, http.MethodPost, "/habits/"+habitID+"/track", request) if err != nil { return nil, err diff --git a/tools/habits.go b/tools/habits.go index 0dcd93661f2e1976cd1d59755a5f0568dd80d696..cf8719bc327919ce645d7acafd4e5b3f8254f163 100644 --- a/tools/habits.go +++ b/tools/habits.go @@ -36,11 +36,16 @@ func (h *Handlers) HandleTrackHabitActivity(ctx context.Context, request mcp.Cal return reportMCPError("Missing or invalid required argument: habit_id") } - performedOn, ok := request.Params.Arguments["performed_on"].(string) - if !ok || performedOn == "" { + performedOnStr, ok := request.Params.Arguments["performed_on"].(string) + if !ok || performedOnStr == "" { return reportMCPError("Missing or invalid required argument: performed_on") } + performedOn, err := lunatask.ParseDate(performedOnStr) + if err != nil { + return reportMCPError(fmt.Sprintf("Invalid format for performed_on: '%s'. Must be YYYY-MM-DD.", performedOnStr)) + } + client := lunatask.NewClient(h.config.AccessToken) habitRequest := &lunatask.TrackHabitActivityRequest{ PerformedOn: performedOn,