delete.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package note
 6
 7import (
 8	"context"
 9
10	"git.secluded.site/go-lunatask"
11	"git.secluded.site/lune/internal/mcp/shared"
12	"github.com/modelcontextprotocol/go-sdk/mcp"
13)
14
15// DeleteToolName is the name of the delete note tool.
16const DeleteToolName = "delete_note"
17
18// DeleteToolDescription describes the delete note tool for LLMs.
19const DeleteToolDescription = `Deletes a note from Lunatask.
20
21Required:
22- id: Note UUID or lunatask://note/... deep link
23
24This action is permanent and cannot be undone.`
25
26// DeleteInput is the input schema for deleting a note.
27type DeleteInput struct {
28	ID string `json:"id" jsonschema:"required"`
29}
30
31// DeleteOutput is the output schema for deleting a note.
32type DeleteOutput struct {
33	Success  bool   `json:"success"`
34	DeepLink string `json:"deep_link"`
35}
36
37// HandleDelete deletes a note.
38func (h *Handler) HandleDelete(
39	ctx context.Context,
40	_ *mcp.CallToolRequest,
41	input DeleteInput,
42) (*mcp.CallToolResult, DeleteOutput, error) {
43	id, err := parseReference(input.ID)
44	if err != nil {
45		return shared.ErrorResult(err.Error()), DeleteOutput{}, nil
46	}
47
48	note, err := h.client.DeleteNote(ctx, id)
49	if err != nil {
50		return shared.ErrorResult(err.Error()), DeleteOutput{}, nil
51	}
52
53	deepLink, _ := lunatask.BuildDeepLink(lunatask.ResourceNote, note.ID)
54
55	return &mcp.CallToolResult{
56			Content: []mcp.Content{&mcp.TextContent{
57				Text: "Note deleted: " + deepLink,
58			}},
59		}, DeleteOutput{
60			Success:  true,
61			DeepLink: deepLink,
62		}, nil
63}