Skip to main content
Glama
by trainual

update_document

Modify collaborative documents by updating or appending content in Tiptap JSON format, specifying the document ID and update mode (replace or append).

Instructions

Update a collaborative document with new content

Input Schema

NameRequiredDescriptionDefault
contentYesDocument content in Tiptap JSON format
idYesID of the document to update
modeNoUpdate mode: replace entire document or append content (default: replace)

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "content": { "additionalProperties": false, "description": "Document content in Tiptap JSON format", "properties": {}, "type": "object" }, "id": { "description": "ID of the document to update", "type": "string" }, "mode": { "description": "Update mode: replace entire document or append content (default: replace)", "enum": [ "replace", "append" ], "type": "string" } }, "required": [ "id", "content" ], "type": "object" }

Implementation Reference

  • The handler function that implements the core logic of the 'update-document' tool. It performs an HTTP PATCH request to the API to update the document content, handles specific error codes (404, 422), and returns structured content responses.
    async ({ id, content, mode = 'replace' }) => { try { const headers: Record<string, string> = { 'User-Agent': 'tiptap-collaboration-mcp', 'Content-Type': 'application/json', }; const token = getToken(); if (token) headers['Authorization'] = token; const response = await fetch(`${getBaseUrl()}/api/documents/${id}?mode=${mode}`, { method: 'PATCH', headers, body: JSON.stringify(content), }); if (!response.ok) { if (response.status === 404) { return { content: [ { type: 'text', text: `Document with ID ${id} not found.`, }, ], }; } if (response.status === 422) { return { content: [ { type: 'text', text: `Invalid payload or update cannot be applied to document ${id}.`, }, ], }; } return { content: [ { type: 'text', text: `Failed to update document. HTTP error: ${response.status} ${response.statusText}`, }, ], }; } return { content: [ { type: 'text', text: `Document with ID ${id} updated successfully using ${mode} mode.`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error updating document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
  • Zod schema for the tool's input parameters: document ID, content object, and optional update mode.
    { id: z.string().describe('ID of the document to update'), content: z.object({}).describe('Document content in Tiptap JSON format'), mode: z.enum(['replace', 'append']).optional().describe('Update mode: replace entire document or append content (default: replace)'), },
  • The registration function exported from the tool module, which calls server.tool to register the 'update-document' tool with its schema and handler.
    export default function registerUpdateDocument( server: McpServer, getBaseUrl: () => string, getToken: () => string | undefined ) { server.tool( 'update-document', 'Update a collaborative document with new content', { id: z.string().describe('ID of the document to update'), content: z.object({}).describe('Document content in Tiptap JSON format'), mode: z.enum(['replace', 'append']).optional().describe('Update mode: replace entire document or append content (default: replace)'), }, async ({ id, content, mode = 'replace' }) => { try { const headers: Record<string, string> = { 'User-Agent': 'tiptap-collaboration-mcp', 'Content-Type': 'application/json', }; const token = getToken(); if (token) headers['Authorization'] = token; const response = await fetch(`${getBaseUrl()}/api/documents/${id}?mode=${mode}`, { method: 'PATCH', headers, body: JSON.stringify(content), }); if (!response.ok) { if (response.status === 404) { return { content: [ { type: 'text', text: `Document with ID ${id} not found.`, }, ], }; } if (response.status === 422) { return { content: [ { type: 'text', text: `Invalid payload or update cannot be applied to document ${id}.`, }, ], }; } return { content: [ { type: 'text', text: `Failed to update document. HTTP error: ${response.status} ${response.statusText}`, }, ], }; } return { content: [ { type: 'text', text: `Document with ID ${id} updated successfully using ${mode} mode.`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error updating document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } } ); }
  • src/server.ts:59-59 (registration)
    Invocation of the registerUpdateDocument function on the main MCP server instance, integrating the tool into the server.
    registerUpdateDocument(server, getBaseUrl, getToken);

Other Tools

Related Tools

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/trainual/tiptap-collaboration-mcp'

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