Refresh MCP tools in Hermes API agents
This commit is contained in:
@@ -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}"]
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user