parseAndDedup reads all config files and returns a deduplicated list of server configs. Missing files are silently skipped; parse errors are logged and skipped.
(ctx context.Context, mcpConfigFiles []string)
| 541 | // list of server configs. Missing files are silently skipped; |
| 542 | // parse errors are logged and skipped. |
| 543 | func (m *Manager) parseAndDedup(ctx context.Context, mcpConfigFiles []string) ([]ServerConfig, map[string]fileSnapshot) { |
| 544 | logger := m.logger.With(agentchat.Fields(ctx)...) |
| 545 | |
| 546 | // Stat before reading so the snapshot is conservatively old. |
| 547 | // If a file changes between stat and read, the snapshot |
| 548 | // records the old mtime, SnapshotChanged detects a mismatch |
| 549 | // on the next check, and triggers a re-read. False positives |
| 550 | // (extra reload) are safe; false negatives (missed change) |
| 551 | // are not. |
| 552 | snap := captureSnapshot(mcpConfigFiles) |
| 553 | |
| 554 | var allConfigs []ServerConfig |
| 555 | for _, configPath := range mcpConfigFiles { |
| 556 | configs, err := ParseConfig(configPath) |
| 557 | if err != nil { |
| 558 | if errors.Is(err, fs.ErrNotExist) { |
| 559 | continue |
| 560 | } |
| 561 | logger.Warn(ctx, "failed to parse MCP config", |
| 562 | slog.F("path", configPath), |
| 563 | slog.Error(err), |
| 564 | ) |
| 565 | continue |
| 566 | } |
| 567 | allConfigs = append(allConfigs, configs...) |
| 568 | } |
| 569 | |
| 570 | // Deduplicate by server name; first occurrence wins. |
| 571 | seen := make(map[string]struct{}) |
| 572 | deduped := make([]ServerConfig, 0, len(allConfigs)) |
| 573 | for _, cfg := range allConfigs { |
| 574 | if _, ok := seen[cfg.Name]; ok { |
| 575 | continue |
| 576 | } |
| 577 | seen[cfg.Name] = struct{}{} |
| 578 | deduped = append(deduped, cfg) |
| 579 | } |
| 580 | return deduped, snap |
| 581 | } |
| 582 | |
| 583 | // classifyServers compares wanted configs against the current |
| 584 | // server map and returns a diff describing what changed. |
no test coverage detected