feat: matrix MCP invite_user tool
Adds an invite_user tool to the per-agent matrix MCP so an agent can invite
another user to a room it's already in (e.g. pull a peer into an existing
chat). Mirrors the existing join_room/send_dm wiring:
- protocol.rs: DaemonRequest::InviteUser { room, user_id }
- handlers.rs: invite_user — parse user_id, resolve room, room.invite_user_by_id
- socket.rs: dispatch arm
- bin/mcp.rs: invite_user tool + InviteUserArgs
room accepts an id or alias; the caller must hold a power level high enough
to invite (the homeserver error is surfaced verbatim otherwise). The invitee
then accepts via join_room. allowedTools is already '*' for the matrix server,
so the tool is exposed without a nix change.
This commit is contained in:
parent
df1ffdd504
commit
c85dcc0dec
4 changed files with 57 additions and 0 deletions
|
|
@ -350,6 +350,28 @@ pub async fn join_room(client: &Client, room_ref: &str) -> DaemonResponse {
|
|||
}
|
||||
}
|
||||
|
||||
/// Invite `user_id` to `room_ref`. The calling agent must be a member of
|
||||
/// the room with a power level high enough to invite; otherwise the
|
||||
/// homeserver rejects it and the error is surfaced verbatim.
|
||||
pub async fn invite_user(client: &Client, room_ref: &str, user_id: &str) -> DaemonResponse {
|
||||
let uid: OwnedUserId = match user_id.parse() {
|
||||
Ok(u) => u,
|
||||
Err(e) => return DaemonResponse::error(format!("invalid user_id {user_id}: {e}")),
|
||||
};
|
||||
let room = match resolve_room(client, room_ref).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => return e,
|
||||
};
|
||||
match room.invite_user_by_id(&uid).await {
|
||||
Ok(()) => DaemonResponse::ok(&serde_json::json!({
|
||||
"invited": true,
|
||||
"room_id": room.room_id().to_string(),
|
||||
"user_id": uid.to_string(),
|
||||
})),
|
||||
Err(e) => DaemonResponse::error(format!("invite {uid} to {room_ref}: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn read_room(client: &Client, room_ref: &str, limit: Option<usize>) -> DaemonResponse {
|
||||
use matrix_sdk::ruma::api::Direction;
|
||||
use matrix_sdk::ruma::api::client::message::get_message_events;
|
||||
|
|
|
|||
Loading…
Reference in a new issue