Skip to main content
Glama

agent_broadcast

Send messages to all agents in a room using Cloudflare relay for cross-device communication between AI agents over the internet.

Instructions

Kirim pesan ke semua agent di room via Cloudflare relay.

Args: params: message, msg_type Returns: str: JSON status broadcast

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main MCP tool handler for 'agent_broadcast'. This async function accepts a BroadcastInput params, creates a broadcast payload, sends it via WebSocket to the Cloudflare relay, handles ACK responses, and manages retry queue for offline scenarios.
    @mcp.tool(name="agent_broadcast")
    async def agent_broadcast(params: BroadcastInput) -> str:
        """
        Kirim pesan ke semua agent di room via Cloudflare relay.
    
        Args:
            params: message, msg_type
        Returns:
            str: JSON status broadcast
        """
        payload = {"type": "broadcast",
            "content": params.message, "msg_type": params.msg_type}
        if current_room is None:
            return json.dumps({"success": False, "error": "Tidak terhubung ke room. Jalankan room_join dulu."})
        if ws_conn is None:
            queued = _enqueue_retry_action("broadcast", payload, reason="WebSocket tidak terhubung")
            return json.dumps({"success": False, "queued_for_retry": True,
                "retry_queue_id": queued["retry_id"],
                "retry_queue_count": len(_retry_queue()),
                "message": "Broadcast disimpan di retry queue lokal hingga koneksi pulih."})
        try:
            request_id, ack = await _await_ack(payload)
            if ack is None:
                queued = _enqueue_retry_action("broadcast", payload, reason="ACK timeout")
                return json.dumps({"success": False, "request_id": request_id,
                    "queued_for_retry": True,
                    "retry_queue_id": queued["retry_id"],
                    "retry_queue_count": len(_retry_queue()),
                    "message": "ACK timeout. Broadcast disimpan di retry queue lokal."})
            if ack.get("delivered", False):
                return json.dumps({"success": ack.get("accepted", False),
                    "accepted": ack.get("accepted", False),
                    "delivered": ack.get("delivered", False),
                    "recipient_count": ack.get("recipient_count", 0),
                    "request_id": request_id,
                    "message_id": ack.get("message_id"),
                    "sequence": ack.get("sequence"),
                    "message": "Broadcast diterima relay."})
            queued = _enqueue_retry_action("broadcast", payload, reason="Belum ada penerima aktif")
            return json.dumps({"success": False,
                "accepted": ack.get("accepted", False),
                "delivered": ack.get("delivered", False),
                "recipient_count": ack.get("recipient_count", 0),
                "request_id": request_id,
                "message_id": ack.get("message_id"),
                "sequence": ack.get("sequence"),
                "queued_for_retry": True,
                "retry_queue_id": queued["retry_id"],
                "retry_queue_count": len(_retry_queue()),
                "message": "Broadcast disimpan di retry queue lokal sampai ada penerima aktif."})
        except Exception as e:
            queued = _enqueue_retry_action("broadcast", payload, reason=str(e))
            return json.dumps({"success": False, "error": str(e),
                "queued_for_retry": True,
                "retry_queue_id": queued["retry_id"],
                "retry_queue_count": len(_retry_queue())})
  • BroadcastInput Pydantic model defining the input schema for agent_broadcast tool. Requires 'message' (min 1 char) and optional 'msg_type' (default 'text').
    class BroadcastInput(BaseModel):
        model_config = ConfigDict(str_strip_whitespace=True, extra="forbid")
        message:  str = Field(..., description="Isi pesan ke semua peer", min_length=1)
        msg_type: str = Field(default="text", description="Tipe pesan")
  • Server-side WebSocket handler for 'broadcast' message type in the AgentLinkRoom Durable Object. Creates a room message with broadcast=true, sends to all connected agents except sender, and returns an ACK with recipient count.
    if (msg.type === "broadcast") {
      const timestamp = new Date().toISOString();
      const sequence = await this.nextSequence();
      const payload = createRoomMessage({
        roomId,
        sequence,
        timestamp,
        from: agentId,
        fromName: name,
        content: msg.content,
        msgType: typeof msg.msg_type === "string" ? msg.msg_type : "text",
        broadcast: true,
      });
      const recipientCount = this.broadcast(ws, JSON.stringify(payload));
      const requestId = typeof msg.request_id === "string" ? msg.request_id : undefined;
    
      ws.send(JSON.stringify(createAck({
        action: "broadcast",
        roomId,
        requestId,
        delivered: recipientCount > 0,
        recipientCount,
        timestamp,
        messageId: payload.message_id,
        sequence: payload.sequence,
        broadcast: true,
      })));
      return;
    }
  • createRoomMessage helper function used by the broadcast handler to construct the message payload with room_id, sequence, timestamp, from, content, msg_type, and broadcast flag.
    export function createRoomMessage(params: {
      roomId: string;
      sequence: number;
      timestamp: string;
      from: string;
      fromName: string;
      content: unknown;
      msgType?: string;
      broadcast?: boolean;
    }): RoomMessagePayload {
      return {
        type: "message",
        room_id: params.roomId,
        message_id: buildMessageId(params.roomId, params.sequence),
        sequence: params.sequence,
        timestamp: params.timestamp,
        from: params.from,
        from_name: params.fromName,
        content: params.content,
        msg_type: params.msgType || "text",
        broadcast: params.broadcast === true,
      };
    }
  • RoomMessagePayload TypeScript interface defining the structure of broadcast messages including type, from, from_name, content, msg_type, and broadcast boolean flag.
    export interface RoomMessagePayload extends SequencedRoomPayload {
      type: "message";
      from: string;
      from_name: string;
      content: unknown;
      msg_type: string;
      broadcast: boolean;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the broadcast mechanism (Cloudflare relay) but lacks critical behavioral details: whether this requires specific permissions, if messages are persistent, rate limits, error conditions, or what 'JSON status broadcast' entails. For a communication tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief and structured with Args and Returns sections, making it easy to scan. However, the Indonesian language may reduce clarity for some agents, and the single sentence could be more front-loaded with key details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, 0% schema coverage, but an output schema exists (implied by 'Returns: str: JSON status broadcast'), the description is moderately complete. It covers purpose and parameters but lacks behavioral context and usage guidelines, which are critical for a broadcast tool in a multi-agent system.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It lists params (message, msg_type) and their roles, adding meaning beyond the bare schema. However, it doesn't explain msg_type options (e.g., 'text' default) or message constraints, leaving gaps. With 1 parameter (a nested object with 2 fields), the baseline is 4, but incomplete details lower the score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Kirim pesan' = Send message) and target ('ke semua agent di room' = to all agents in the room) with the mechanism ('via Cloudflare relay'). It distinguishes from siblings like agent_send (likely point-to-point) and agent_read_inbox (receiving). However, it doesn't explicitly contrast with all relevant siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., being in a room), when not to use it (e.g., for private messages), or compare with siblings like agent_send for targeted communication.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/syuaibsyuaib/ssyubix'

If you have feedback or need assistance with the MCP directory API, please join our Discord server