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

Method handleToolCall

pkg/tools/bridge/http_server.go:128–161  ·  view source on GitHub ↗

handleToolCall 处理工具调用请求

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

Source from the content-addressed store, hash-verified

126
127// handleToolCall 处理工具调用请求
128func (s *HTTPBridgeServer) handleToolCall(w http.ResponseWriter, r *http.Request) {
129 // 仅支持 POST
130 if r.Method != http.MethodPost {
131 http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
132 return
133 }
134
135 // 解析请求
136 var req ToolCallRequest
137 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
138 s.sendError(w, "Invalid JSON request", http.StatusBadRequest)
139 return
140 }
141
142 // 验证参数
143 if req.Tool == "" {
144 s.sendError(w, "Tool name is required", http.StatusBadRequest)
145 return
146 }
147
148 // 获取工具上下文
149 tc := s.getToolContext()
150
151 // 调用工具
152 ctx := r.Context()
153 result, _ := s.bridge.CallTool(ctx, req.Tool, req.Input, tc)
154
155 // 返回响应
156 s.sendJSON(w, &ToolCallResponse{
157 Success: result.Success,
158 Result: result.Result,
159 Error: result.Error,
160 })
161}
162
163// handleToolList 处理工具列表请求
164func (s *HTTPBridgeServer) handleToolList(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 6

sendErrorMethod · 0.95
getToolContextMethod · 0.95
sendJSONMethod · 0.95
ErrorMethod · 0.65
ContextMethod · 0.65
CallToolMethod · 0.45

Tested by

no test coverage detected