UNPKG

@iflow-mcp/ansvar-systems-german-law-mcp

Version:

German legal research MCP server with statutes, case law, and preparatory works from gesetze-im-internet.de

111 lines (110 loc) • 4.41 kB
/** * metadata.ts — Centralized metadata generation for all tool responses. * * Provides professional-use warnings, data freshness tracking, and source authority disclosure. */ /** * Generate standard metadata for tool responses. * * This provides consistent professional-use warnings, data freshness tracking, * and source authority disclosure across all tools. * * @param db - Optional database handle. If not provided, data freshness checks are skipped. */ export function generateResponseMetadata(db) { const dataFreshness = db ? getDataFreshness(db) : getEmptyDataFreshness(); const sourceAuthority = getSourceAuthority(); return { data_freshness: dataFreshness, disclaimer: 'NOT LEGAL ADVICE. This tool is for research purposes only and does not constitute professional legal advice. Always verify citations with official sources before relying on them in legal matters. Users are solely responsible for verifying accuracy and currency of all information.', source_authority: sourceAuthority, coverage_gaps: [ 'Landesrecht (state-level legislation of 16 Bundeslaender)', 'CJEU (Court of Justice of the European Union) case law', 'Historical statute versions (limited availability)', 'Legal commentary and annotations (Kommentare)' ], ai_disclosure: 'AI-assisted legal research tool. Results generated by algorithmic search and may contain errors or omissions. Human review required before professional use.' }; } /** * Return empty data freshness when database is not available. */ function getEmptyDataFreshness() { return { statute_last_updated: null, case_law_last_sync: null, staleness_warning: 'Data freshness information unavailable (tool does not query database)' }; } /** * Check data freshness and generate staleness warnings. */ function getDataFreshness(db) { let statuteLastUpdated = null; try { const statuteRow = db.prepare(` SELECT MAX(last_updated) as max_date FROM legal_documents WHERE type = 'statute' AND last_updated IS NOT NULL `).get(); statuteLastUpdated = statuteRow?.max_date || null; } catch { // Ignore errors } let caseLawLastSync = null; try { const caseRow = db.prepare(` SELECT last_sync_date FROM case_law_sync_metadata WHERE id = 1 `).get(); caseLawLastSync = caseRow?.last_sync_date || null; } catch { // Table might not exist yet } const stalenessWarning = calculateStalenessWarning(statuteLastUpdated, caseLawLastSync); return { statute_last_updated: statuteLastUpdated, case_law_last_sync: caseLawLastSync, staleness_warning: stalenessWarning }; } /** * Generate staleness warning if data is >30 days old. */ function calculateStalenessWarning(statuteDate, caseLawDate) { const now = new Date(); const thirtyDaysAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000); const warnings = []; if (statuteDate) { const statuteTimestamp = new Date(statuteDate); if (statuteTimestamp < thirtyDaysAgo) { const daysOld = Math.floor((now.getTime() - statuteTimestamp.getTime()) / (24 * 60 * 60 * 1000)); warnings.push(`Statute data is ${daysOld} days old - amendments may have been published in the BGBl`); } } else { warnings.push('Statute update timestamp unavailable'); } if (caseLawDate) { const caseLawTimestamp = new Date(caseLawDate); if (caseLawTimestamp < thirtyDaysAgo) { const daysOld = Math.floor((now.getTime() - caseLawTimestamp.getTime()) / (24 * 60 * 60 * 1000)); warnings.push(`Case law data is ${daysOld} days old - new decisions may be missing`); } } return warnings.length > 0 ? warnings.join('. ') : null; } /** * Get source authority disclosure. */ function getSourceAuthority() { return { primary_source: 'Gesetze im Internet (gesetze-im-internet.de) and BGBl (Bundesgesetzblatt) for federal statutes; EUR-Lex for EU-reference metadata', authority_level: 'official', verification_required: 'ALWAYS cross-check with current official publications on gesetze-im-internet.de or BGBl before relying on output in legal or compliance work.' }; }