The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp): let a disabled event route lapse
emozillaf9fda2369d56
diff --git a/tests/tools/test_mcp_events.py b/tests/tools/test_mcp_events.pyindex b5f9e41f702..fb916d2413d 100644--- a/tests/tools/test_mcp_events.py+++ b/tests/tools/test_mcp_events.py@@ -134,6 +134,16 @@ class TestSubscribe:assert "public_url" in _subscribe(session)["error"]assert session.sent == [] and _routes(home) == {}+ def test_a_disabled_subscription_is_not_turned_back_on(self, home):+ _subscribe(FakeSession(_grant()))+ data = _routes(home)+ (name, route), = data.items()+ route["enabled"] = False+ (home / "webhook_subscriptions.json").write_text(json.dumps(data))+ session = FakeSession()+ assert "error" in _subscribe(session)+ assert session.sent == [] and _routes(home)[name]["enabled"] is False+class TestUnsubscribe:def test_unsubscribe_sends_the_granted_url_and_drops_the_route(self, home):@@ -192,6 +202,15 @@ class TestRefresh:next_due = asyncio.run(events.refresh_server_subscriptions(_server(session), force=False, failures=failures))assert session.sent == [] and 100 < next_due - time.time() <= 4 * events._REFRESH_MIN_SLEEP_S+ def test_a_disabled_route_is_left_to_lapse(self, home):+ _subscribe(FakeSession(_grant()))+ data = _routes(home)+ next(iter(data.values()))["enabled"] = False+ (home / "webhook_subscriptions.json").write_text(json.dumps(data))+ session = FakeSession()+ asyncio.run(events.refresh_server_subscriptions(_server(session), force=True))+ assert session.sent == []+def test_a_new_subscription_wakes_the_refresh_loop(self, home, monkeypatch):passes = []diff --git a/tools/mcp_tool_events.py b/tools/mcp_tool_events.pyindex 7c0350f0708..b2abdde9b6c 100644--- a/tools/mcp_tool_events.py+++ b/tools/mcp_tool_events.py@@ -224,9 +224,9 @@ def _wake_refresh_loops(server_name: str) -> None:async def refresh_server_subscriptions(server, *, force: bool,failures: Optional[dict[str, tuple[int, float]]] = None) -> float:"""Re-subscribe this server's routes that are due (all of them when *force*, i.e. on a fresh- connection, where the server may have lost soft state). A failed refresh is retried with exponential- back-off: *failures* maps a route to (consecutive failures, retry time) across passes. Returns the next- due time."""+ connection, where the server may have lost soft state). A route disabled in the dashboard is left to+ lapse; turning it back on resubscribes it. A failed refresh is retried with exponential back-off:+ *failures* maps a route to (consecutive failures, retry time) across passes. Returns the next due time."""failures = {} if failures is None else failuresurl_base = _callback_base()routes = await asyncio.to_thread(_load_routes, server.name)@@ -242,7 +242,7 @@ async def refresh_server_subscriptions(server, *, force: bool,# Re-read under the lock: an unsubscribe that ran while we waited must not be undone.route = (await asyncio.to_thread(_load_routes, server.name)).get(route_name)stored = None- if route is not None:+ if route is not None and route.get("enabled", True) is not False:stored = await _subscribe_route(server.session, route_name, route, url_base)if stored is None:failures.pop(route_name, None)@@ -313,7 +313,8 @@ async def _list_events(session, args: dict, server_name: str) -> dict:routes = await asyncio.to_thread(_load_routes, server_name)states = await asyncio.to_thread(_load_state)subscribed = [{"name": r["mcp_event"]["name"], "arguments": r["mcp_event"]["arguments"],- "deliver": r.get("deliver", "log"), "refreshBefore": states.get(n, {}).get("refresh_before")}+ "deliver": r.get("deliver", "log"), "refreshBefore": states.get(n, {}).get("refresh_before"),+ **({"enabled": False} if r.get("enabled", True) is False else {})}for n, r in routes.items()]return {"events": events, "subscriptions": subscribed}@@ -326,6 +327,10 @@ async def _subscribe_event(session, args: dict, server_name: str) -> dict:arguments = args.get("arguments") or {}route_name = _route_name(server_name, args["name"], arguments)existing = (await asyncio.to_thread(_load_routes, server_name)).get(route_name)+ if existing is not None and existing.get("enabled", True) is False:+ # Only the dashboard's enable action turns a route back on (same rule as hermes_cli.webhook).+ return {"error": f"The subscription to '{args['name']}' with these arguments is turned off in the "+ "webhook dashboard. Turn it back on there to resume it."}deliver_extra = {"chat_id": args["deliver_chat_id"]} if args.get("deliver_chat_id") else {}# The route is the subscription's fixed contract: an admitted run's reply is checked against a digest# of it, so nothing that changes while the subscription lives (grant, cursor) is stored here, and andiff --git a/website/docs/user-guide/features/mcp.md b/website/docs/user-guide/features/mcp.mdindex f90c0881203..6e45cdb9d84 100644--- a/website/docs/user-guide/features/mcp.md+++ b/website/docs/user-guide/features/mcp.md@@ -1037,7 +1037,8 @@ instructions or a different destination. Hermes answers the server's signed verievents by `eventId`, and refreshes the subscription before the lifetime the server granted runs outwhile the MCP connection is up (and again whenever it reconnects). A refresh the server refusesfor good (access revoked, event type removed, arguments no longer valid) removes the route; other-failures are retried with back-off. If the server ends a subscription,+failures are retried with back-off. Turning the route off in the webhook dashboard lets the+subscription lapse, and turning it back on resubscribes it. If the server ends a subscription,Hermes removes the route and tells the `deliver` target. Events only arrive while`hermes gateway run` is running. Event payloads are external data: event runs use the sameconstrained webhook toolset as other webhook routes.