package caption import ( "bytes" "context" "io" "log/slog" "github.com/eat-pray-ai/yutu/cmd" "github.com/eat-pray-ai/yutu/pkg/caption" "github.com/mark3labs/mcp-go/mcp" "github.com/spf13/cobra" ) const ( deleteShort = "Delete captions" deleteLong = "Delete captions of a video by ids" deleteIdsUsage = "IDs of the captions to delete" ) func init() { cmd.MCP.AddTool(deleteTool, deleteHandler) captionCmd.AddCommand(deleteCmd) deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, deleteIdsUsage) deleteCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "") deleteCmd.Flags().StringVarP( &onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "", ) _ = deleteCmd.MarkFlagRequired("ids") } var deleteCmd = &cobra.Command{ Use: "delete", Short: deleteShort, Long: deleteLong, Run: func(cmd *cobra.Command, args []string) { err := del(cmd.OutOrStdout()) if err != nil { _ = cmd.Help() cmd.PrintErrf("Error: %v\n", err) } }, } var deleteTool = mcp.NewTool( "caption-delete", mcp.WithTitleAnnotation(deleteShort), mcp.WithDescription(deleteLong), mcp.WithDestructiveHintAnnotation(true), mcp.WithOpenWorldHintAnnotation(true), mcp.WithReadOnlyHintAnnotation(false), mcp.WithArray( "ids", mcp.DefaultArray([]string{}), mcp.Items(map[string]any{"type": "string"}), mcp.Description(deleteIdsUsage), mcp.Required(), ), mcp.WithString( "onBehalfOf", mcp.DefaultString(""), mcp.Description(""), mcp.Required(), ), mcp.WithString( "onBehalfOfContentOwner", mcp.DefaultString(""), mcp.Description(""), mcp.Required(), ), ) func deleteHandler( ctx context.Context, request mcp.CallToolRequest, ) (*mcp.CallToolResult, error) { args := request.GetArguments() idsRaw, _ := args["ids"].([]any) ids := make([]string, len(idsRaw)) for i, id := range idsRaw { ids[i] = id.(string) } onBehalfOf, _ = args["onBehalfOf"].(string) onBehalfOfContentOwner, _ = args["onBehalfOfContentOwner"].(string) slog.InfoContext(ctx, "caption delete started") var writer bytes.Buffer err := del(&writer) if err != nil { slog.ErrorContext( ctx, "caption delete failed", "error", err, "args", args, ) return mcp.NewToolResultError(err.Error()), err } slog.InfoContext( ctx, "caption delete completed successfully", "resultSize", writer.Len(), ) return mcp.NewToolResultText(writer.String()), nil } func del(writer io.Writer) error { c := caption.NewCation( caption.WithIDs(ids), caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), caption.WithService(nil), ) return c.Delete(writer) }