(projectRoot string, execCtx ExecutionContext)
| 264 | } |
| 265 | |
| 266 | var mcpNamePattern = regexp.MustCompile(`[^a-z0-9_]`) |
| 267 | |
| 268 | func sanitizeMCPPart(value string) string { |
| 269 | return mcpNamePattern.ReplaceAllString(strings.ToLower(value), "_") |
| 270 | } |
| 271 | |
| 272 | func trustedMCPConfigs(projectRoot string, execCtx ExecutionContext) []mcp.McpServerConfig { |
| 273 | if cfg, ok := execCtx["config"].(config.Config); ok && strings.TrimSpace(cfg.ProjectPaths.CanonicalRoot) != "" { |
| 274 | projectRoot = cfg.ProjectPaths.CanonicalRoot |
| 275 | } |
| 276 | configs := append([]mcp.McpServerConfig{}, mcp.LoadUserMCPConfig()...) |
| 277 | projectConfigs := mcp.LoadProjectMCPConfig(projectRoot) |
| 278 | if len(projectConfigs) == 0 { |
| 279 | return configs |
| 280 | } |
| 281 | trusted := mcp.LoadTrustedMCP(projectRoot) |
| 282 | var pending []map[string]any |
| 283 | var trustedProject []mcp.McpServerConfig |
| 284 | for _, cfg := range projectConfigs { |
| 285 | fingerprint := cfg.Fingerprint() |
| 286 | if trusted[cfg.Name] == fingerprint { |
| 287 | trustedProject = append(trustedProject, cfg) |
| 288 | continue |
| 289 | } |
| 290 | pending = append(pending, map[string]any{ |
| 291 | "name": cfg.Name, |
| 292 | "fingerprint": fingerprint, |
| 293 | "command": stringPtrValue(cfg.Command), |
| 294 | "args": append([]string(nil), cfg.Args...), |
| 295 | "cwd": stringPtrValue(cfg.CWD), |
| 296 | "url": stringPtrValue(cfg.URL), |
| 297 | }) |
| 298 | } |
| 299 | if len(pending) > 0 && execCtx != nil { |
| 300 | existing, _ := execCtx["pending_mcp_trust"].([]map[string]any) |
| 301 | execCtx["pending_mcp_trust"] = append(existing, pending...) |
| 302 | } |
| 303 | approvals, _ := execCtx["trusted_mcp_servers"].(map[string]string) |
| 304 | trustedChanged := false |
| 305 | if approvals != nil { |
| 306 | for _, cfg := range projectConfigs { |
| 307 | fingerprint := cfg.Fingerprint() |
| 308 | if approvals[cfg.Name] == fingerprint { |
| 309 | trusted[cfg.Name] = fingerprint |
| 310 | trustedProject = append(trustedProject, cfg) |
| 311 | trustedChanged = true |
| 312 | } |
| 313 | } |
no test coverage detected