get_document
Retrieve detailed information about a collaborative document by specifying its unique ID. The tool works with the Tiptap Collaboration MCP Server to manage document interactions.
Instructions
Get information about a collaborative document
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID of the document to retrieve |
Implementation Reference
- src/tools/get-document.ts:15-65 (handler)The core handler function for the 'get-document' tool. It makes an HTTP request to the API to fetch document information based on the provided ID, handles authentication, parses the response, and returns formatted text content or an error message.
async ({ id }) => { 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}`, { headers }); if (!response.ok) { return { content: [ { type: 'text', text: `Document with ID ${id} not found. HTTP error: ${response.status} ${response.statusText}`, }, ], }; } const documentData = await response.json(); return { content: [ { type: 'text', text: `Document Information: ${JSON.stringify( documentData, null, 2 )}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error retrieving document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } } ); - src/tools/get-document.ts:12-14 (schema)Input schema definition using Zod, specifying a required 'id' string parameter for the document ID.
{ id: z.string().describe('ID of the document to retrieve'), }, - src/tools/get-document.ts:4-66 (registration)The registration function exported from the tool file, which calls server.tool() to register the 'get-document' tool with its name, description, schema, and handler on the MCP server.
export default function registerGetDocument( server: McpServer, getBaseUrl: () => string, getToken: () => string | undefined ) { server.tool( 'get-document', 'Get information about a collaborative document', { id: z.string().describe('ID of the document to retrieve'), }, async ({ id }) => { 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}`, { headers }); if (!response.ok) { return { content: [ { type: 'text', text: `Document with ID ${id} not found. HTTP error: ${response.status} ${response.statusText}`, }, ], }; } const documentData = await response.json(); return { content: [ { type: 'text', text: `Document Information: ${JSON.stringify( documentData, null, 2 )}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error retrieving document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } } ); } - src/server.ts:53-53 (registration)The call to register the 'get-document' tool on the main MCP server instance.
registerGetDocument(server, getBaseUrl, getToken);