MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Invoke

Method Invoke

module/mcp/iml.go:202–302  ·  view source on GitHub ↗
(ctx context.Context, req mcp.CallToolRequest)

Source from the content-addressed store, hash-verified

200)
201
202func (i *imlMcpModule) Invoke(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
203 gatewayInvoke := utils.GatewayInvoke(ctx)
204
205 if gatewayInvoke == "" {
206 return nil, fmt.Errorf("gateway invoke is required")
207 }
208 u, err := url.Parse(gatewayInvoke)
209 if err != nil {
210 return nil, fmt.Errorf("parse gateway invoke error: %w", err)
211 }
212 if u.Scheme == "" {
213 u.Scheme = "http"
214 }
215
216 path, ok := req.GetArguments()["path"].(string)
217 if !ok {
218 return nil, fmt.Errorf("invalid path")
219 }
220 u.Path = fmt.Sprintf("%s/%s", strings.TrimSuffix(u.Path, "/"), strings.TrimPrefix(path, "/"))
221
222 method, ok := req.GetArguments()["method"].(string)
223 if !ok {
224 method = "GET"
225 }
226 queryParam := url.Values{}
227 query, ok := req.GetArguments()["query"].(map[string]interface{})
228 if ok {
229 for k, v := range query {
230 switch v := v.(type) {
231 case string:
232 queryParam.Add(k, v)
233 case []string:
234 for _, value := range v {
235 queryParam.Add(k, value)
236 }
237 case float64:
238 queryParam.Add(k, strconv.FormatFloat(v, 'f', -1, 64))
239 default:
240 return nil, fmt.Errorf("invalid query param type: %T", v)
241 }
242 }
243 }
244 u.RawQuery = queryParam.Encode()
245 headerParam := http.Header{}
246 header, ok := req.GetArguments()["header"].(map[string]interface{})
247 if ok {
248 for k, v := range header {
249 switch v := v.(type) {
250 case string:
251 headerParam.Set(k, v)
252 case []string:
253 for _, value := range v {
254 headerParam.Set(k, value)
255 }
256 default:
257 return nil, fmt.Errorf("invalid header param type: %T", v)
258 }
259 }

Callers

nothing calls this directly

Calls 5

EncodeMethod · 0.80
LabelMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected