Skip to content

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

feat(mcp): add ui tool definitions

Steven Enamakeld5481499c621
diff --git a/crates/openhuman-core/src/mcp/ui/tools.rs b/crates/openhuman-core/src/mcp/ui/tools.rs
index c11c9b2bb0..aedbd85a37 100644
--- a/crates/openhuman-core/src/mcp/ui/tools.rs
+++ b/crates/openhuman-core/src/mcp/ui/tools.rs
@@ -10,7 +10,9 @@ use std::path::{Component, Path, PathBuf};
use async_trait::async_trait;
use serde_json::{json, Value};
-use tinytools::{PermissionLevel, Tool, ToolExposure, ToolResult};
+use tinytools::{
+ PermissionLevel, Tool, ToolCallOptions, ToolExposure, ToolResult, ToolRunContext,
+};
use super::cache::{self, InlineEntry};
use super::resolve::{MAX_RESOURCE_BYTES, MAX_STRUCTURED_BYTES};
@@ -109,8 +111,12 @@ pub fn confine_path_in(roots: &[PathBuf], path: &str) -> Result<(PathBuf, PathBu
/// # Errors
///
/// When the open is refused, the file is not regular, or it is too large.
-pub async fn read_confined(root: PathBuf, resolved: PathBuf) -> Result<String, String> {
- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || {
+pub async fn read_confined(
+ ctx: &crate::core::runtime::DispatchCtx,
+ root: PathBuf,
+ resolved: PathBuf,
+) -> Result<String, String> {
+ ctx.spawn_blocking(move || {
use std::io::Read;
let file = crate::agent::attachments::provider::open::secure_open(&resolved, &root)
.map_err(|error| {
@@ -180,6 +186,17 @@ impl Tool for ShowUiTool {
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.execute_with_context(args, ToolCallOptions::default(), None)
+ .await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: Value,
+ _options: ToolCallOptions,
+ tool_context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
let html_arg = args.get("html").and_then(Value::as_str);
let path_arg = args.get("path").and_then(Value::as_str);
let html = match (html_arg, path_arg) {
@@ -189,7 +206,7 @@ impl Tool for ShowUiTool {
Ok(found) => found,
Err(error) => return Ok(ToolResult::error(format!("show_ui: {error}"))),
};
- match read_confined(root, resolved).await {
+ match read_confined(&ctx, root, resolved).await {
Ok(html) => html,
Err(error) => return Ok(ToolResult::error(format!("show_ui: {error}"))),
}
diff --git a/crates/openhuman-core/src/mcp/ui/tools_tests.rs b/crates/openhuman-core/src/mcp/ui/tools_tests.rs
index 90acd0b15e..078f16132e 100644
--- a/crates/openhuman-core/src/mcp/ui/tools_tests.rs
+++ b/crates/openhuman-core/src/mcp/ui/tools_tests.rs
@@ -46,7 +46,7 @@ async fn read_confined_refuses_a_file_swapped_for_an_outside_symlink() {
let roots = vec![root.path().to_path_buf()];
let (canonical_root, resolved) = confine_path_in(&roots, "view.html").unwrap();
assert_eq!(
- read_confined(canonical_root.clone(), resolved.clone())
+ read_confined(&DispatchCtx::ambient(), canonical_root.clone(), resolved.clone())
.await
.unwrap(),
"<p>inside</p>"
@@ -54,7 +54,7 @@ async fn read_confined_refuses_a_file_swapped_for_an_outside_symlink() {
std::fs::remove_file(&target).unwrap();
std::os::unix::fs::symlink(outside.path().join("secret.html"), &target).unwrap();
- assert!(read_confined(canonical_root, resolved).await.is_err());
+ assert!(read_confined(&DispatchCtx::ambient(), canonical_root, resolved).await.is_err());
}
#[cfg(unix)]
@@ -70,7 +70,7 @@ async fn read_confined_refuses_a_directory_swapped_for_an_outside_symlink() {
std::fs::remove_dir_all(root.path().join("pages")).unwrap();
std::os::unix::fs::symlink(outside.path(), root.path().join("pages")).unwrap();
- assert!(read_confined(canonical_root, resolved).await.is_err());
+ assert!(read_confined(&DispatchCtx::ambient(), canonical_root, resolved).await.is_err());
}
#[tokio::test]