MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

server/handlers/tool.go:296–370  ·  view source on GitHub ↗

Execute executes a tool

(c *gin.Context)

Source from the content-addressed store, hash-verified

294
295// Execute executes a tool
296func (h *ToolHandler) Execute(c *gin.Context) {
297 ctx := c.Request.Context()
298 id := c.Param("id")
299
300 var req struct {
301 Input map[string]any `json:"input" binding:"required"`
302 }
303
304 if err := c.ShouldBindJSON(&req); err != nil {
305 c.JSON(http.StatusBadRequest, gin.H{
306 "success": false,
307 "error": gin.H{
308 "code": "bad_request",
309 "message": err.Error(),
310 },
311 })
312 return
313 }
314
315 // Check if tool exists
316 var tool ToolRecord
317 if err := (*h.store).Get(ctx, "tools", id, &tool); err != nil {
318 if errors.Is(err, store.ErrNotFound) {
319 c.JSON(http.StatusNotFound, gin.H{
320 "success": false,
321 "error": gin.H{
322 "code": "not_found",
323 "message": "Tool not found",
324 },
325 })
326 return
327 }
328 c.JSON(http.StatusInternalServerError, gin.H{
329 "success": false,
330 "error": gin.H{
331 "code": "internal_error",
332 "message": err.Error(),
333 },
334 })
335 return
336 }
337
338 // Create execution record
339 execution := &ToolExecution{
340 ID: uuid.New().String(),
341 ToolID: id,
342 Input: req.Input,
343 Status: "pending",
344 StartedAt: time.Now(),
345 }
346
347 if err := (*h.store).Set(ctx, "tool_executions", execution.ID, execution); err != nil {
348 c.JSON(http.StatusInternalServerError, gin.H{
349 "success": false,
350 "error": gin.H{
351 "code": "internal_error",
352 "message": err.Error(),
353 },

Callers

nothing calls this directly

Calls 7

InfoFunction · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
ErrorMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected