agentmux_mcp/tools/
widget_tool.rs1use super::family::{pick, relabeled, Act};
10use super::*;
11
12pub(super) const ACTS: &[Act] = &[
13 Act { action: "list", tool: "WidgetList", rename: &[] },
14 Act { action: "install", tool: "WidgetInstall", rename: &[] },
15 Act { action: "open", tool: "OpenWidget", rename: &[] },
16];
17
18pub(super) async fn call(name: &str, arguments: &Value, cx: &ToolCtx<'_>) -> Result<String> {
19 match name {
20 "Widget" => {
21 let (act, args) = pick("Widget", ACTS, arguments)?;
22 relabeled("Widget", ACTS, widgets::call(act.tool, &args, cx).await)
23 }
24 _ => Err(not_in_family()),
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn every_action_is_in_the_schema() {
34 let schema: Value = serde_json::from_str(crate::tool_schemas::WIDGET_TOOL).unwrap();
35 let mut listed: Vec<&str> = schema["inputSchema"]["properties"]["action"]["enum"]
36 .as_array()
37 .unwrap()
38 .iter()
39 .filter_map(|v| v.as_str())
40 .collect();
41 let mut want = super::super::family::action_names(ACTS);
42 listed.sort();
43 want.sort();
44 assert_eq!(listed, want);
45 }
46}