parseGitHubTool converts raw github tool configuration to GitHubToolConfig
(val any)
| 187 | |
| 188 | // parseGitHubTool converts raw github tool configuration to GitHubToolConfig |
| 189 | func parseGitHubTool(val any) *GitHubToolConfig { |
| 190 | if val == nil { |
| 191 | toolsParserLog.Print("GitHub tool enabled with default configuration") |
| 192 | return &GitHubToolConfig{ |
| 193 | ReadOnly: true, // default to read-only for security |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Handle string type (simple enable) |
| 198 | if _, ok := val.(string); ok { |
| 199 | toolsParserLog.Print("GitHub tool enabled with string configuration") |
| 200 | return &GitHubToolConfig{ |
| 201 | ReadOnly: true, // default to read-only for security |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Handle map type (detailed configuration) |
| 206 | if configMap, ok := val.(map[string]any); ok { |
| 207 | toolsParserLog.Print("Parsing GitHub tool detailed configuration") |
| 208 | config := &GitHubToolConfig{ |
| 209 | ReadOnly: true, // default to read-only for security |
| 210 | } |
| 211 | |
| 212 | if allowedSetting, ok := configMap["allowed"]; ok { |
| 213 | // Tool call limits are enforced by MCP guard policies; parser keeps only tool names. |
| 214 | allowedTools, _ := parseGitHubAllowedToolsAndLimits(allowedSetting) |
| 215 | config.Allowed = make(GitHubAllowedTools, 0, len(allowedTools)) |
| 216 | for _, toolName := range allowedTools { |
| 217 | config.Allowed = append(config.Allowed, GitHubToolName(toolName)) |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if mode, ok := configMap["mode"].(string); ok { |
| 222 | config.Mode = GitHubMCPMode(mode) |
| 223 | } |
| 224 | if mcpType, ok := configMap["type"].(string); ok { |
| 225 | config.Type = mcpType |
| 226 | } |
| 227 | |
| 228 | if version, ok := configMap["version"].(string); ok { |
| 229 | config.Version = version |
| 230 | } |
| 231 | |
| 232 | if args, ok := configMap["args"].([]any); ok { |
| 233 | config.Args = make([]string, 0, len(args)) |
| 234 | for _, item := range args { |
| 235 | if str, ok := item.(string); ok { |
| 236 | config.Args = append(config.Args, str) |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if readOnly, ok := configMap["read-only"].(bool); ok { |
| 242 | config.ReadOnly = readOnly |
| 243 | } |
| 244 | // else: defaults to true (set above) |
| 245 | |
| 246 | if token, ok := configMap["github-token"].(string); ok { |