MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / add_server

Method add_server

atomic-cli/src/commands/server/mod.rs:228–293  ·  view source on GitHub ↗

Add a new server profile.

(&self, add: &ServerAdd)

Source from the content-addressed store, hash-verified

226
227 /// Add a new server profile.
228 fn add_server(&self, add: &ServerAdd) -> CliResult<()> {
229 if !add.url.contains("://") {
230 return Err(CliError::InvalidArgument {
231 message: format!(
232 "Invalid URL '{}': must include a scheme (e.g. https://)",
233 add.url
234 ),
235 });
236 }
237
238 let mut config = GlobalConfig::load()
239 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load config: {}", e)))?;
240
241 if config.servers.contains_key(&add.name) {
242 return Err(CliError::InvalidArgument {
243 message: format!(
244 "Server profile '{}' already exists. \
245 Use 'atomic server set-identity' or 'atomic server remove' to modify it.",
246 add.name
247 ),
248 });
249 }
250
251 let profile = ServerConfig {
252 url: Some(add.url.trim_end_matches('/').to_string()),
253 default_org: add.org.clone(),
254 default_workspaces: std::collections::BTreeMap::new(),
255 identity: add.identity.clone(),
256 // Bound when an agent is created against this profile, not here.
257 agent_identity: None,
258 // Auto-detected at registration; manual profiles default to
259 // multi-tenant URL semantics.
260 single_tenant: false,
261 };
262
263 config.servers.insert(add.name.clone(), profile);
264
265 if add.set_default {
266 config.default_server = Some(add.name.clone());
267 }
268
269 config
270 .save()
271 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save config: {}", e)))?;
272
273 print_success(&format!("Server profile '{}' added", add.name));
274 println!(" URL: {}", add.url);
275 if let Some(ref org) = add.org {
276 println!(" Org: {}", org);
277 }
278 if let Some(ref identity) = add.identity {
279 println!(" Identity: {}", identity);
280 }
281 if add.set_default {
282 println!();
283 print_success(&format!("'{}' is now the active server", add.name));
284 } else {
285 println!();

Callers 1

runMethod · 0.80

Calls 7

print_successFunction · 0.85
print_hintFunction · 0.85
contains_keyMethod · 0.80
containsMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected