|
@@ -108,8 +108,8 @@ async def get_latest_events(topic: str = "crypto", limit: int = 5, include_artic
|
|
|
return out
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
-@mcp.tool(description="What's happening with X? Filter latest clusters by extracted entity substring (case-insensitive).")
|
|
|
|
|
-async def get_events_for_entity(entity: str, limit: int = 10, include_articles: bool = False):
|
|
|
|
|
|
|
+@mcp.tool(description="What's happening with X? Filter clusters by extracted entity substring (case-insensitive) within a timeframe.")
|
|
|
|
|
+async def get_events_for_entity(entity: str, limit: int = 10, timeframe: str = "24h", include_articles: bool = False):
|
|
|
limit = max(1, min(int(limit), 30))
|
|
limit = max(1, min(int(limit), 30))
|
|
|
query = normalize_query(entity).strip().lower()
|
|
query = normalize_query(entity).strip().lower()
|
|
|
if not query:
|
|
if not query:
|
|
@@ -124,7 +124,6 @@ async def get_events_for_entity(entity: str, limit: int = 10, include_articles:
|
|
|
}
|
|
}
|
|
|
query_terms = {q for q in query_terms if q}
|
|
query_terms = {q for q in query_terms if q}
|
|
|
|
|
|
|
|
- # Cache-first: search recent clusters across all topics.
|
|
|
|
|
store = SQLiteClusterStore(DB_PATH)
|
|
store = SQLiteClusterStore(DB_PATH)
|
|
|
|
|
|
|
|
def _match_clusters(clusters: list[dict]) -> list[dict]:
|
|
def _match_clusters(clusters: list[dict]) -> list[dict]:
|
|
@@ -140,10 +139,9 @@ async def get_events_for_entity(entity: str, limit: int = 10, include_articles:
|
|
|
clusters = store.get_latest_clusters_all_topics(ttl_hours=CLUSTERS_TTL_HOURS, limit=limit * 5)
|
|
clusters = store.get_latest_clusters_all_topics(ttl_hours=CLUSTERS_TTL_HOURS, limit=limit * 5)
|
|
|
hits = _match_clusters(clusters)
|
|
hits = _match_clusters(clusters)
|
|
|
|
|
|
|
|
- # If the recent slice misses, broaden the search window before giving up.
|
|
|
|
|
- if not hits:
|
|
|
|
|
- clusters = store.get_latest_clusters_all_topics(ttl_hours=24 * 7, limit=500)
|
|
|
|
|
- hits = _match_clusters(clusters)
|
|
|
|
|
|
|
+ hours = _parse_timeframe_to_hours(timeframe)
|
|
|
|
|
+ clusters = store.get_latest_clusters_all_topics(ttl_hours=hours, limit=max(200, limit * 10))
|
|
|
|
|
+ hits = _match_clusters(clusters)
|
|
|
|
|
|
|
|
# Compress to tool response shape.
|
|
# Compress to tool response shape.
|
|
|
out = []
|
|
out = []
|