Webhook ingestion: register a webhook as an MCP resource
Connectors are pull-only today. Several of the shipped adapters (Shopware, Billbee, Stripe, WhatsApp) have webhooks that would let an agent react to something happening instead of polling for it.
Scope
- A per-connector inbound webhook URL with a shared secret.
- Received events stored with a retention window, exposed as MCP resources.
- Response mapping applies on the way out, same as tool responses.
Design question first: MCP resources or a *_recent_events tool? Resources are the correct primitive; tool support is more widely implemented across clients today. Comments welcome.
Design decisions (from the discussion below)
- A
*_recent_eventstool first; a resource view over the same store can come later. - Retention: a periodic
setIntervalsweep in core (like the existing auth-status, audit and session sweeps) plus a per-connector row cap on insert. Noee/code, same behaviour on Cloud and self-hosted. - Verification per provider (Stripe-Signature with replay window; Meta verify-token handshake + X-Hub-Signature-256), generic HMAC/shared secret only as a fallback. Nothing is stored before verification.
- Ingress fails closed: its own rate limiter with an in-memory fallback when Redis is absent, a small body size limit, and the same response for unknown connectors as for bad signatures.
@helpcodeai just sharing how I read this, not proposing to build it — let me know if I'm off anywhere.
Resources vs. *_recent_events tool:
- Resources — Advantage: these are genuinely readable, static-ish data once received, so conceptually they fit the primitive. Disadvantage:
McpResourcetoday is one static row per URI, andplanServerResources()lists every row with no pagination and silently withholds anything with a duplicate URI. A live feed doesn't fit that — either synthesize a resource row per event (unbounded growth, no pagination, nothing to clean old ones up) or bolt on a single aggregating resource that behaves nothing like any other one in the system. - Tool — Advantage: fits the existing tool-response pipeline as-is (pagination params, response mapping, size caps already exist for tools), and works across more MCP clients today, as the issue itself says. Disadvantage: loses the "just shows up in
resources/list" discoverability a true resource would give.
My read: the tool fits the current code better even though resources is the "purer" primitive.
Retention window:
- Advantage of delete-on-insert (trim old rows whenever a new event lands): no new infrastructure, works identically on Cloud and self-hosted.
- Disadvantage: the only
@Cronjob anywhere iskg-cron.service.tsunderee/cloud, which is commercial-licensed, so this can't be reused, and self-hosted has no scheduler at all today. Adding a real scheduler dependency instead would be a bigger call, since it'd be the first of its kind in the open-source core.
Shared secret:
- Advantage of one generic shared-secret field: simplest possible model, same UI/config for every adapter.
- Disadvantage: it would under-verify several of the adapters actually named. Stripe signs with
Stripe-Signature(HMAC-SHA256 + timestamp, replay window); WhatsApp Business does a GET handshake with a verify token plusX-Hub-Signature-256on POST. Neither is just "compare a bearer secret," so a single shared-secret check wouldn't really authenticate either one correctly.
Public ingress:
- Advantage: reusing
McpRateLimitGuardwould be the least new code. - Disadvantage: it falls back to allow-all when Redis isn't configured — fine for the authenticated MCP endpoint, but this would be a new public, unauthenticated-until-verified POST endpoint anyone on the internet can hit, so inheriting that fallback feels like the wrong default here.
Thanks @rangarajan19, this is a careful read and it matches the code. Our current thinking, point by point:
Resources vs. tool: agreed, the tool comes first. McpResource is one static row per URI, and planServerResources() withholds duplicate URIs and has no pagination, so it can't carry a live feed. A *_recent_events tool reuses what tools already have: response mapping, size caps and pagination arguments. A resource can come later as a thin view over the same store (for example one resource template per connector) once that's worth it.
Retention: one correction. The open-source core already runs periodic jobs without @Cron: setInterval sweeps in connector-auth-status.service.ts, audit.service.ts and mcp-session.manager.ts. So a retention sweep can live in core on both Cloud and self-hosted, with no ee/ code and no new scheduler dependency. We'd combine it with a per-connector row cap enforced on insert, so storage stays bounded even between sweeps.
Verification: agreed, a single shared secret isn't enough. Verification would be per provider: Stripe's Stripe-Signature (HMAC plus timestamp, with a replay window), and Meta's GET verify-token handshake plus X-Hub-Signature-256. A generic HMAC or shared-secret check would remain only as the fallback for providers without a scheme of their own. Nothing is stored before the signature checks out.
Public ingress: agreed, this endpoint must fail closed. It gets its own limiter that falls back to an in-memory window when Redis is absent, instead of McpRateLimitGuard's allow-all. Also a small body size limit, and unknown or disabled connectors answered with the same response as a bad signature.
Before any code, I'll fold these points into the issue description.
@helpcodeai , happy to help if you need anything
Thanks @rangarajan19! The decisions from this thread are now in the issue description.
If you want to build the first part, it is welcome. That would be the inbound endpoint with Stripe signature checks, and the *_recent_events tool that reads the stored events. Just say so here and I'll assign it to you.
It needs a new table for the events, so please post the Prisma model in this issue first, before writing the rest. Then we can agree on it early and the PR stays small.
@helpcodeai I'd like to work on this — the inbound endpoint with Stripe signature checks plus the *_recent_events tool. Here's the Prisma model and the shape of that first slice, before writing anything else, per your ask.
I validated the model against the real schema (prisma validate with the new model and the back-relations added) and tested the signature-verification logic against real computed HMAC vectors (valid signature, wrong secret, tampered body, stale timestamp, malformed header) before writing this up, so this isn't just untested theory.
Prisma model
model WebhookEvent {
id String @id @default(cuid())
connectorId String @map("connector_id")
connector Connector @relation(fields: [connectorId], references: [id], onDelete: Cascade)
organizationId String @map("organization_id")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
// Which verifier matched: 'stripe' now, 'meta' / 'generic' later.
provider String
// Provider's own event type where it has one (e.g. payment_intent.succeeded).
eventType String? @map("event_type")
// Provider's own event id, for de-dup on redelivery. Null for schemes with none.
externalId String? @map("external_id")
// Verified body only. Nothing lands here before the signature checks out.
payload Json
receivedAt DateTime @default(now()) @map("received_at")
@@unique([connectorId, externalId])
@@index([connectorId, receivedAt])
@@index([organizationId, receivedAt])
@@map("webhook_events")
}
externalId nullable under a unique constraint is fine on Postgres (NULLs don't collide), so providers with no event id just skip dedup.
Connector gets three new nullable columns rather than a second config table: webhookEnabled Boolean @default(false), webhookProvider String?, webhookSecret String? (encrypted the same way authConfig is today, same encrypt/decrypt helpers, no AAD, matching the existing convention).
Endpoint
POST /api/webhooks/:connectorId, new controller outside ee/. Looked up ConnectorType.WEBHOOK to see if this should live there — it's in the enum but has no execution engine; dynamic-mcp-tools.ts's dispatch throws Unsupported connector type for it today. Reading it as reserved for something else (outbound-call-shaped tools), not inbound receiving, so this is a capability any connector opts into, not a new connector type.
- Raw bytes:
main.tsalready capturesreq.rawBodyfor/api/support/webhookspecifically, for the same reason Stripe needs it (HMAC over the exact bytes sent). Adding/api/webhooks/to that same check. - Verification: Stripe's
Stripe-Signature(HMAC-SHA256 overtimestamp.body, reject if the timestamp is outside a tolerance window) plus a generic HMAC fallback for adapters with no named scheme. Meta's GET-handshake-plus-X-Hub-Signature-256left for a follow-up, as you scoped it. - Same response for an unknown connector ID, a disabled one, and a bad signature — no oracle for probing which IDs exist.
- Rate limiting:
@Throttle()on the route, same asauth/connect/*already does —ThrottlerModuleis already global and in-memory (no Redis storage configured anywhere), so this needs no new infrastructure, just the decorator. - Body size: a smaller cap than the global 10 MB, checked before the signature check runs.
- Idempotency:
@@unique([connectorId, externalId])catches Stripe's at-least-once redelivery.
Tool
<adapter>_recent_events, reading WebhookEvent ordered by receivedAt desc, with limit/since params. Goes through the existing tool pipeline (response mapping, size caps) like every other tool — no new pipeline needed there.
Retention
A setInterval sweep in core, same shape as ConnectorAuthStatusService's (setTimeout first run, then setInterval, both .unref()'d, cleared in onModuleDestroy) — deletes rows past the window. Paired with a cap enforced on insert (delete the oldest for that connector past N rows) so storage stays bounded between sweeps even under a burst.
Let me know if any of this should change, and I'll get started once the model looks right to you.
@rangarajan19 thanks, this is a solid first slice and the model is fine. Go ahead, I am assigning you. A few points so the PR stays small and passes review:
WebhookEventas posted is good. KeeporganizationIdon the row and filter every read by it, as everywhere else in the code base. Add@@index([connectorId, externalId])only if the unique does not already cover your lookups (it does).- The three nullable columns on
Connectorare fine. EncryptwebhookSecretwith the same helpers asauthConfig, and never return it from any API or tool response. - Endpoint
POST /api/webhooks/:connectorIdoutsideee/, same response for unknown id, disabled hook and bad signature, body cap below the global 10 MB checked before the HMAC,@Throttle()on the route. All as you wrote. - Stripe first. Leave the generic HMAC fallback out of the first PR, it needs its own design (header name, encoding, replay window) and doubles the test surface. One verifier, well tested, is enough to merge.
- Tool
<adapter>_recent_eventswithlimitandsince, read-only, through the normal tool pipeline. - Retention: the interval sweep plus the per-connector cap on insert is right. Make both numbers configurable with sane defaults and document them.
- Include the Prisma migration in the PR and a short note on how it behaves on Cloud and self-hosted (same code path, no difference expected).
- Tests: unit tests for the signature check with your vectors (valid, wrong secret, tampered body, stale timestamp, malformed header), one e2e for the endpoint and one for the tool.
Post the PR as a draft early if you want a first look.
@helpcodeai PR is up: #1372
Thanks again @rangarajan19. #1372 is merged, so webhook ingestion is on main. I am closing this issue. The open points on our side (Cloud plan limits and a dashboard UI) continue in #1393.