@@ -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
@@ -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,