Skip to content

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

test(mcp): cover argument normalization in tool call paths

Steven Enamakel7c707fe88260
diff --git a/crates/openhuman-core/src/mcp/registry/tools_tests.rs b/crates/openhuman-core/src/mcp/registry/tools_tests.rs
index 49f1ef9d39..ca20f96a3e 100644
--- a/crates/openhuman-core/src/mcp/registry/tools_tests.rs
+++ b/crates/openhuman-core/src/mcp/registry/tools_tests.rs
@@ -215,13 +215,21 @@ fn registry_tools_present_the_exact_identity_they_always_had() {
#[tokio::test]
async fn tool_call_refuses_arguments_that_are_not_an_object() {
- let err = McpRegistryToolCallTool::new(cfg())
+ let dir = tempfile::tempdir().expect("temp workspace");
+ let config = workspace_config(dir.path());
+ crate::mcp::module_client::McpConfiguredClient::install_test_port(
+ &config,
+ Box::new(ToolCallPort::default()),
+ )
+ .expect("test module port");
+ let err = McpRegistryToolCallTool::new(config)
.execute(json!({ "server_id": "srv", "tool_name": "t", "arguments": 5 }))
.await
.expect_err("a number is not arguments");
let message = err.to_string();
assert!(message.contains("mcp_registry_tool_call"), "{message}");
- assert!(message.contains("a number"), "{message}");
+ assert!(message.contains("invalid tool arguments"), "{message}");
+ assert!(!message.contains('5'), "module failure must not echo arguments: {message}");
}
/// A workspace of its own, so the host this opens is not shared.
@@ -310,6 +318,23 @@ impl crate::mcp::module_client::McpModulePort for ToolCallPort {
serde_json::to_value(overview.into_iter().collect::<Vec<_>>())
.map_err(|_| crate::modules::client::ModuleCallError::ModuleFault)
}
+ tinymcp_bus::names::methods::NORMALIZE_TOOL_ARGUMENTS => {
+ let value = args
+ .get(0)
+ .cloned()
+ .ok_or(crate::modules::client::ModuleCallError::ModuleFault)?;
+ let map = match value {
+ Value::Null => serde_json::Map::new(),
+ Value::Object(map) => map,
+ Value::String(text) => serde_json::from_str::<Value>(&text)
+ .ok()
+ .and_then(|value| value.as_object().cloned())
+ .ok_or(crate::modules::client::ModuleCallError::ModuleFault)?,
+ _ => return Err(crate::modules::client::ModuleCallError::ModuleFault),
+ };
+ serde_json::to_value(map)
+ .map_err(|_| crate::modules::client::ModuleCallError::ModuleFault)
+ }
tinymcp_bus::names::methods::TOOL_CALL => {
let arguments = args
.get(2)
diff --git a/crates/openhuman-core/src/tools/impl/network/mcp_target_tests.rs b/crates/openhuman-core/src/tools/impl/network/mcp_target_tests.rs
index c581140d26..2ee33fa1f3 100644
--- a/crates/openhuman-core/src/tools/impl/network/mcp_target_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/network/mcp_target_tests.rs
@@ -25,31 +25,41 @@ impl McpModulePort for PreparePort {
_: &str,
_: &tinymcp_bus::McpClientConfig,
) -> Result<OpenConfiguredResponse, crate::modules::client::ModuleCallError> {
- unreachable!("target preparation is a root operation")
+ Ok(OpenConfiguredResponse {
+ object_path: "/test/mcp".to_owned(),
+ transition_id: "open-test".to_owned(),
+ })
}
async fn close(
&self,
_: &str,
) -> Result<Option<String>, crate::modules::client::ModuleCallError> {
- unreachable!("target preparation does not open a workspace")
+ Ok(None)
}
async fn transition_status(
&self,
_: &str,
) -> Result<TransitionStatus, crate::modules::client::ModuleCallError> {
- unreachable!("target preparation does not open a workspace")
+ Ok(TransitionStatus::Complete)
}
async fn call_object(
&self,
_: &str,
- _: &str,
- _: Value,
+ member: &str,
+ args: Value,
_: bool,
) -> Result<Value, crate::modules::client::ModuleCallError> {
- unreachable!("target preparation is a root operation")
+ if member != tinymcp_bus::names::methods::NORMALIZE_TOOL_ARGUMENTS {
+ return Err(crate::modules::client::ModuleCallError::IncompatibleContract);
+ }
+ let Some(Value::Object(arguments)) = args.get(0).cloned() else {
+ return Err(crate::modules::client::ModuleCallError::ModuleFault);
+ };
+ serde_json::to_value(arguments)
+ .map_err(|_| crate::modules::client::ModuleCallError::ModuleFault)
}
async fn prepare_agent_tools(