create_document
Initiate a collaborative document with a specified name and optional initial content using the Tiptap Collaboration MCP Server for efficient team editing and management.
Instructions
Create a new collaborative document
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | Initial content for the document | |
| name | Yes | Name of the document |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"content": {
"description": "Initial content for the document",
"type": "string"
},
"name": {
"description": "Name of the document",
"type": "string"
}
},
"required": [
"name"
],
"type": "object"
}
Implementation Reference
- src/tools/create-document.ts:39-129 (handler)The asynchronous function that executes the 'create-document' tool logic. It makes a POST request to the /api/documents/{name} endpoint with the provided content in Tiptap JSON format, handles various HTTP responses including errors like 409 (already exists), and returns formatted text content indicating success or failure.async ({ name, content }) => { 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/${name}?format=json`, { method: 'POST', headers, body: JSON.stringify(content), } ); if (!response.ok) { if (response.status === 409) { return { content: [ { type: 'text', text: `Document with name ${name} already exists. Choose a different name or delete the existing document first.`, }, ], }; } return { content: [ { type: 'text', text: `Failed to create document. HTTP error: ${response.status} ${response.statusText}`, }, ], }; } // Handle successful response - 204 No Content means success with empty body if (response.status === 204) { return { content: [ { type: 'text', text: `Document '${name}' created successfully.`, }, ], }; } // For other success status codes, try to parse JSON response try { const documentData = await response.json(); return { content: [ { type: 'text', text: `Document created successfully: ${JSON.stringify( documentData, null, 2 )}`, }, ], }; } catch (parseError) { // If JSON parsing fails, just return success message return { content: [ { type: 'text', text: `Document '${name}' created successfully (no response data).`, }, ], }; } } catch (error) { return { content: [ { type: 'text', text: `Error creating document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- src/tools/create-document.ts:12-38 (schema)Zod schema for the tool inputs: 'name' (required string) and 'content' (optional Tiptap JSON object with a sensible default).{ name: z.string().describe('name of the new document'), content: z .object({}) .passthrough() .default({ type: 'doc', content: [ { type: 'paragraph', attrs: { indent: 0, textAlign: 'left', }, content: [ { text: 'Test', type: 'text', }, ], }, ], }) .describe( 'Document content in Tiptap JSON format (uses default if not provided)' ), },
- src/tools/create-document.ts:9-130 (registration)The server.tool() call that registers the 'create-document' tool with its name, description, input schema, and handler function within the registerCreateDocument module.server.tool( 'create-document', 'Create a new collaborative document', { name: z.string().describe('name of the new document'), content: z .object({}) .passthrough() .default({ type: 'doc', content: [ { type: 'paragraph', attrs: { indent: 0, textAlign: 'left', }, content: [ { text: 'Test', type: 'text', }, ], }, ], }) .describe( 'Document content in Tiptap JSON format (uses default if not provided)' ), }, async ({ name, content }) => { 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/${name}?format=json`, { method: 'POST', headers, body: JSON.stringify(content), } ); if (!response.ok) { if (response.status === 409) { return { content: [ { type: 'text', text: `Document with name ${name} already exists. Choose a different name or delete the existing document first.`, }, ], }; } return { content: [ { type: 'text', text: `Failed to create document. HTTP error: ${response.status} ${response.statusText}`, }, ], }; } // Handle successful response - 204 No Content means success with empty body if (response.status === 204) { return { content: [ { type: 'text', text: `Document '${name}' created successfully.`, }, ], }; } // For other success status codes, try to parse JSON response try { const documentData = await response.json(); return { content: [ { type: 'text', text: `Document created successfully: ${JSON.stringify( documentData, null, 2 )}`, }, ], }; } catch (parseError) { // If JSON parsing fails, just return success message return { content: [ { type: 'text', text: `Document '${name}' created successfully (no response data).`, }, ], }; } } catch (error) { return { content: [ { type: 'text', text: `Error creating document: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } } );
- src/server.ts:47-47 (registration)The call to registerCreateDocument which sets up the tool on the main McpServer instance.registerCreateDocument(server, getBaseUrl, getToken);
- src/server.ts:3-3 (registration)Import of the registerCreateDocument function used to register the tool.import registerCreateDocument from './tools/create-document.js';