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(mcp): move TinyMcpPort into its own module
Steven Enamakel824e35466a6d
diff --git a/crates/openhuman-core/src/mcp/module_client.rs b/crates/openhuman-core/src/mcp/module_client.rsindex 45164fbb6f..1c0205ad0d 100644--- a/crates/openhuman-core/src/mcp/module_client.rs+++ b/crates/openhuman-core/src/mcp/module_client.rs@@ -114,115 +114,9 @@ pub(crate) trait McpModulePort: Send + Sync {}}-struct TinyMcpPort {- root: ModuleClient,-}--#[async_trait]-impl McpModulePort for TinyMcpPort {- async fn open_configured(- &self,- data_dir: &str,- config: &McpClientConfig,- ) -> Result<OpenConfiguredResponse, ModuleCallError> {- self.root- .call_confidential(- MODULE,- names::methods::OPEN_CONFIGURED,- (OpenConfiguredRequest {- data_dir: data_dir.to_owned(),- client: config.clone(),- },),- )- .await- }-- async fn close(&self, data_dir: &str) -> Result<Option<String>, ModuleCallError> {- self.root- .call(MODULE, names::methods::CLOSE, (data_dir.to_owned(),))- .await- }-- async fn transition_status(- &self,- transition_id: &str,- ) -> Result<TransitionStatus, ModuleCallError> {- self.root- .call(- MODULE,- names::methods::TRANSITION_STATUS,- (transition_id.to_owned(),),- )- .await- }-- async fn call_object(- &self,- object_path: &str,- member: &str,- args: Value,- confidential: bool,- ) -> Result<Value, ModuleCallError> {- #[cfg(feature = "modules")]- {- let object = self.root.object_client(MODULE, object_path).await?;- if confidential {- object.call_confidential(member, args).await- } else {- object.call(member, args).await- }- }- #[cfg(not(feature = "modules"))]- {- let _ = (object_path, member, args, confidential);- Err(ModuleCallError::Unavailable)- }- }-- async fn prepare_agent_tools(- &self,- request: PrepareAgentToolsRequest,- ) -> Result<Vec<McpToolPresentation>, ModuleCallError> {- self.root- .call(MODULE, names::methods::PREPARE_AGENT_TOOLS, (request,))- .await- }-- async fn validate_server_arguments(- &self,- request: ValidateServerArgumentsRequest,- ) -> Result<ServerArgumentsValidation, ModuleCallError> {- self.root- .call_confidential(- MODULE,- names::methods::VALIDATE_SERVER_ARGUMENTS,- (request,),- )- .await- }-- async fn normalize_tool_arguments(- &self,- arguments: Option<Value>,- ) -> Result<Map<String, Value>, ModuleCallError> {- self.root- .call_confidential(- MODULE,- names::methods::NORMALIZE_TOOL_ARGUMENTS,- (arguments,),- )- .await- }-- async fn transform_text(- &self,- request: tinymcp_bus::TransformTextRequest,- ) -> Result<String, ModuleCallError> {- self.root- .call_confidential(MODULE, names::methods::TRANSFORM_TEXT, (request,))- .await- }-}+#[path = "module_port.rs"]+mod module_port;+use module_port::TinyMcpPort;/// One workspace's serialized TinyMCP lifecycle and private object proxy.pub(crate) struct McpConfiguredClient {@@ -342,9 +236,7 @@ impl McpConfiguredClient {.to_owned();Ok(Self::with_port(data_dir,- Box::new(TinyMcpPort {- root: ModuleClient::new(config.clone()),- }),+ Box::new(TinyMcpPort::new(ModuleClient::new(config.clone()))),))}diff --git a/crates/openhuman-core/src/mcp/module_client_owner_tests.rs b/crates/openhuman-core/src/mcp/module_client_owner_tests.rsindex 7fa0aa26b6..4af9880fe6 100644--- a/crates/openhuman-core/src/mcp/module_client_owner_tests.rs+++ b/crates/openhuman-core/src/mcp/module_client_owner_tests.rs@@ -53,13 +53,11 @@ async fn cancelled_close_retries_its_receipt_on_the_original_owner() {.unwrap();}original.request_name(names::INTERFACE).await.unwrap();- let port = TinyMcpPort {- root: ModuleClient::fixture(+ let port = TinyMcpPort::new(ModuleClient::fixture(caller.proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE).unwrap(),- ),- };+ ));assert_eq!(port.transition_status("original-open").await,Ok(TransitionStatus::Complete)@@ -134,7 +132,7 @@ async fn cleanup_receipts_stay_with_the_original_module_after_alias_replacement(.proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE).unwrap(),);- let port = TinyMcpPort { root };+ let port = TinyMcpPort::new(root);// Resolve the original owner through a real bus call. No secret is sent// to these deliberately unattested lifecycle fixtures.assert_eq!(diff --git a/crates/openhuman-core/src/mcp/module_port.rs b/crates/openhuman-core/src/mcp/module_port.rsnew file mode 100644index 0000000000..c48fcd0ecf--- /dev/null+++ b/crates/openhuman-core/src/mcp/module_port.rs@@ -0,0 +1,137 @@+//! Bus adapter pinned to the module instance that starts its lifecycle.+use super::*;+#[cfg(feature = "modules")]+use crate::modules::client::ModuleObjectClient;++pub(super) struct TinyMcpPort {+ root: ModuleClient,+ #[cfg(feature = "modules")]+ pinned: tokio::sync::OnceCell<ModuleObjectClient>,+}++impl TinyMcpPort {+ pub(super) fn new(root: ModuleClient) -> Self {+ Self { root, #[cfg(feature = "modules")] pinned: tokio::sync::OnceCell::new() }+ }++ #[cfg(feature = "modules")]+ async fn pinned(&self) -> Result<&ModuleObjectClient, ModuleCallError> {+ self.pinned.get_or_try_init(|| async {+ self.root.object_client(MODULE, names::OBJECT_PATH).await?.pin_owner().await+ }).await+ }++ async fn root_call<R: DeserializeOwned>(&self, member: &str, args: impl Serialize, confidential: bool) -> Result<R, ModuleCallError> {+ #[cfg(feature = "modules")]+ {+ let root = self.pinned().await?;+ if confidential { root.call_confidential(member, args).await }+ else { root.call(member, args).await }+ }+ #[cfg(not(feature = "modules"))]+ {+ if confidential { self.root.call_confidential(MODULE, member, args).await }+ else { self.root.call(MODULE, member, args).await }+ }+ }+}++#[async_trait]+impl McpModulePort for TinyMcpPort {+ async fn open_configured(+ &self,+ data_dir: &str,+ config: &McpClientConfig,+ ) -> Result<OpenConfiguredResponse, ModuleCallError> {+ self.root_call(+ names::methods::OPEN_CONFIGURED,+ (OpenConfiguredRequest {+ data_dir: data_dir.to_owned(),+ client: config.clone(),+ },),+ true,+ )+ .await+ }++ async fn close(&self, data_dir: &str) -> Result<Option<String>, ModuleCallError> {+ self.root_call(names::methods::CLOSE, (data_dir.to_owned(),), false)+ .await+ }++ async fn transition_status(+ &self,+ transition_id: &str,+ ) -> Result<TransitionStatus, ModuleCallError> {+ self.root_call(+ names::methods::TRANSITION_STATUS,+ (transition_id.to_owned(),),+ false,+ )+ .await+ }++ async fn call_object(+ &self,+ object_path: &str,+ member: &str,+ args: Value,+ confidential: bool,+ ) -> Result<Value, ModuleCallError> {+ #[cfg(feature = "modules")]+ {+ let object = self.pinned().await?.object_at(object_path)?;+ if confidential {+ object.call_confidential(member, args).await+ } else {+ object.call(member, args).await+ }+ }+ #[cfg(not(feature = "modules"))]+ {+ let _ = (object_path, member, args, confidential);+ Err(ModuleCallError::Unavailable)+ }+ }++ async fn prepare_agent_tools(+ &self,+ request: PrepareAgentToolsRequest,+ ) -> Result<Vec<McpToolPresentation>, ModuleCallError> {+ self.root_call(names::methods::PREPARE_AGENT_TOOLS, (request,), false)+ .await+ }++ async fn validate_server_arguments(+ &self,+ request: ValidateServerArgumentsRequest,+ ) -> Result<ServerArgumentsValidation, ModuleCallError> {+ self.root_call(+ names::methods::VALIDATE_SERVER_ARGUMENTS,+ (request,),+ true,+ )+ .await+ }++ async fn normalize_tool_arguments(+ &self,+ arguments: Option<Value>,+ ) -> Result<Map<String, Value>, ModuleCallError> {+ self.root_call(+ names::methods::NORMALIZE_TOOL_ARGUMENTS,+ (arguments,),+ true,+ )+ .await+ }++ async fn transform_text(+ &self,+ request: tinymcp_bus::TransformTextRequest,+ ) -> Result<String, ModuleCallError> {+ self.root_call(names::methods::TRANSFORM_TEXT, (request,), true)+ .await+ }+}+