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

Method List

server/handlers/tool.go:95–134  ·  view source on GitHub ↗

List lists all tools

(c *gin.Context)

Source from the content-addressed store, hash-verified

93
94// List lists all tools
95func (h *ToolHandler) List(c *gin.Context) {
96 ctx := c.Request.Context()
97 status := c.Query("status")
98 toolType := c.Query("type")
99
100 records, err := (*h.store).List(ctx, "tools")
101 if err != nil {
102 c.JSON(http.StatusInternalServerError, gin.H{
103 "success": false,
104 "error": gin.H{
105 "code": "internal_error",
106 "message": err.Error(),
107 },
108 })
109 return
110 }
111
112 tools := make([]*ToolRecord, 0)
113 for _, record := range records {
114 var tool ToolRecord
115 if err := store.DecodeValue(record, &tool); err != nil {
116 continue
117 }
118
119 // Filter
120 if status != "" && tool.Status != status {
121 continue
122 }
123 if toolType != "" && tool.Type != toolType {
124 continue
125 }
126
127 tools = append(tools, &tool)
128 }
129
130 c.JSON(http.StatusOK, gin.H{
131 "success": true,
132 "data": tools,
133 })
134}
135
136// Get retrieves a single tool
137func (h *ToolHandler) Get(c *gin.Context) {

Callers

nothing calls this directly

Calls 6

DecodeValueFunction · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
QueryMethod · 0.65
ListMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected