LoadConfig loads MCP server configurations from a JSON file.
(configPath string)
| 146 | |
| 147 | // LoadConfig loads MCP server configurations from a JSON file. |
| 148 | func (m *Manager) LoadConfig(configPath string) error { |
| 149 | data, err := os.ReadFile(configPath) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream) |
| 150 | if err != nil { |
| 151 | if os.IsNotExist(err) { |
| 152 | return nil // No config is fine |
| 153 | } |
| 154 | return fmt.Errorf("reading MCP config: %w", err) |
| 155 | } |
| 156 | |
| 157 | var configs struct { |
| 158 | Servers []ServerConfig `json:"mcpServers"` |
| 159 | } |
| 160 | if err := json.Unmarshal(data, &configs); err != nil { |
| 161 | return fmt.Errorf("parsing MCP config: %w", err) |
| 162 | } |
| 163 | |
| 164 | for _, cfg := range configs.Servers { |
| 165 | if cfg.Enabled { |
| 166 | m.mu.Lock() |
| 167 | m.servers[cfg.Name] = &ServerConnection{ |
| 168 | Config: cfg, |
| 169 | Status: ServerStatus{Name: cfg.Name, Starting: true}, |
| 170 | logs: newLogRing(mcpLogRingCapacity), |
| 171 | } |
| 172 | m.mu.Unlock() |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | m.logger.Info("MCP servers loaded", zap.Int("count", len(m.servers))) |
| 177 | return nil |
| 178 | } |
| 179 | |
| 180 | // DefaultConfigPath returns the default MCP config file path. |
| 181 | func DefaultConfigPath() string { |