Skip to main content
Glama

Tiptap Collaboration MCP Server

by trainual
duplicate-document.ts3.02 kB
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { z } from 'zod'; export default function registerDuplicateDocument( server: McpServer, getBaseUrl: () => string, getToken: () => string | undefined ) { server.tool( 'duplicate-document', 'Duplicate a collaborative document', { sourceId: z.string().describe('ID of the source document to duplicate'), targetId: z.string().describe('ID for the new duplicated document'), }, async ({ sourceId, targetId }) => { try { const headers: Record<string, string> = { 'User-Agent': 'tiptap-collaboration-mcp', 'Content-Type': 'application/json', }; const token = getToken(); if (token) headers['Authorization'] = token; // First, get the source document const getResponse = await fetch(`${getBaseUrl()}/api/documents/${sourceId}`, { headers, }); if (!getResponse.ok) { if (getResponse.status === 404) { return { content: [ { type: 'text', text: `Source document with ID ${sourceId} not found.`, }, ], }; } return { content: [ { type: 'text', text: `Failed to retrieve source document. HTTP error: ${getResponse.status} ${getResponse.statusText}`, }, ], }; } const sourceContent = await getResponse.json(); // Then, create the new document with the source content const createResponse = await fetch(`${getBaseUrl()}/api/documents?format=json`, { method: 'POST', headers, body: JSON.stringify({ ...sourceContent, id: targetId }), }); if (!createResponse.ok) { if (createResponse.status === 409) { return { content: [ { type: 'text', text: `Target document with ID ${targetId} already exists. Choose a different ID or delete the existing document first.`, }, ], }; } return { content: [ { type: 'text', text: `Failed to create duplicate document. HTTP error: ${createResponse.status} ${createResponse.statusText}`, }, ], }; } return { content: [ { type: 'text', text: `Document ${sourceId} successfully duplicated to ${targetId}.`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error duplicating document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } } ); }

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