Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(mcp): honor disabled module configuration

Steven Enamakel0f1e37b598dc
diff --git a/crates/openhuman-core/src/mcp/module_client.rs b/crates/openhuman-core/src/mcp/module_client.rs
index df7abba1c4..c502f22a01 100644
--- a/crates/openhuman-core/src/mcp/module_client.rs
+++ b/crates/openhuman-core/src/mcp/module_client.rs
@@ -163,6 +163,11 @@ impl McpConfiguredClient {
/// reachable until `close` confirms cleanup; workspace/config switching is
/// serialized by the client itself.
pub(crate) fn for_config(config: &Config) -> Result<Arc<Self>, ModuleCallError> {
+ if !config.modules.enabled {
+ ModuleClient::report_unavailable(MODULE);
+ return Err(ModuleCallError::Unavailable);
+ }
+
let data_dir = crate::core::runtime::agent_scope_dir(config);
let clients = CLIENTS.get_or_init(|| Mutex::new(HashMap::new()));
let mut clients = clients
diff --git a/crates/openhuman-core/src/mcp/module_client_tests.rs b/crates/openhuman-core/src/mcp/module_client_tests.rs
index 963227f742..4ab0e05b42 100644
--- a/crates/openhuman-core/src/mcp/module_client_tests.rs
+++ b/crates/openhuman-core/src/mcp/module_client_tests.rs
@@ -131,6 +131,38 @@ async fn opening_sends_configuration_confidentially_and_reuses_the_ready_object(
assert!(!calls[0].3);
}
+#[tokio::test]
+async fn disabling_modules_rejects_a_cached_client_but_keeps_shutdown_cleanup() {
+ let temporary = tempfile::tempdir().expect("temporary workspace");
+ let mut enabled = Config::default();
+ enabled.workspace_dir = temporary.path().to_path_buf();
+ enabled.modules.enabled = true;
+
+ let port = FakePort::default();
+ let opened = Arc::clone(&port.opened);
+ let closed = Arc::clone(&port.closed);
+ let client = McpConfiguredClient::install_test_port(&enabled, Box::new(port))
+ .expect("install test module port");
+ client
+ .call::<bool>(&configured("server"), "ConnectedOverview", ())
+ .await
+ .expect("open enabled module client");
+ assert_eq!(opened.lock().unwrap().len(), 1);
+
+ let mut disabled = enabled;
+ disabled.modules.enabled = false;
+ assert!(matches!(
+ McpConfiguredClient::for_config(&disabled),
+ Err(ModuleCallError::Unavailable)
+ ));
+ assert_eq!(opened.lock().unwrap().len(), 1);
+
+ // Disabling new calls must not drop the prior owner before shutdown can
+ // close the configured TinyMCP object.
+ client.close().await.expect("cleanup cached client");
+ assert_eq!(closed.lock().unwrap().len(), 1);
+}
+
#[tokio::test]
async fn configuration_switches_replace_the_object_before_dispatch() {
let port = FakePort::default();