Skip to main content
Glama
liveblocks
by liveblocks

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
NameRequiredDescriptionDefault
roomIdYes
threadIdYes
dataYes

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 } ) ); } );
  • 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), });
  • 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, }, ], }; } }
  • 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; }

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/liveblocks/liveblocks-mcp-server'

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