create-comment
Add comments to collaborative documents in Liveblocks rooms. Specify room, thread, user ID, and comment content to enable real-time discussion.
Instructions
Create a Liveblocks comment. Always ask for a userId.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| roomId | Yes | ||
| threadId | Yes | ||
| data | Yes |
Implementation Reference
- src/server.ts:452-472 (registration)Full registration of the 'create-comment' MCP tool, including inline schema definition and handler function that delegates to Liveblocks client.
server.tool( "create-comment", `Create a Liveblocks comment. Always ask for a userId.`, { roomId: z.string(), threadId: z.string(), data: z.object({ body: CommentBody, userId: z.string(), createdAt: z.date().optional(), }), }, async ({ roomId, threadId, data }, extra) => { return await callLiveblocksApi( getLiveblocks().createComment( { roomId, threadId, data }, { signal: extra.signal } ) ); } ); - src/zod.ts:3-36 (schema)Zod schema definition for CommentBody, used in the input parameters for creating a comment (body field). Supports rich text with text, mentions, links, formatting.
const CommentBodyText = z.object({ text: z.string(), bold: z.boolean().optional(), italic: z.boolean().optional(), strikethrough: z.boolean().optional(), code: z.boolean().optional(), }); const CommentBodyMention = z.object({ type: z.literal("mention"), id: z.string(), }); const CommentBodyLink = z.object({ type: z.literal("link"), url: z.string(), text: z.string().optional(), }); const CommentBodyInlineElement = z.union([ CommentBodyText, CommentBodyMention, CommentBodyLink, ]); const CommentBodyParagraph = z.object({ type: z.literal("paragraph"), children: z.array(CommentBodyInlineElement), }); export const CommentBody = z.object({ version: z.literal(1), content: z.array(CommentBodyParagraph), }); - src/utils.ts:3-37 (helper)Utility function used by the handler to call Liveblocks API promises and format the response as MCP CallToolResult, including JSON stringification of data or error handling.
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 to lazily initialize and return the Liveblocks client instance used in all tool handlers, including create-comment.
function getLiveblocks() { if (!client) { client = new Liveblocks({ secret: process.env.LIVEBLOCKS_SECRET_KEY as string, }); } return client; }