Skip to content

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

feat(tools): add registry ops for tool schema management

Steven Enamakel780bb67cdca2
diff --git a/crates/openhuman-core/src/tools/registry/ops.rs b/crates/openhuman-core/src/tools/registry/ops.rs
index bf2ddc016b..ee5a5f83fe 100644
--- a/crates/openhuman-core/src/tools/registry/ops.rs
+++ b/crates/openhuman-core/src/tools/registry/ops.rs
@@ -4,6 +4,7 @@ use serde_json::{json, Map, Value};
use crate::config::Config;
use crate::core::all;
+use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
use crate::mcp::audit::McpWriteListQuery;
@@ -28,8 +29,8 @@ const POLICY_SURFACES: &[&str] = &[
];
/// Return the current read-only tool registry snapshot.
-pub fn list_tools() -> Outcome<ToolRegistryList> {
- let tools = registry_entries();
+pub fn list_tools(ctx: &DispatchCtx) -> Outcome<ToolRegistryList> {
+ let tools = registry_entries(ctx);
log::debug!(
"[tool_registry] list_tools completed entries={}",
tools.len()
@@ -196,13 +197,13 @@ async fn mcp_write_audit_health(config: &Config) -> McpWriteAuditHealth {
}
/// Look up one registry entry by stable `tool_id`.
-pub fn get_tool(tool_id: &str) -> Result<Outcome<ToolRegistryEntry>, String> {
+pub fn get_tool(ctx: &DispatchCtx, tool_id: &str) -> Result<Outcome<ToolRegistryEntry>, String> {
let normalized = tool_id.trim();
if normalized.is_empty() {
return Err("tool_id must be a non-empty string".to_string());
}
- let tool = registry_entries()
+ let tool = registry_entries(ctx)
.into_iter()
.find(|entry| entry.tool_id == normalized)
.ok_or_else(|| format!("tool not found in registry: {normalized}"))?;
@@ -225,9 +226,10 @@ pub fn get_tool(tool_id: &str) -> Result<Outcome<ToolRegistryEntry>, String> {
/// The connected-client tools come from whichever workspace `mcp::init` claimed
/// as the process default. That is right for the shipped app, which opens one;
/// a caller that holds a `Config` should prefer
-/// [`registry_entries_for_config`], which names the workspace it means.
-pub fn registry_entries() -> Vec<ToolRegistryEntry> {
- build_registry_entries(None)
+/// [`registry_entries_for_config`], which names the workspace it means. The
+/// connections are read for the context `ctx` the caller was handed.
+pub fn registry_entries(ctx: &DispatchCtx) -> Vec<ToolRegistryEntry> {
+ build_registry_entries(McpSource::Ctx(ctx))
}
/// The same snapshot, with connected-client tools read from `config`'s
@@ -240,11 +242,20 @@ pub fn registry_entries() -> Vec<ToolRegistryEntry> {
/// `tool_registry_entries_include_connected_mcp_client_tools` came to pass
/// alone and fail beside its neighbours.
pub fn registry_entries_for_config(config: &Config) -> Vec<ToolRegistryEntry> {
- build_registry_entries(Some(config))
+ build_registry_entries(McpSource::Config(config))
}
-/// The shared body. `config` selects the MCP host; everything else is identical.
-fn build_registry_entries(config: Option<&Config>) -> Vec<ToolRegistryEntry> {
+/// Where the connected MCP client servers are read from.
+#[derive(Clone, Copy)]
+enum McpSource<'a> {
+ /// The workspace `config` names.
+ Config(&'a Config),
+ /// The process default host, as seen by the context handed in.
+ Ctx(&'a DispatchCtx),
+}
+
+/// The shared body. `source` selects the MCP host; everything else is identical.
+fn build_registry_entries(source: McpSource<'_>) -> Vec<ToolRegistryEntry> {
let mut entries = BTreeMap::new();
for spec in crate::mcp::server::tool_specs() {
@@ -270,15 +281,12 @@ fn build_registry_entries(config: Option<&Config>) -> Vec<ToolRegistryEntry> {
if handle.runtime_flavor() == tokio::runtime::RuntimeFlavor::MultiThread {
tokio::task::block_in_place(|| {
handle.block_on(async {
- match config {
- Some(config) => {
+ match source {
+ McpSource::Config(config) => {
connections::all_connected_tools_for_config(config).await
}
- None => {
- connections::all_connected_tools(
- &crate::core::runtime::DispatchCtx::ambient(),
- )
- .await
+ McpSource::Ctx(ctx) => {
+ connections::all_connected_tools(ctx).await
}
}
})
diff --git a/crates/openhuman-core/src/tools/registry/ops_tests.rs b/crates/openhuman-core/src/tools/registry/ops_tests.rs
index bc7eb0e7ad..87fcf56837 100644
--- a/crates/openhuman-core/src/tools/registry/ops_tests.rs
+++ b/crates/openhuman-core/src/tools/registry/ops_tests.rs
@@ -5,7 +5,7 @@ use crate::core::{FieldSchema, TypeSchema};
#[test]
fn registry_entries_include_mcp_and_controller_tools() {
- let entries = registry_entries();
+ let entries = registry_entries(&DispatchCtx::host_default());
// The MCP-transport half of the inventory is sourced from
// `mcp::server::tool_specs()`, which the `mcp` feature compiles out (the
@@ -46,7 +46,7 @@ fn registry_entries_include_mcp_and_controller_tools() {
#[test]
fn registry_entries_are_unique_and_sorted_by_tool_id() {
- let entries = registry_entries();
+ let entries = registry_entries(&DispatchCtx::host_default());
let ids = entries
.iter()
.map(|entry| entry.tool_id.as_str())
@@ -235,25 +235,25 @@ fn get_tool_trims_and_returns_exact_entry() {
#[cfg(not(feature = "mcp"))]
let tool_id = "tools.web_search";
- let outcome = get_tool(&format!(" {tool_id} ")).expect("registry lookup");
+ let outcome = get_tool(&DispatchCtx::host_default(), &format!(" {tool_id} ")).expect("registry lookup");
assert_eq!(outcome.value.tool_id, tool_id);
}
#[test]
fn get_tool_rejects_blank_id() {
- let err = get_tool(" ").expect_err("blank id should fail");
+ let err = get_tool(&DispatchCtx::host_default(), " ").expect_err("blank id should fail");
assert!(err.contains("non-empty"));
}
#[test]
fn get_tool_reports_unknown_id() {
- let err = get_tool("missing.tool").expect_err("unknown id should fail");
+ let err = get_tool(&DispatchCtx::host_default(), "missing.tool").expect_err("unknown id should fail");
assert!(err.contains("missing.tool"));
}
#[test]
fn all_registry_entries_have_non_empty_name_and_description() {
- let entries = registry_entries();
+ let entries = registry_entries(&DispatchCtx::host_default());
assert!(
!entries.is_empty(),
"registry must contain at least one tool"
diff --git a/crates/openhuman-core/src/tools/registry/schemas.rs b/crates/openhuman-core/src/tools/registry/schemas.rs
index 44dff7a54a..c5ac81fd45 100644
--- a/crates/openhuman-core/src/tools/registry/schemas.rs
+++ b/crates/openhuman-core/src/tools/registry/schemas.rs
@@ -87,21 +87,21 @@ pub fn schemas(function: &str) -> ControllerSchema {
}
}
-fn handle_list(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_list(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
log::debug!(
"[tool_registry] rpc list requested param_count={}",
params.len()
);
- to_json(crate::tools::registry::ops::list_tools())
+ to_json(crate::tools::registry::ops::list_tools(&ctx))
})
}
-fn handle_get(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_get(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let tool_id = required_tool_id(&params)?;
log::debug!("[tool_registry] rpc get requested tool_id={tool_id}");
- to_json(crate::tools::registry::ops::get_tool(tool_id)?)
+ to_json(crate::tools::registry::ops::get_tool(&ctx, tool_id)?)
})
}