1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5// Package areas provides the list_areas_and_goals MCP tool.
6package areas
7
8import (
9 "context"
10 "fmt"
11 "strings"
12
13 "github.com/mark3labs/mcp-go/mcp"
14
15 "git.sr.ht/~amolith/lunatask-mcp-server/tools/shared"
16)
17
18// Handler handles area-related MCP tool calls.
19type Handler struct {
20 areas []shared.AreaProvider
21}
22
23// NewHandler creates a new areas Handler.
24func NewHandler(areas []shared.AreaProvider) *Handler {
25 return &Handler{areas: areas}
26}
27
28// Handle handles the list_areas_and_goals tool call.
29func (h *Handler) Handle(
30 _ context.Context,
31 _ mcp.CallToolRequest,
32) (*mcp.CallToolResult, error) {
33 var builder strings.Builder
34
35 for _, area := range h.areas {
36 fmt.Fprintf(&builder, "- %s: %s\n", area.GetName(), area.GetID())
37
38 for _, goal := range area.GetGoals() {
39 fmt.Fprintf(&builder, " - %s: %s\n", goal.GetName(), goal.GetID())
40 }
41 }
42
43 return &mcp.CallToolResult{
44 Content: []mcp.Content{
45 mcp.TextContent{
46 Type: "text",
47 Text: builder.String(),
48 },
49 },
50 }, nil
51}