Skip to main content

agentmux_mcp/tools/
widget_tool.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Widget: one tool for the custom panes an agent builds for the user, with an
5//! `action` (docs/specs/SPEC_MUXAPI_TOOL_CONSOLIDATION_2026_10_15.md ยง4.2, slice
6//! S4). It replaces WidgetList, WidgetInstall and OpenWidget; their handlers
7//! (widgets.rs) run each action unchanged.
8
9use 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}