From 9e707661afa1c983b050309328329ace0086bb3b Mon Sep 17 00:00:00 2001 From: davegilligan Date: Tue, 2 Jun 2026 21:40:00 +0200 Subject: [PATCH] feat(mcp): expose ai_summary in dbn_get_document response LEFT JOIN doc_summaries so the document object includes ai_summary and summary_model alongside id/title. Returns null for docs not yet backfilled. --- api/document-chunks.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/api/document-chunks.php b/api/document-chunks.php index fdc375c..87274b2 100644 --- a/api/document-chunks.php +++ b/api/document-chunks.php @@ -18,7 +18,13 @@ try { $ragDb = dbnToolsRagDb(); - $docStmt = $ragDb->prepare("SELECT id, title FROM documents WHERE id = ? LIMIT 1"); + $docStmt = $ragDb->prepare(" + SELECT d.id, d.title, ds.summary AS ai_summary, ds.summary_model + FROM documents d + LEFT JOIN doc_summaries ds ON ds.document_id = d.id + WHERE d.id = ? + LIMIT 1 + "); $docStmt->execute([$documentId]); $doc = $docStmt->fetch(PDO::FETCH_ASSOC); if (!$doc) { @@ -44,7 +50,12 @@ try { echo json_encode([ 'ok' => true, - 'document' => ['id' => (int)$doc['id'], 'title' => (string)$doc['title']], + 'document' => [ + 'id' => (int)$doc['id'], + 'title' => (string)$doc['title'], + 'ai_summary' => $doc['ai_summary'] ?? null, + 'summary_model' => $doc['summary_model'] ?? null, + ], 'chunks' => $chunks, ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);