add_document_collaborator
Grant document access to users by assigning read, comment, edit, or admin permissions to enable collaborative work.
Instructions
Add a collaborator to a document with specific permissions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | ID of the document | |
| user_id | Yes | ID of the user to add as collaborator | |
| permission_level | No | Permission level for the collaborator | edit |
| notify | No | Whether to notify the user about collaboration invite |
Implementation Reference
- src/tools/documents.ts:653-681 (handler)The main handler function that executes the tool logic: validates args, fetches document, creates collaboration record, and returns results.export const addDocumentCollaborator = requireAuth(async (args: any) => { const { document_id, user_id, permission_level, notify } = AddDocumentCollaboratorSchema.parse(args) logger.info('Adding document collaborator', { document_id, user_id, permission_level }) // Get document and verify permissions const document = await supabaseService.getDocument(document_id) if (!document) { throw new Error('Document not found') } // Create collaboration record const collaboration = await supabaseService.createDocumentCollaboration({ document_id, user_id, permission_level, status: 'active', invited_at: new Date().toISOString() }) // Note: metadata field doesn't exist in the database schema // Collaboration would be tracked in a separate table return { collaboration, document: await supabaseService.getDocument(document_id), message: `User added as ${permission_level} collaborator` } })
- src/tools/documents.ts:646-651 (schema)Zod input validation schema used by the handler for parsing arguments.const AddDocumentCollaboratorSchema = z.object({ document_id: z.string().min(1), user_id: z.string().min(1), permission_level: z.enum(['read', 'comment', 'edit', 'admin']).default('edit'), notify: z.boolean().default(true) })
- src/tools/documents.ts:616-644 (registration)MCPTool object definition exporting the tool name, description, and input schema for registration.export const addDocumentCollaboratorTool: MCPTool = { name: 'add_document_collaborator', description: 'Add a collaborator to a document with specific permissions', inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: 'ID of the document' }, user_id: { type: 'string', description: 'ID of the user to add as collaborator' }, permission_level: { type: 'string', enum: ['read', 'comment', 'edit', 'admin'], default: 'edit', description: 'Permission level for the collaborator' }, notify: { type: 'boolean', default: true, description: 'Whether to notify the user about collaboration invite' } }, required: ['document_id', 'user_id'] } }
- src/tools/documents.ts:1346-1358 (registration)Registration of the handler function under its tool name in the documentHandlers export map.export const documentHandlers = { list_documents: listDocuments, create_document: createDocument, get_document: getDocument, update_document: updateDocument, search_documents: searchDocuments, get_document_context: getDocumentContext, add_document_collaborator: addDocumentCollaborator, analyze_document_content: analyzeDocumentContent, get_document_collaboration: getDocumentCollaboration, generate_document_template: generateDocumentTemplate, bulk_document_operations: bulkDocumentOperations }
- src/tools/documents.ts:1361-1373 (registration)Export of all document tools including addDocumentCollaboratorTool for top-level registration.export const documentTools = { listDocumentsTool, createDocumentTool, getDocumentTool, updateDocumentTool, searchDocumentsTool, getDocumentContextTool, addDocumentCollaboratorTool, analyzeDocumentContentTool, getDocumentCollaborationTool, generateDocumentTemplateTool, bulkDocumentOperationsTool }