1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5// Package timestamp provides the get_timestamp MCP tool for parsing natural
6// language dates into formatted timestamps.
7package timestamp
8
9import (
10 "context"
11 "fmt"
12 "time"
13
14 "github.com/ijt/go-anytime"
15 "github.com/modelcontextprotocol/go-sdk/mcp"
16
17 "git.secluded.site/lunatask-mcp-server/tools/shared"
18)
19
20// Handler handles timestamp-related MCP tool calls.
21type Handler struct {
22 timezone string
23}
24
25// NewHandler creates a new timestamp Handler.
26func NewHandler(timezone string) *Handler {
27 return &Handler{timezone: timezone}
28}
29
30// Handle handles the get_timestamp tool call.
31func (h *Handler) Handle(
32 _ context.Context,
33 _ *mcp.CallToolRequest,
34 input Input,
35) (*mcp.CallToolResult, Output, error) {
36 loc, err := shared.LoadLocation(h.timezone)
37 if err != nil {
38 return nil, Output{}, err
39 }
40
41 parsedTime, err := anytime.Parse(input.NaturalLanguageDate, time.Now().In(loc))
42 if err != nil {
43 return nil, Output{}, fmt.Errorf(
44 "could not parse natural language date %q: %w",
45 input.NaturalLanguageDate,
46 err,
47 )
48 }
49
50 return nil, Output{Timestamp: parsedTime.Format(time.RFC3339)}, nil
51}