handleToolSchema 处理工具 Schema 请求(带缓存)
(w http.ResponseWriter, r *http.Request)
| 175 | |
| 176 | // handleToolSchema 处理工具 Schema 请求(带缓存) |
| 177 | func (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 健康检查 |
| 209 | func (s *HTTPBridgeServer) handleHealth(w http.ResponseWriter, r *http.Request) { |