Skip to content

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

refactor(mcp): move argument validation into the module client

Steven Enamakel9247f951b96d
diff --git a/crates/openhuman-core/src/mcp/module_client.rs b/crates/openhuman-core/src/mcp/module_client.rs
index cb6d4e3775..90eeb87495 100644
--- a/crates/openhuman-core/src/mcp/module_client.rs
+++ b/crates/openhuman-core/src/mcp/module_client.rs
@@ -172,7 +172,7 @@ impl McpModulePort for TinyMcpPort {
.await
}
- pub(crate) async fn validate_server_arguments(
+ async fn validate_server_arguments(
&self,
request: ValidateServerArgumentsRequest,
) -> Result<ServerArgumentsValidation, ModuleCallError> {
@@ -391,7 +391,7 @@ impl McpConfiguredClient {
.await
}
- async fn validate_server_arguments(
+ pub(crate) async fn validate_server_arguments(
&self,
request: ValidateServerArgumentsRequest,
) -> Result<ServerArgumentsValidation, ModuleCallError> {
diff --git a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs
index c2205f5175..3a4421835c 100644
--- a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs
+++ b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs
@@ -44,7 +44,7 @@ pub async fn call_tool(
.ok_or_else(|| ToolCallError::InvalidParams(format!("unknown MCP tool `{name}`")))?;
let audit_arguments = arguments.clone();
- let params = match build_rpc_params(spec.name, arguments) {
+ let params = match build_rpc_params(spec.name, arguments).await {
Ok(params) => params,
Err(err) => {
if write_dispatch::is_write_tool(spec.name) {
@@ -317,10 +317,9 @@ async fn list_subagents() -> Result<Value, ToolCallError> {
async fn run_subagent_tool(params: &Map<String, Value>) -> Result<Value, ToolCallError> {
use super::super::subagent_depth;
- use tinymcp::server::args::required_non_empty_string;
- let agent_id = required_non_empty_string(params, "agent_id")?;
- let prompt = required_non_empty_string(params, "prompt")?;
+ let agent_id = validated_param(params, "agent_id")?;
+ let prompt = validated_param(params, "prompt")?;
// Bound nested recursion per delegation chain (CC → run_subagent → CC → …).
// `current_depth()` is the depth of THIS chain (carried across the loopback
// MCP hop via the depth header); the subagent we're about to spawn sits one
@@ -389,6 +388,13 @@ async fn run_subagent_tool(params: &Map<String, Value>) -> Result<Value, ToolCal
}))
}
+fn validated_param<'a>(params: &'a Map<String, Value>, key: &str) -> Result<&'a str, ToolCallError> {
+ params
+ .get(key)
+ .and_then(Value::as_str)
+ .ok_or_else(|| ToolCallError::Internal("MCP module returned invalid arguments".into()))
+}
+
pub fn tool_success(value: Value) -> Value {
json!({
"content": [{
diff --git a/crates/openhuman-core/src/mcp/server/tools/params.rs b/crates/openhuman-core/src/mcp/server/tools/params.rs
index cc817b2085..ec47d52580 100644
--- a/crates/openhuman-core/src/mcp/server/tools/params.rs
+++ b/crates/openhuman-core/src/mcp/server/tools/params.rs
@@ -20,11 +20,9 @@ pub async fn build_rpc_params(
let name = tool_name;
match tool_name {
"core.list_tools" | "core.tool_instructions" | "agent.list_subagents" => {
- reject_unexpected_arguments(&args, &[])?;
Ok(Map::new())
}
"agent.run_subagent" => {
- reject_unexpected_arguments(&args, SUBAGENT_RUN_ARGUMENTS)?;
let agent_id = validated_string(&args, "agent_id")?;
let prompt = validated_string(&args, "prompt")?;
Ok(Map::from_iter([
@@ -33,7 +31,6 @@ pub async fn build_rpc_params(
]))
}
"memory.recall" => {
- reject_unexpected_arguments(&args, MEMORY_RECALL_ARGUMENTS)?;
let mut params = Map::new();
params.insert(
"question".to_string(),
@@ -43,7 +40,6 @@ pub async fn build_rpc_params(
Ok(params)
}
"memory.fetch" => {
- reject_unexpected_arguments(&args, MEMORY_FETCH_ARGUMENTS)?;
let mut params = Map::new();
params.insert(
"query".to_string(),
@@ -58,14 +54,12 @@ pub async fn build_rpc_params(
Ok(params)
}
"memory.list" => {
- reject_unexpected_arguments(&args, MEMORY_LIST_ARGUMENTS)?;
let mut params = Map::new();
insert_filter_and_limit(&args, &mut params)?;
insert_cursor(&args, &mut params)?;
Ok(params)
}
"memory.learn" => {
- reject_unexpected_arguments(&args, MEMORY_LEARN_ARGUMENTS)?;
let mut params = Map::new();
params.insert(
"text".to_string(),
@@ -91,7 +85,6 @@ pub async fn build_rpc_params(
Ok(params)
}
"memory.forget" => {
- reject_unexpected_arguments(&args, MEMORY_FORGET_ARGUMENTS)?;
let ids = validated_string_array(&args, "ids")?;
if ids.len() > MEMORY_FORGET_MAX_IDS {
return Err(ToolCallError::InvalidParams(format!(
@@ -107,7 +100,6 @@ pub async fn build_rpc_params(
} else {
SEARXNG_SEARCH_ARGUMENTS
};
- reject_unexpected_arguments(&args, allowed)?;
let query = validated_string(&args, "query")?;
let mut params = Map::new();
params.insert("query".to_string(), Value::String(query));
@@ -122,7 +114,6 @@ pub async fn build_rpc_params(
Ok(params)
}
"web_answer" => {
- reject_unexpected_arguments(&args, WEB_ANSWER_ARGUMENTS)?;
let query = validated_string(&args, "query")?;
let mut params = Map::new();
params.insert("query".to_string(), Value::String(query));
diff --git a/vendor/tinymcp b/vendor/tinymcp
index 8869ca4901..11ef3c8403 160000
--- a/vendor/tinymcp
+++ b/vendor/tinymcp
@@ -1 +1 @@
-Subproject commit 8869ca4901c62c15c97c38e3c6ac24e5a359e59e
+Subproject commit 11ef3c840309e18274fce6a6ded26490ca7a9138