From a984ce1892fbf026c53c8679a27ec28dc77dc3e4 Mon Sep 17 00:00:00 2001 From: Mikei386 <44135113+Mikei386@users.noreply.github.com> Date: Tue, 25 Aug 2026 15:33:59 +0200 Subject: [PATCH] Refresh MCP tools in Hermes API agents --- compose.yaml | 1 + platform/hermes/patch-api-mcp-refresh.py | 44 ++++++++++++++++++++++++ platform/hermes/start-hermes-managed.sh | 4 +++ 3 files changed, 49 insertions(+) create mode 100644 platform/hermes/patch-api-mcp-refresh.py diff --git a/compose.yaml b/compose.yaml index c0a538e..9570bd3 100644 --- a/compose.yaml +++ b/compose.yaml @@ -803,6 +803,7 @@ services: - /data/hermes:/opt/data - /data/hermes/workspace:/workspace - ./platform/hermes/start-hermes-managed.sh:/usr/local/bin/start-hermes-managed:ro + - ./platform/hermes/patch-api-mcp-refresh.py:/usr/local/lib/mike-ai/patch-api-mcp-refresh.py:ro environment: HERMES_HOME: /opt/data dns: ["${AI_DNS:-1.1.1.1}"] diff --git a/platform/hermes/patch-api-mcp-refresh.py b/platform/hermes/patch-api-mcp-refresh.py new file mode 100644 index 0000000..bab68f0 --- /dev/null +++ b/platform/hermes/patch-api-mcp-refresh.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""Apply the upstream Hermes API-server MCP refresh workaround. + +Hermes 0.20.5 creates an API-server AIAgent without rebuilding its tool +snapshot from the live MCP registry. Healthy MCP servers that finish +discovery after process startup are therefore invisible through the OpenAI +compatible API even though ``hermes mcp test`` can reach them. + +This startup patch is deliberately small and fail-closed: it accepts either +the pristine upstream source or an already patched source, and refuses to +modify an unknown future implementation. +""" + +from pathlib import Path + + +TARGET = Path("/opt/hermes/gateway/platforms/api_server.py") +ANCHOR = " agent = AIAgent(**agent_kwargs)\n" +PATCHED = """ # Athena workaround for upstream issue #69746: the API platform + # otherwise snapshots tools before the live MCP registry is attached. + agent = AIAgent(**agent_kwargs) + try: + from tools.mcp_tool import refresh_agent_mcp_tools + + refresh_agent_mcp_tools(agent, quiet_mode=True) + except Exception: + logger.warning( + "api_server failed to refresh the live MCP tool registry", + exc_info=True, + ) +""" + + +source = TARGET.read_text(encoding="utf-8") +if PATCHED in source: + print("Hermes API MCP refresh patch already present") +elif source.count(ANCHOR) == 1: + TARGET.write_text(source.replace(ANCHOR, PATCHED, 1), encoding="utf-8") + print("Applied Hermes API MCP refresh patch") +else: + raise SystemExit( + "HERMES_START_REFUSED: upstream api_server.py changed; " + "review the MCP refresh patch before upgrading" + ) diff --git a/platform/hermes/start-hermes-managed.sh b/platform/hermes/start-hermes-managed.sh index ba8b2cb..1d4c638 100755 --- a/platform/hermes/start-hermes-managed.sh +++ b/platform/hermes/start-hermes-managed.sh @@ -67,4 +67,8 @@ grep -Eq '^[[:space:]]+base_url:[[:space:]]+["'\'']?http://router:8081/v1["'\''] exit 78 } +# Hermes 0.20.5 does not refresh the API agent from the live MCP registry. +# Apply the narrow, version-checked workaround before starting the gateway. +python /usr/local/lib/mike-ai/patch-api-mcp-refresh.py + exec hermes gateway run