(ctx context.Context, name string, r map[string]any)
| 384 | } |
| 385 | |
| 386 | func UnmarshalYAMLToolConfig(ctx context.Context, name string, r map[string]any) (tools.ToolConfig, error) { |
| 387 | resourceType, ok := r["type"].(string) |
| 388 | if !ok { |
| 389 | return nil, fmt.Errorf("missing 'type' field or it is not a string") |
| 390 | } |
| 391 | // `authRequired` and `useClientOAuth` cannot be specified together |
| 392 | if r["authRequired"] != nil && r["useClientOAuth"] == true { |
| 393 | return nil, fmt.Errorf("`authRequired` and `useClientOAuth` are mutually exclusive. Choose only one authentication method") |
| 394 | } |
| 395 | // Make `authRequired` an empty list instead of nil for Tool manifest |
| 396 | if r["authRequired"] == nil { |
| 397 | r["authRequired"] = []string{} |
| 398 | } |
| 399 | |
| 400 | // Parse scopesRequired if present |
| 401 | if rawScopes, ok := r["scopesRequired"]; ok { |
| 402 | if scopesList, ok := rawScopes.([]any); ok { |
| 403 | var scopes []string |
| 404 | for _, s := range scopesList { |
| 405 | if str, ok := s.(string); ok { |
| 406 | scopes = append(scopes, str) |
| 407 | } |
| 408 | } |
| 409 | r["scopesRequired"] = scopes |
| 410 | } else { |
| 411 | return nil, fmt.Errorf("scopesRequired must be a list of strings") |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // validify parameter references |
| 416 | if rawParams, ok := r["parameters"]; ok { |
| 417 | if paramsList, ok := rawParams.([]any); ok { |
| 418 | // Turn params into a map |
| 419 | validParamNames := make(map[string]bool) |
| 420 | for _, rawP := range paramsList { |
| 421 | if pMap, ok := rawP.(map[string]any); ok { |
| 422 | if pName, ok := pMap["name"].(string); ok && pName != "" { |
| 423 | validParamNames[pName] = true |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // Validate references |
| 429 | for i, rawP := range paramsList { |
| 430 | pMap, ok := rawP.(map[string]any) |
| 431 | if !ok { |
| 432 | continue |
| 433 | } |
| 434 | |
| 435 | pName, _ := pMap["name"].(string) |
| 436 | refName, _ := pMap["valueFromParam"].(string) |
| 437 | |
| 438 | if refName != "" { |
| 439 | // Check if the referenced parameter exists |
| 440 | if !validParamNames[refName] { |
| 441 | return nil, fmt.Errorf("tool %q config error: parameter %q (index %d) references '%q' in the 'valueFromParam' field, which is not a defined parameter", name, pName, i, refName) |
| 442 | } |
| 443 |
no test coverage detected