Skip to main content

agentmux_mcp/tools/
message_tool.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Message: one tool for messages to one agent or many and for each
5//! repository's coordination channel, with an `action`
6//! (docs/specs/SPEC_MUXAPI_TOOL_CONSOLIDATION_2026_10_15.md ยง4.2, slice S4). It
7//! replaces SendMessage, FleetBroadcast, PostToChannel and ReadChannel; their
8//! handlers (fleet.rs, overlap.rs) run each action unchanged, so a message is
9//! signed and delivered exactly as before.
10
11use super::family::{pick, relabeled, Act};
12use super::*;
13
14pub(super) const ACTS: &[Act] = &[
15    Act { action: "send", tool: "SendMessage", rename: &[] },
16    Act { action: "broadcast", tool: "FleetBroadcast", rename: &[] },
17    Act { action: "post", tool: "PostToChannel", rename: &[] },
18    Act { action: "read", tool: "ReadChannel", rename: &[] },
19    Act { action: "bulletin", tool: "PostBulletin", rename: &[] },
20    Act { action: "read_bulletin", tool: "ReadBulletin", rename: &[] },
21    Act { action: "quota_mode", tool: "QuotaMode", rename: &[] },
22];
23
24pub(super) async fn call(name: &str, arguments: &Value, cx: &ToolCtx<'_>) -> Result<String> {
25    match name {
26        "Message" => {
27            let (act, args) = pick("Message", ACTS, arguments)?;
28            let result = match act.tool {
29                "SendMessage" | "FleetBroadcast" => fleet::call(act.tool, &args, cx).await,
30                _ => overlap::call(act.tool, &args, cx).await,
31            };
32            relabeled("Message", ACTS, result)
33        }
34        _ => Err(not_in_family()),
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn every_action_is_in_the_schema() {
44        let schema: Value = serde_json::from_str(crate::tool_schemas::MESSAGE_TOOL).unwrap();
45        let mut listed: Vec<&str> = schema["inputSchema"]["properties"]["action"]["enum"]
46            .as_array()
47            .unwrap()
48            .iter()
49            .filter_map(|v| v.as_str())
50            .collect();
51        let mut want = super::super::family::action_names(ACTS);
52        listed.sort();
53        want.sort();
54        assert_eq!(listed, want);
55    }
56}