MCPcopy Create free account
hub / github.com/github/gh-aw / parseGitHubAllowedToolsAndLimits

Function parseGitHubAllowedToolsAndLimits

pkg/workflow/mcp_github_config.go:266–302  ·  view source on GitHub ↗

parseGitHubAllowedToolsAndLimits parses tools.github.allowed entries. Supports string entries and object entries: {name: "tool_name", max-calls: 1}.

(allowedSetting any)

Source from the content-addressed store, hash-verified

264// Supports string entries and object entries:
265// {name: "tool_name", max-calls: 1}.
266func parseGitHubAllowedToolsAndLimits(allowedSetting any) ([]string, map[string]int) {
267 allowedItems, ok := allowedSetting.([]any)
268 if !ok {
269 return parseStringSliceAny(allowedSetting, nil), nil
270 }
271
272 allowedTools := make([]string, 0, len(allowedItems))
273 toolCallLimits := make(map[string]int)
274
275 for _, item := range allowedItems {
276 switch entry := item.(type) {
277 case string:
278 toolName := strings.TrimSpace(entry)
279 if toolName == "" {
280 continue
281 }
282 allowedTools = append(allowedTools, toolName)
283 case map[string]any:
284 toolName, ok := entry["name"].(string)
285 toolName = strings.TrimSpace(toolName)
286 if !ok || toolName == "" {
287 continue
288 }
289 allowedTools = append(allowedTools, toolName)
290 if maxCalls, hasMax := entry["max-calls"]; hasMax {
291 if max, ok := typeutil.ParseIntValue(maxCalls); ok && max > 0 {
292 toolCallLimits[toolName] = max
293 }
294 }
295 }
296 }
297
298 if len(toolCallLimits) == 0 {
299 return allowedTools, nil
300 }
301 return allowedTools, toolCallLimits
302}
303
304// getGitHubGuardPolicies extracts guard policies from GitHub tool configuration.
305// It reads the flat allowed-repos/repos/min-integrity/blocked-users/trusted-users/approval-labels fields

Callers 3

getGitHubAllowedToolsFunction · 0.85
getGitHubGuardPoliciesFunction · 0.85
parseGitHubToolFunction · 0.85

Calls 2

ParseIntValueFunction · 0.92
parseStringSliceAnyFunction · 0.85

Tested by

no test coverage detected