From 8b6b735a20a9c3d122167df9faf1c9f821a1ce43 Mon Sep 17 00:00:00 2001 From: damocles Date: Sun, 4 Oct 2026 20:11:24 +0200 Subject: [PATCH] hive-matrix-mcp: surface the inviter and topic in list_invites --- docs/tools/matrix.md | 4 +++- hive-matrix-mcp/src/handlers.rs | 33 ++++++++++++++++++++++++--------- hive-matrix-mcp/src/mcp.rs | 5 +++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/tools/matrix.md b/docs/tools/matrix.md index f140e857..21888b8c 100644 --- a/docs/tools/matrix.md +++ b/docs/tools/matrix.md @@ -66,7 +66,9 @@ room you haven't read yet. a pending invite if one exists, but prefer `resolve_invite` for invites (it can reject too). - `list_invites()` — rooms this agent has been invited to but not - yet joined (`{ id, canonical_alias, name }` per room). + yet joined (`{ id, canonical_alias, name, inviter, topic }` per room — + `inviter` and `topic` are there so an agent has enough to judge an + invite before `resolve_invite`ing it, not just a bare room id). ### Receipts diff --git a/hive-matrix-mcp/src/handlers.rs b/hive-matrix-mcp/src/handlers.rs index 6aa2ccf4..5c211028 100644 --- a/hive-matrix-mcp/src/handlers.rs +++ b/hive-matrix-mcp/src/handlers.rs @@ -32,6 +32,16 @@ pub struct InviteInfo { pub room_id: String, pub canonical_alias: Option, pub name: Option, + /// Who sent the invite — the `sender` of the `m.room.member` invite + /// event for this account. `None` only on an SDK-side lookup failure + /// (`invite_details` errors if the room isn't genuinely in the + /// `Invited` state, which shouldn't happen here since we got the room + /// from `invited_rooms()` itself). + pub inviter: Option, + /// The room's topic, where set. Most invites to a freshly created room + /// won't have one; `canonical_alias`/`name` are just as commonly unset, + /// so this is one more thing to judge the invite by, not a guarantee. + pub topic: Option, } /// JSON-shape for `list_rooms`: one row per joined room. @@ -654,18 +664,23 @@ pub async fn list_room_members(client: &Client, room_ref: &str) -> DaemonRespons DaemonResponse::ok(&list) } -#[must_use] -pub fn list_invites(client: &Client) -> DaemonResponse { - let invites: Vec = client - .invited_rooms() - .into_iter() - .map(|room| InviteInfo { +pub async fn list_invites(client: &Client) -> DaemonResponse { + let mut pending = Vec::new(); + for room in client.invited_rooms() { + let inviter = room + .invite_details() + .await + .map(|details| details.inviter_id.to_string()) + .ok(); + pending.push(InviteInfo { room_id: room.room_id().to_string(), canonical_alias: room.canonical_alias().map(|a| a.to_string()), name: room.name(), - }) - .collect(); - DaemonResponse::ok(&invites) + inviter, + topic: room.topic(), + }); + } + DaemonResponse::ok(&pending) } pub async fn join_room(client: &Client, room_ref: &str) -> DaemonResponse { diff --git a/hive-matrix-mcp/src/mcp.rs b/hive-matrix-mcp/src/mcp.rs index 3301e87e..b94ab745 100644 --- a/hive-matrix-mcp/src/mcp.rs +++ b/hive-matrix-mcp/src/mcp.rs @@ -384,7 +384,8 @@ impl MatrixMcp { #[tool( description = "List rooms this agent has been invited to but not yet joined. \ - Each row has the room id, canonical alias (when set), and display name. \ + Each row has the room id, canonical alias (when set), display name, inviting \ + user id, and topic (when set) — enough to judge an invite before accepting. \ Use `resolve_invite` to accept or reject an invite." )] async fn list_invites(&self, Parameters(args): Parameters) -> String { @@ -392,7 +393,7 @@ impl MatrixMcp { Ok(c) => c, Err(e) => return format!("matrix error: {e}"), }; - render(handlers::list_invites(client)) + render(handlers::list_invites(client).await) } #[tool(