// Copyright 2025 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package channelSection
import (
"encoding/json"
"io"
"github.com/eat-pray-ai/yutu/cmd"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/channelSection"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/spf13/cobra"
)
const (
listTool = "channelSection-list"
listShort = "List channel sections"
listLong = "List channel sections"
listIdsUsage = "Return the channel sections with the given ids"
)
var listInSchema = &jsonschema.Schema{
Type: "object",
Required: []string{},
Properties: map[string]*jsonschema.Schema{
"ids": {
Type: "array", Description: listIdsUsage,
Items: &jsonschema.Schema{Type: "string"},
},
"channel_id": {Type: "string", Description: cidUsage},
"hl": {Type: "string", Description: hlUsage},
"mine": {Type: "boolean", Description: mineUsage},
"on_behalf_of_content_owner": {Type: "string"},
"parts": {
Type: "array", Description: pkg.PartsUsage,
Items: &jsonschema.Schema{Type: "string"},
Default: json.RawMessage(`["id","snippet"]`),
},
"output": {
Type: "string", Enum: []any{"json", "yaml", "table"},
Description: pkg.TableUsage, Default: json.RawMessage(`"yaml"`),
},
"jsonpath": {Type: "string", Description: pkg.JPUsage},
},
}
func init() {
mcp.AddTool(
cmd.Server, &mcp.Tool{
Name: listTool, Title: listShort, Description: listLong,
InputSchema: listInSchema, Annotations: &mcp.ToolAnnotations{
DestructiveHint: jsonschema.Ptr(false),
IdempotentHint: true,
OpenWorldHint: jsonschema.Ptr(true),
ReadOnlyHint: true,
},
}, cmd.GenToolHandler(
listTool,
func(input channelSection.ChannelSection, writer io.Writer) error {
return input.List(writer)
},
),
)
channelSectionCmd.AddCommand(listCmd)
listCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, listIdsUsage)
listCmd.Flags().StringVarP(&channelId, "channelId", "c", "", cidUsage)
listCmd.Flags().StringVarP(&hl, "hl", "l", "", hlUsage)
listCmd.Flags().BoolVarP(mine, "mine", "M", false, mineUsage)
listCmd.Flags().StringVarP(
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", "",
)
listCmd.Flags().StringSliceVarP(
&parts, "parts", "p", []string{"id", "snippet"}, pkg.PartsUsage,
)
listCmd.Flags().StringVarP(&output, "output", "o", "table", pkg.TableUsage)
listCmd.Flags().StringVarP(&jsonpath, "jsonpath", "j", "", pkg.JPUsage)
}
var listCmd = &cobra.Command{
Use: "list",
Short: listShort,
Long: listLong,
Run: func(cmd *cobra.Command, args []string) {
input := channelSection.NewChannelSection(
channelSection.WithIds(ids),
channelSection.WithChannelId(channelId),
channelSection.WithHl(hl),
channelSection.WithMine(mine),
channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
channelSection.WithParts(parts),
channelSection.WithOutput(output),
channelSection.WithJsonpath(jsonpath),
)
utils.HandleCmdError(input.List(cmd.OutOrStdout()), cmd)
},
}