create-thread
Initiate a thread within a Liveblocks room by specifying a roomId and including a structured comment with userId, enabling collaborative discussions.
Instructions
Create a Liveblocks thread. Always ask for a userId.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | ||
| roomId | Yes |
Implementation Reference
- src/server.ts:259-280 (registration)Registration of the 'create-thread' MCP tool, including inline schema definition and handler function that delegates to Liveblocks SDK's createThread method.server.tool( "create-thread", `Create a Liveblocks thread. Always ask for a userId.`, { roomId: z.string(), data: z.object({ comment: z.object({ body: CommentBody, userId: z.string(), createdAt: z.date().optional(), }), metadata: z .record(z.string(), z.union([z.string(), z.boolean(), z.number()])) .optional(), }), }, async ({ roomId, data }, extra) => { return await callLiveblocksApi( getLiveblocks().createThread({ roomId, data }, { signal: extra.signal }) ); } );
- src/zod.ts:33-36 (schema)Zod schema definition for CommentBody, referenced in the create-thread tool's input schema.export const CommentBody = z.object({ version: z.literal(1), content: z.array(CommentBodyParagraph), });
- src/utils.ts:1-37 (helper)Helper utility function callLiveblocksApi used by the create-thread handler to execute the Liveblocks API call and format the MCP tool response.import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; 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)Helper function getLiveblocks() used in create-thread handler to initialize and return the Liveblocks client instance.function getLiveblocks() { if (!client) { client = new Liveblocks({ secret: process.env.LIVEBLOCKS_SECRET_KEY as string, }); } return client; }