The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(ops): replace direct registry access with store module functions
Steven Enamakel05c23428b48b
diff --git a/src/openhuman/mcp/registry/custom/ops.rs b/src/openhuman/mcp/registry/custom/ops.rsindex cc940fe241..9e61b6a0ca 100644--- a/src/openhuman/mcp/registry/custom/ops.rs+++ b/src/openhuman/mcp/registry/custom/ops.rs@@ -6,15 +6,17 @@use std::collections::HashMap;+use crate::core::bus::BUS;+use crate::core::events::DomainEvent;use serde_json::{json, Value};-use tinymcp_bus::{InstalledServer, ServerProvenance};use uuid::Uuid;-use crate::core::event_bus::{publish_global, DomainEvent};use crate::openhuman::config::Config;use crate::openhuman::mcp::host;use crate::rpc::RpcOutcome;+use super::super::store;+use super::super::types::{InstalledServer, ServerProvenance};use super::validate::{base_slug, build_custom_transport, clean_description, credential_scope, env_key_list,resolve_env, resolve_env_for_transport, validate_env,@@ -22,12 +24,6 @@ use super::validate::{use super::{CustomServerInput, CUSTOM_QUALIFIED_PREFIX, MAX_SLUG_ATTEMPTS};/// The dynamic registry for `config`'s workspace, or an error string.-fn registry(config: &Config) -> Result<&tinymcp::McpRegistry, String> {- host::for_config(config)- .map(|service| service.dynamic())- .map_err(|error| format!("failed to open the MCP service: {error}"))-}-fn allocate_qualified_name(config: &Config,display_name: &str,@@ -37,15 +33,13 @@ fn allocate_qualified_name("{CUSTOM_QUALIFIED_PREFIX}{}",base_slug(display_name, server_id));- let store = registry(config)?.store();for attempt in 0..MAX_SLUG_ATTEMPTS {let candidate = if attempt == 0 {base.clone()} else {format!("{base}-{}", attempt + 1)};- let taken = store- .find_server_by_qualified_name(&candidate)+ let taken = store::find_server_by_qualified_name(config, &candidate).map_err(|e| e.to_string())?.is_some();if !taken {@@ -138,7 +132,7 @@ pub async fn mcp_clients_add_custom(server.qualified_name);- publish_global(DomainEvent::McpServerInstalled {+ BUS.publish(DomainEvent::McpServerInstalled {server_id: server_id.clone(),qualified_name: server.qualified_name.clone(),});@@ -173,9 +167,6 @@ pub async fn mcp_clients_update_custom(let (transport, command_kind, command, args) = build_custom_transport(&input)?;validate_env(&input.env, transport.is_http_remote())?;- let reg = registry(config)?;- let store = reg.store();-// Read the current record, resolve env, and write both tables as one// serializable transaction (see `Store::update_server_rmw`).// Provenance, the previous transport (for credential-scope), and the stored@@ -184,58 +175,56 @@ pub async fn mcp_clients_update_custom(// `update_custom` could switch transport and store new-scope credentials —// and a stale snapshot could revert the token or mis-scope and carry the// new credentials across origins.- let updated = store- .update_server_rmw(&server_id, |current, stored_env| {- if current.provenance != ServerProvenance::Custom {- return Err(tinymcp::Error::other(format!(- "server `{server_id}` was installed from a registry; its command and endpoint \+ let updated = store::update_custom_server_rmw(config, &server_id, |current, stored_env| {+ if current.provenance != ServerProvenance::Custom {+ return Err(tinymcp::Error::other(format!(+ "server `{server_id}` was installed from a registry; its command and endpoint \come from the catalog listing and cannot be edited here"- )));- }- let scope_changed =- credential_scope(¤t.transport) != credential_scope(&transport);- let env = resolve_env_for_transport(- &input.env,- &stored_env.into_iter().collect::<HashMap<String, String>>(),- ¤t.transport,- &transport,- );- tracing::debug!(- "[mcp-custom] update server_id={} transport={}{} env_keys={:?}",- server_id,- transport.dispatch_kind(),- if scope_changed {- " (re-scoped — stored env dropped)"- } else {- ""- },- env.keys().collect::<Vec<_>>()- );- let record = InstalledServer {- // Identity and provenance survive an edit untouched — re-deriving- // `qualified_name` from the new display name would orphan this row's- // env values.- server_id: current.server_id.clone(),- qualified_name: current.qualified_name.clone(),- installed_at: current.installed_at,- provenance: current.provenance,- icon_url: current.icon_url.clone(),- config: current.config.clone(),- enabled: current.enabled,- last_connected_at: current.last_connected_at,-- display_name: display_name.clone(),- description: clean_description(input.description.clone()),- command_kind,- command: command.clone(),- args: args.clone(),- env_keys: env_key_list(&env),- transport: transport.clone(),- };- let env_btree: std::collections::BTreeMap<String, String> = env.into_iter().collect();- Ok((record, env_btree))- })- .map_err(|e| e.to_string())?;+ )));+ }+ let scope_changed = credential_scope(¤t.transport) != credential_scope(&transport);+ let env = resolve_env_for_transport(+ &input.env,+ &stored_env.into_iter().collect::<HashMap<String, String>>(),+ ¤t.transport,+ &transport,+ );+ tracing::debug!(+ "[mcp-custom] update server_id={} transport={}{} env_keys={:?}",+ server_id,+ transport.dispatch_kind(),+ if scope_changed {+ " (re-scoped — stored env dropped)"+ } else {+ ""+ },+ env.keys().collect::<Vec<_>>()+ );+ let record = InstalledServer {+ // Identity and provenance survive an edit untouched — re-deriving+ // `qualified_name` from the new display name would orphan this row's+ // env values.+ server_id: current.server_id.clone(),+ qualified_name: current.qualified_name.clone(),+ installed_at: current.installed_at,+ provenance: current.provenance,+ icon_url: current.icon_url.clone(),+ config: current.config.clone(),+ enabled: current.enabled,+ last_connected_at: current.last_connected_at,++ display_name: display_name.clone(),+ description: clean_description(input.description.clone()),+ command_kind,+ command: command.clone(),+ args: args.clone(),+ env_keys: env_key_list(&env),+ transport: transport.clone(),+ };+ let env_btree: std::collections::BTreeMap<String, String> = env.into_iter().collect();+ Ok((record, env_btree))+ })+ .map_err(|e| e.to_string())?;// Only now drop the live connection: it was dialed with the previous command// or URL, so leaving it up would keep serving tools from the old@@ -244,7 +233,9 @@ pub async fn mcp_clients_update_custom(// pins the server to the pre-edit command indefinitely — it stays healthy, so// no later tick reconnects it. `update_env` persists first for the same// reason.- reg.connections().disconnect(&server_id).await;+ if let Ok(service) = host::for_config(config) {+ service.dynamic().connections().disconnect(&server_id).await;+ }tracing::debug!("[mcp-custom] update ok server_id={}", server_id);