broadcast-event
Send real-time events to a specified room in Liveblocks, enabling instant communication and updates for collaborative applications.
Instructions
Broadcast an event to a Liveblocks room
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| event | Yes | ||
| roomId | Yes |
Implementation Reference
- src/server.ts:182-186 (handler)Executes the broadcast-event tool by calling Liveblocks broadcastEvent method wrapped in callLiveblocksApi.async ({ roomId, event }, extra) => { return await callLiveblocksApi( getLiveblocks().broadcastEvent(roomId, event, { signal: extra.signal }) ); }
- src/server.ts:178-181 (schema)Zod input schema for roomId (string) and event (any object).{ roomId: z.string(), event: z.record(z.string(), z.any()), },
- src/server.ts:175-187 (registration)Registers the 'broadcast-event' tool on the McpServer instance.server.tool( "broadcast-event", "Broadcast an event to a Liveblocks room", { roomId: z.string(), event: z.record(z.string(), z.any()), }, async ({ roomId, event }, extra) => { return await callLiveblocksApi( getLiveblocks().broadcastEvent(roomId, event, { signal: extra.signal }) ); } );
- src/utils.ts:3-37 (helper)Utility function that wraps Liveblocks API promises, formats successful responses as JSON in MCP format, and handles errors.export async function callLiveblocksApi( liveblocksPromise: Promise<any> ): Promise<CallToolResult> { try { const data = await liveblocksPromise; if (!data) { return { content: [{ type: "text", text: "Success. No data returned." }], }; } return { content: [ { type: "text", text: "Here is the data. If the user has no specific questions, return it in a JSON code block", }, { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (err) { return { content: [ { type: "text", text: "" + err, }, ], }; } }
- src/server.ts:21-28 (helper)Singleton factory for the Liveblocks client using the secret key from environment.function getLiveblocks() { if (!client) { client = new Liveblocks({ secret: process.env.LIVEBLOCKS_SECRET_KEY as string, }); } return client; }