get_document_context
Retrieve documents with complete context including links, references, and AI metadata for comprehensive project management and analysis.
Instructions
Get document with full context including links, references, and AI metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | The unique identifier of the document |
Implementation Reference
- src/tools/documents.ts:352-375 (handler)The core handler function for the 'get_document_context' tool. It fetches the document by ID, performs content analysis, extracts links, generates AI context, finds related documents, and returns comprehensive context information.export const getDocumentContext = requireAuth(async (args: any) => { const { document_id } = GetDocumentSchema.parse(args) logger.info('Getting document context', { document_id }) const document = await supabaseService.getDocument(document_id) // Analyze document content and extract metadata const contentAnalysis = analyzeDocumentContentHelper(document.content, document.document_type) const linkAnalysis = extractDocumentLinks(document.content) const aiContext = extractAIContext({}) // Find related documents const relatedDocs = await findRelatedDocuments(document) return { document, content_analysis: contentAnalysis, link_analysis: linkAnalysis, ai_context: aiContext, related_documents: relatedDocs, recommendations: generateDocumentRecommendations(document, contentAnalysis) } })
- src/tools/documents.ts:336-350 (schema)The MCPTool definition including input schema for validating the document_id parameter (UUID string).export const getDocumentContextTool: MCPTool = { name: 'get_document_context', description: 'Get document with full context including links, references, and AI metadata', inputSchema: { type: 'object', properties: { document_id: { type: 'string', format: 'uuid', description: 'The unique identifier of the document' } }, required: ['document_id'] } }
- src/tools/documents.ts:1346-1358 (registration)Registration of the getDocumentContext handler in the documentHandlers object, likely used to register all document-related handlers centrally.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/registration of the getDocumentContextTool in the documentTools object for MCP tool registration.export const documentTools = { listDocumentsTool, createDocumentTool, getDocumentTool, updateDocumentTool, searchDocumentsTool, getDocumentContextTool, addDocumentCollaboratorTool, analyzeDocumentContentTool, getDocumentCollaborationTool, generateDocumentTemplateTool, bulkDocumentOperationsTool }
- src/tools/documents.ts:378-407 (helper)Key helper function called by the handler to analyze document content, extracting metrics like word count, headings, links, complexity, and AI readiness score.function analyzeDocumentContentHelper(content: string, documentType: string): object { // Parse frontmatter if present const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/) const hasFrontmatter = !!frontmatterMatch // Extract plain content (without frontmatter) const plainContent = hasFrontmatter ? content.replace(/^---\n[\s\S]*?\n---\n/, '') : content // Basic content analysis const words = plainContent.split(/\s+/).filter(w => w.length > 0) const lines = plainContent.split('\n') const headings = (plainContent.match(/^#+\s+.+$/gm) || []).length const codeBlocks = (plainContent.match(/```[\s\S]*?```/g) || []).length const links = (plainContent.match(/\[([^\]]+)\]\([^)]+\)/g) || []).length const internalLinks = (plainContent.match(/\[\[([^\]]+)\]\]/g) || []).length return { word_count: words.length, line_count: lines.length, character_count: plainContent.length, heading_count: headings, code_block_count: codeBlocks, link_count: links, internal_link_count: internalLinks, has_frontmatter: hasFrontmatter, estimated_read_time: Math.ceil(words.length / 200), // 200 words per minute content_complexity: calculateContentComplexity(plainContent, documentType), ai_readiness_score: calculateAIReadinessScore(content, hasFrontmatter) } }