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

Method handleToolSchema

pkg/tools/bridge/http_server.go:177–206  ·  view source on GitHub ↗

handleToolSchema 处理工具 Schema 请求(带缓存)

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

175
176// handleToolSchema 处理工具 Schema 请求(带缓存)
177func (s *HTTPBridgeServer) handleToolSchema(w http.ResponseWriter, r *http.Request) {
178 if r.Method != http.MethodGet {
179 http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
180 return
181 }
182
183 toolName := r.URL.Query().Get("name")
184 if toolName == "" {
185 s.sendError(w, "Tool name is required", http.StatusBadRequest)
186 return
187 }
188
189 // 尝试从缓存获取
190 if cachedSchema, ok := s.schemaCache.get(toolName); ok {
191 s.sendJSON(w, cachedSchema)
192 return
193 }
194
195 // 缓存未命中,从 bridge 获取
196 schema, err := s.bridge.GetToolSchema(toolName)
197 if err != nil {
198 s.sendError(w, err.Error(), http.StatusNotFound)
199 return
200 }
201
202 // 存入缓存
203 s.schemaCache.set(toolName, schema)
204
205 s.sendJSON(w, schema)
206}
207
208// handleHealth 健康检查
209func (s *HTTPBridgeServer) handleHealth(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 8

sendErrorMethod · 0.95
sendJSONMethod · 0.95
GetToolSchemaMethod · 0.80
ErrorMethod · 0.65
GetMethod · 0.65
QueryMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected