Skip to main content
Glama
liveblocks

Liveblocks

Official
by liveblocks

get-storage-document

Retrieve collaborative document data from a Liveblocks room using its unique room ID to access stored content.

Instructions

Get a Liveblocks storage document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
roomIdYes

Implementation Reference

  • Handler function that retrieves the Liveblocks storage document for the given roomId by calling the Liveblocks API through callLiveblocksApi.
    async ({ roomId }, extra) => {
      return await callLiveblocksApi(
        getLiveblocks().getStorageDocument(roomId, "json", {
          signal: extra.signal,
        })
      );
    }
  • Input schema defining the required 'roomId' parameter as a string.
    {
      roomId: z.string(),
    },
  • src/server.ts:191-204 (registration)
    Full registration of the 'get-storage-document' tool using McpServer.tool(), including name, description, input schema, and handler.
    server.tool(
      "get-storage-document",
      "Get a Liveblocks storage document",
      {
        roomId: z.string(),
      },
      async ({ roomId }, extra) => {
        return await callLiveblocksApi(
          getLiveblocks().getStorageDocument(roomId, "json", {
            signal: extra.signal,
          })
        );
      }
    );
  • Utility function used by all tools to call Liveblocks APIs and format the response as an MCP CallToolResult, handling success and error cases.
    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 using the secret key from environment.
    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