MCPcopy Create free account
hub / github.com/diillson/chatcli / ExecuteWithStream

Method ExecuteWithStream

cli/plugins/builtin_tools.go:111–139  ·  view source on GitHub ↗

ExecuteWithStream mirrors Execute — no incremental output.

(_ context.Context, args []string, _ func(string))

Source from the content-addressed store, hash-verified

109
110// ExecuteWithStream mirrors Execute — no incremental output.
111func (p *BuiltinToolsPlugin) ExecuteWithStream(_ context.Context, args []string, _ func(string)) (string, error) {
112 adapter := currentToolCatalogAdapter()
113 if adapter == nil {
114 return "", errors.New("@tools: no tool-catalog adapter wired in this session")
115 }
116 if len(args) == 0 {
117 return "", errors.New(`@tools: empty args. Example: <tool_call name="@tools" args='{"cmd":"describe","args":{"name":"@diagram"}}' />`)
118 }
119
120 cmd, inner, err := parseToolsInvocation(args)
121 if err != nil {
122 return "", fmt.Errorf("@tools: %w", err)
123 }
124 switch cmd {
125 case "describe":
126 var in struct {
127 Name string `json:"name"`
128 }
129 _ = json.Unmarshal([]byte(inner), &in)
130 if strings.TrimSpace(in.Name) == "" {
131 return "", errors.New(`@tools describe: "name" is required`)
132 }
133 return adapter.Describe(in.Name)
134 case "list":
135 return adapter.List()
136 default:
137 return "", fmt.Errorf("@tools: unknown cmd %q (valid: describe|list)", cmd)
138 }
139}
140
141// parseToolsInvocation accepts the JSON envelope {cmd, args} or the argv form
142// ("describe @diagram" / "list").

Callers 1

ExecuteMethod · 0.95

Calls 5

parseToolsInvocationFunction · 0.85
ErrorfMethod · 0.80
DescribeMethod · 0.65
ListMethod · 0.65

Tested by

no test coverage detected