get_document_context
Retrieve documents with complete context including links, references, and AI metadata to support project management workflows.
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 main handler function that implements the core logic of the 'get_document_context' tool. It validates input, fetches the document from Supabase, performs content analysis, extracts links, finds related documents, and returns comprehensive context.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 providing the schema, name, and description for the 'get_document_context' tool, used for tool discovery and input validation.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)Module-level registration of the getDocumentContext handler in the documentHandlers object, which is imported and merged into the global allHandlers in src/index.ts for MCP tool execution.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)Module-level registration of the getDocumentContextTool schema in the documentTools object, imported and merged into the global allTools for MCP tool listing.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, structure, links, 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) } }