From 683956f60d410228a7d27d44ee1c361f13044da2 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 23 Sep 2026 09:35:29 -0400 Subject: [PATCH] fix(mcp): corpus_status sorts Published dates chronologically corpus_status compared HPE "Published" values ("July 2026") as plain strings, so "March 2026" outranked "July 2026" for the most-recent date and the most-recently-edited ordering. Parse to (year, month) for both. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01SXZ3ZdHEP75P9YmyFM7W3k --- docs_mcp/server.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs_mcp/server.py b/docs_mcp/server.py index ec4613c..616f15b 100644 --- a/docs_mcp/server.py +++ b/docs_mcp/server.py @@ -810,6 +810,21 @@ def weekly_digest( return "\n".join(lines) +def _pub_sort_key(pub: str) -> tuple[int, int]: + """Sortable (year, month) for an HPE "Published" value like "July 2026". + + Plain string comparison ranks "March 2026" above "July 2026". + Unparseable values sort last. + """ + for fmt in ("%B %Y", "%b %Y", "%B %d, %Y", "%Y-%m-%d"): + try: + d = _dt.datetime.strptime(pub.strip(), fmt) + return (d.year, d.month) + except ValueError: + continue + return (0, 0) + + @mcp.tool() def corpus_status() -> str: """Freshness + size of the knowledge base. @@ -831,7 +846,7 @@ def corpus_status() -> str: for slug, b in cat.items(): pub = (b.get("dates") or {}).get("Published") if pub: - if latest_pub is None or pub > latest_pub: + if latest_pub is None or _pub_sort_key(pub) > _pub_sort_key(latest_pub): latest_pub = pub per_bundle.append((slug, pub)) if latest_pub: @@ -850,7 +865,7 @@ def corpus_status() -> str: "", ] if per_bundle: - per_bundle.sort(key=lambda kv: kv[1], reverse=True) + per_bundle.sort(key=lambda kv: _pub_sort_key(kv[1]), reverse=True) lines.append("## Most-recently-edited bundles (by HPE)") for slug, when in per_bundle[:5]: b = cat.get(slug, {}) -- 2.54.0