Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Enabling a toolset in Clean room counts only the tools it lists (#324)

BFlat4ab820fe7ff0
diff --git a/crates/mcp/src/lib.rs b/crates/mcp/src/lib.rs
index c0f7ca01..6d935009 100644
--- a/crates/mcp/src/lib.rs
+++ b/crates/mcp/src/lib.rs
@@ -315,12 +315,17 @@ impl Server {
self.opts.all_tools || self.enabled.lock().unwrap_or_else(PoisonError::into_inner).contains(&set)
}
+ /// Whether a tool is on this connection's list: its toolset is shown and, in Clean room, it's
+ /// one Clean room runs (the rest would only be refused).
+ fn listed(&self, s: &craft_anything_engine::ToolSpec, clean: bool) -> bool {
+ self.visible(s.toolset) && (!clean || craft_anything_engine::clean_room::allows(s.id))
+ }
+
fn tools_list(&self) -> Value {
let registry = self.engine.registry();
- // Clean room lists only the tools it runs; the rest would only be refused.
let clean = self.engine.session().clean_room();
let mut tools: Vec<Value> = Vec::new();
- for s in registry.all().iter().filter(|s| self.visible(s.toolset) && (!clean || craft_anything_engine::clean_room::allows(s.id))) {
+ for s in registry.all().iter().filter(|s| self.listed(s, clean)) {
tools.push(registry.mcp_descriptor(s));
}
if !self.opts.all_tools {
@@ -432,9 +437,11 @@ impl Server {
if !added.is_empty() {
self.notify("notifications/tools/list_changed", json!({}));
}
- let tools: Vec<&str> = self.engine.registry().all().iter().filter(|s| self.visible(s.toolset)).map(|s| s.id).collect();
+ // Counted as tools/list shows them, so Clean room's refused tools aren't counted (#263).
+ let clean = self.engine.session().clean_room();
+ let visible = self.engine.registry().all().iter().filter(|s| self.listed(s, clean)).count();
Ok(ToolOutput::Value(
- json!({"enabled": added, "visible_tools": tools.len(), "note": "The tool list changed; refresh it if your client does not do so automatically."}),
+ json!({"enabled": added, "visible_tools": visible, "note": "The tool list changed; refresh it if your client does not do so automatically."}),
))
}
diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rs
index ecfeb7e4..118e70ce 100644
--- a/crates/mcp/src/tests.rs
+++ b/crates/mcp/src/tests.rs
@@ -77,6 +77,25 @@ fn a_large_approval_keeps_its_decision() {
assert_eq!(decision, json!({"behavior": "allow", "updatedInput": input}));
}
+/// #263: in Clean room, enabling a toolset counted the tools Clean room hides from the list.
+#[test]
+fn enabling_a_toolset_counts_the_tools_listed() {
+ let input = format!(
+ "{}
+",
+ req(1, "tools/call", json!({"name": "enable_toolset", "arguments": {"toolset": "all"}}))
+ );
+ let mut session = craft_anything_engine::testing::session();
+ session.settings.deep_mode = false;
+ let engine = Arc::new(Engine::new(session));
+ let runs = engine.registry().all().iter().filter(|s| craft_anything_engine::clean_room::allows(s.id)).count();
+ let buf = Buf::default();
+ serve(engine, ServerOptions::default(), std::io::Cursor::new(input.into_bytes()), Box::new(buf.clone())).unwrap();
+ let out: Vec<Value> = String::from_utf8(buf.0.lock().unwrap().clone()).unwrap().lines().map(|l| serde_json::from_str(l).unwrap()).collect();
+ let enabled: Value = serde_json::from_str(response(&out, 1)["result"]["content"][0]["text"].as_str().unwrap()).unwrap();
+ assert_eq!(enabled["result"]["visible_tools"], json!(runs), "{enabled}");
+}
+
fn tool_names(v: &Value) -> Vec<String> {
v["result"]["tools"].as_array().unwrap().iter().map(|t| t["name"].as_str().unwrap().to_string()).collect()
}