Skip to content

The agent that grows with you

fix(webhook): give MCP event runs the whole payload

emozillaee6d894698d2
diff --git a/gateway/platforms/webhook.py b/gateway/platforms/webhook.py
index 13952756cfc..6745c9c35a8 100644
--- a/gateway/platforms/webhook.py
+++ b/gateway/platforms/webhook.py
@@ -41,7 +41,8 @@ from gateway.platforms.event import MessageEvent, MessageType
from gateway.platforms.tcp_site import start_tcp_site
from gateway.platforms.webhook_coalesce import WebhookCoalescer, validate_coalesce_config
from gateway.platforms.webhook_filters import DEFAULT_SCRIPT_TIMEOUT_SECONDS, WebhookRouteProcessor
-from gateway.platforms.webhook_mcp_events import handle_mcp_event_control, mcp_event_delivery_id
+from gateway.platforms.webhook_mcp_events import (
+ handle_mcp_event_control, mcp_event_delivery_id, render_mcp_event_prompt)
from gateway.response_filters import is_autonomous_silence_response
logger = logging.getLogger(__name__)
@@ -694,7 +695,8 @@ class WebhookAdapter(BasePlatformAdapter):
logger.info("[webhook] script ignored event=%s route=%s", event_type, route_name)
return web.json_response({"status": "ignored", "reason": "script", "route": route_name})
payload = transformed_payload or payload
- prompt = self._render_prompt(route_config.get("prompt", ""), payload, event_type, route_name)
+ prompt = (render_mcp_event_prompt(self, route_config, payload, event_type, route_name)
+ or self._render_prompt(route_config.get("prompt", ""), payload, event_type, route_name))
# cron_job routes: the job's own skills apply; the rendered prompt is only per-run context.
if (skills := route_config.get("skills", [])) and not route_config.get("cron_job"):
prompt = self._apply_skills(prompt, skills)
diff --git a/gateway/platforms/webhook_mcp_events.py b/gateway/platforms/webhook_mcp_events.py
index 0c112834c11..2d3865d5637 100644
--- a/gateway/platforms/webhook_mcp_events.py
+++ b/gateway/platforms/webhook_mcp_events.py
@@ -5,6 +5,7 @@ route pipeline, keyed for idempotency by its ``eventId``. Signatures (Standard W
are already verified by the adapter before any of this runs."""
import asyncio
+import json
import logging
from typing import Any, Optional
@@ -12,6 +13,7 @@ logger = logging.getLogger(__name__)
_MAX_CHALLENGE_CHARS = 512
_MAX_NOTICE_DETAIL_CHARS = 200
+_MAX_EVENT_DATA_CHARS = 32_000
def _json(body: dict, status: int = 200):
@@ -24,6 +26,25 @@ def _mcp_event(route_config: dict) -> Optional[dict]:
return event if isinstance(event, dict) else None
+def render_mcp_event_prompt(adapter, route_config: dict, payload: Any, event_type: str,
+ route_name: str) -> Optional[str]:
+ """The prompt for an occurrence on an MCP event route whose template uses ``{data}``; None otherwise.
+ ``{data}`` takes the whole payload (up to ``_MAX_EVENT_DATA_CHARS``, with a note when cut) instead of
+ the 2,000-character cap other placeholders get, and the JSON goes in after the rest of the template
+ renders, so text inside the payload is never read as a placeholder."""
+ if _mcp_event(route_config) is None or not isinstance(payload, dict):
+ return None
+ template = route_config.get("prompt")
+ if not isinstance(template, str) or "{data}" not in template:
+ return None
+ data = json.dumps(payload.get("data"), indent=2, ensure_ascii=False)
+ if len(data) > _MAX_EVENT_DATA_CHARS:
+ data = (f"{data[:_MAX_EVENT_DATA_CHARS]}\n[truncated: the first {_MAX_EVENT_DATA_CHARS:,} of "
+ f"{len(data):,} characters]")
+ return data.join(adapter._render_prompt(part, payload, event_type, route_name) if part else ""
+ for part in template.split("{data}"))
+
+
def mcp_event_delivery_id(route_config: dict, payload: Any) -> Optional[str]:
"""``eventId`` is the sketch's dedup key (stable across retries and redeliveries), unlike the
per-attempt ``webhook-id``."""
diff --git a/tests/gateway/test_webhook_mcp_events.py b/tests/gateway/test_webhook_mcp_events.py
index 013a6679a6a..aa61939c789 100644
--- a/tests/gateway/test_webhook_mcp_events.py
+++ b/tests/gateway/test_webhook_mcp_events.py
@@ -147,3 +147,21 @@ async def test_an_unknown_control_envelope_is_acknowledged_without_a_run(home):
assert odd.status == 200
adapter.handle_message.assert_not_called()
+
+async def test_the_event_payload_reaches_the_prompt_whole(home):
+ from tools.mcp_tool_events import _event_prompt
+ routes = _routes(home)
+ routes[ROUTE]["prompt"] = _event_prompt("ambush", "feed.emission.created", "Explain it.")
+ (home / "webhook_subscriptions.json").write_text(json.dumps(routes))
+ adapter = _adapter()
+ text = "b" * 10_000
+ occurrence = {"name": "feed.emission.created", "timestamp": "2026-10-16T00:00:00Z", "cursor": None}
+ async with TestClient(TestServer(_app(adapter))) as cli:
+ assert (await _post(cli, {**occurrence, "eventId": "e-big",
+ "data": {"text": text, "note": "{eventId}"}})).status == 202
+ assert (await _post(cli, {**occurrence, "eventId": "e-huge", "data": {"text": "h" * 50_000}})).status == 202
+ big, huge = (call.args[0].text for call in adapter.handle_message.await_args_list)
+ assert text in big and big.endswith("Explain it.")
+ assert '"note": "{eventId}"' in big # payload text is never read as a placeholder
+ assert "truncated" in huge and len(huge) < 40_000
diff --git a/website/docs/user-guide/features/mcp.md b/website/docs/user-guide/features/mcp.md
index 6e45cdb9d84..9e1ed8da99e 100644
--- a/website/docs/user-guide/features/mcp.md
+++ b/website/docs/user-guide/features/mcp.md
@@ -1040,7 +1040,8 @@ for good (access revoked, event type removed, arguments no longer valid) removes
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 same
+`hermes gateway run` is running. The event payload reaches the run whole, up to 32,000 characters
+of JSON, with a note when it is cut. Event payloads are external data: event runs use the same
constrained webhook toolset as other webhook routes.
The listener's per-route rate limit (`platforms.webhook.extra.rate_limit`, 30 a minute by default)
applies to event deliveries too; raise it for a busy event type, since a server may not retry a