Explorar el Código

news-mcp: add include_articles option to get_event_summary

Lukas Goldschmidt hace 1 mes
padre
commit
e467cf07a2
Se han modificado 1 ficheros con 20 adiciones y 2 borrados
  1. 20 2
      news_mcp/mcp_server_fastmcp.py

+ 20 - 2
news_mcp/mcp_server_fastmcp.py

@@ -175,7 +175,7 @@ async def get_events_for_entity(entity: str, limit: int = 10, include_articles:
 
 
 @mcp.tool(description="Explain an event clearly by cluster_id (Groq summary).")
-async def get_event_summary(event_id: str):
+async def get_event_summary(event_id: str, include_articles: bool = False):
     store = SQLiteClusterStore(DB_PATH)
 
     # Summary cache: reuse if present within TTL.
@@ -199,10 +199,24 @@ async def get_event_summary(event_id: str):
             "error": "NOT_FOUND",
         }
 
+    articles_out = None
+    if include_articles:
+        arts = cluster.get("articles", []) or []
+        articles_out = [
+            {
+                "title": a.get("title"),
+                "url": a.get("url"),
+                "source": a.get("source"),
+                "timestamp": a.get("timestamp"),
+            }
+            for a in arts
+            if isinstance(a, dict)
+        ]
+
     summary = await summarize_cluster_groq(cluster)
 
     store.upsert_cluster_summary(event_id, summary)
-    return {
+    out = {
         "event_id": event_id,
         "headline": summary.get("headline"),
         "mergedSummary": summary.get("mergedSummary"),
@@ -210,6 +224,10 @@ async def get_event_summary(event_id: str):
         "sources": summary.get("sources", []),
     }
 
+    if include_articles:
+        out["articles"] = articles_out or []
+    return out
+
 
 @mcp.tool(description="Detect emerging topics/entities from recent cached news clusters.")
 async def detect_emerging_topics(limit: int = 10):