MCPcopy Create free account
hub / github.com/compozy/agh / newToolInvokeCommand

Function newToolInvokeCommand

internal/cli/tool_operator.go:224–278  ·  view source on GitHub ↗
(deps commandDeps)

Source from the content-addressed store, hash-verified

222}
223
224func newToolInvokeCommand(deps commandDeps) *cobra.Command {
225 var flags toolInvokeFlags
226 cmd := &cobra.Command{
227 Use: "invoke <tool_id>",
228 Short: "Invoke one registry tool through daemon policy",
229 Example: ` # Invoke a tool with inline JSON input
230 agh tool invoke agh__tool_info --input '{"tool_id":"agh__skill_view"}' -o json
231
232 # Invoke a tool with JSON read from a file
233 agh tool invoke agh__tool_info --input-file ./input.json -o json
234
235 # Invoke a tool with JSON read from stdin
236 echo '{"tool_id":"agh__skill_view"}' | agh tool invoke agh__tool_info -o json`,
237 Args: exactOneNonBlankArg(),
238 RunE: func(cmd *cobra.Command, args []string) error {
239 id, err := parseToolIDArg(args[0])
240 if err != nil {
241 return writeToolCommandError(cmd, err)
242 }
243 input, err := resolveToolInvokeInput(cmd, flags)
244 if err != nil {
245 return writeToolCommandError(cmd, toolValidationCommandError(id, "tool input is invalid", err))
246 }
247 return runToolCommand(cmd, deps, func(client DaemonClient) error {
248 request := ToolInvokeRequest{
249 SessionID: strings.TrimSpace(flags.scope.sessionID),
250 WorkspaceID: strings.TrimSpace(flags.scope.workspaceID),
251 AgentName: strings.TrimSpace(flags.scope.agentName),
252 ToolCallID: strings.TrimSpace(flags.toolCallID),
253 TurnID: strings.TrimSpace(flags.turnID),
254 CorrelationID: strings.TrimSpace(flags.correlationID),
255 ApprovalToken: strings.TrimSpace(flags.approvalToken),
256 Input: input,
257 SensitiveInputFields: trimNonEmptyStrings(flags.sensitiveInputFields),
258 }
259 response, err := client.InvokeTool(cmd.Context(), id.String(), request)
260 if err != nil {
261 return err
262 }
263 return writeCommandOutput(cmd, toolInvokeBundle(sanitizeToolInvokeResponse(response)))
264 })
265 },
266 }
267 flags.scope.bind(cmd)
268 cmd.Flags().StringVar(&flags.input, "input", "", "Inline JSON input")
269 cmd.Flags().StringVar(&flags.inputFile, "input-file", "", "Path to JSON input file, or '-' for stdin")
270 cmd.Flags().StringVar(&flags.toolCallID, "tool-call-id", "", "Optional caller tool-call id")
271 cmd.Flags().StringVar(&flags.turnID, "turn-id", "", "Optional caller turn id")
272 cmd.Flags().StringVar(&flags.correlationID, "correlation-id", "", "Optional correlation id")
273 cmd.Flags().
274 StringVar(&flags.approvalToken, "approval-token", "", "Single-use approval token for approval-gated tools")
275 cmd.Flags().
276 StringArrayVar(&flags.sensitiveInputFields, "sensitive-input-field", nil, "Input field path to redact in events")
277 return cmd
278}
279
280func newToolsetsCommand(deps commandDeps) *cobra.Command {
281 cmd := &cobra.Command{

Callers 1

newToolCommandFunction · 0.85

Calls 13

exactOneNonBlankArgFunction · 0.85
parseToolIDArgFunction · 0.85
writeToolCommandErrorFunction · 0.85
resolveToolInvokeInputFunction · 0.85
runToolCommandFunction · 0.85
trimNonEmptyStringsFunction · 0.85
writeCommandOutputFunction · 0.85
toolInvokeBundleFunction · 0.85
InvokeToolMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected