Skip to content

feat: per-message webhook-id for SEP-3415 clients, eventId for legacy ones - #114

Merged
leggetter merged 4 commits into
mainfrom
feat/113-webhook-id-mode
Nov 13, 2026
Merged

leggetter merged 4 commits into
mainfrom
feat/113-webhook-id-mode

Conversation

@leggetter

@leggetter leggetter commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #113.

SEP-3415 now requires each delivery's webhook-id to be a per-message id, unique to one event on one subscription, kept across retries, and never derived from eventId. The bridge has always sent the eventId, and TanStack AI, the Vercel AI SDK and OpenClaw reject anything else. This PR picks the format per subscription.

What changes

  • Two formats. event-id: webhook-id is the event's eventId, as today. per-message: msg_ plus 24 random characters, the same on every retry of that delivery.
  • auto (the default) chooses per subscription, at every subscribe and refresh:
    • per-message when the client declares io.modelcontextprotocol/events in the request's _meta (io.modelcontextprotocol/clientCapabilities). The MCP SDK moves that envelope to ctx.mcpReq.envelope, so the subscribe handler reads it from there.
    • event-id for any client that doesn't declare it, and for a legacy list of client names: tanstack-ai-mcp, ai-sdk-mcp-client and openclaw. TanStack AI declares the extension whenever events are on, and still rejects a per-message id, so the declaration alone isn't enough.
  • BRIDGE_WEBHOOK_ID_FORMAT (subscriptions.webhookIdFormat): auto, event-id or per-message. A fixed value applies to every subscription, for example event-id when one of those clients runs under a name of its own.
  • Where it's stored: "wid":"msg" in the subscription's connection description, which the transformation reads. Replays publish with the same rule.
  • Dedupe moves from headers.webhook-id to body.eventId, on subscription and replay connections. A service resending an event runs the transformation again, which gives a new random id, so dedupe on the header would let the repeat through. It's the same as before for event-id subscriptions. Existing subscriptions take the new rule at their next refresh.
  • An event id with a period is delivered with per-message, rather than skipped.
  • serve logs the choice after each subscribe: <subscription id>: webhook-id per message (client "<name>" declares io.modelcontextprotocol/events) or <subscription id>: webhook-id is the eventId (...).

Verified

  • Event Gateway keeps a generated id across retries (live, 13 Nov). A transformation set a random webhook-id with crypto.getRandomValues. The initial attempt, two automatic retries and a manual retry all carried the same id, each with a fresh timestamp and signature. The transformation runs once per event. All spike-113 resources are deleted.
  • Dedupe on a body field the transformation sets drops a repeated request as DUPLICATE, even though its random webhook-id differed.
  • The clients' declarations were read from source, not run: TanStack AI (@tanstack/ai-mcp 1.2.0), the AI SDK (@ai-sdk/mcp 2.0.99) and OpenClaw (v2026.11.3). A bridge test with the MCP TypeScript SDK client confirms that a declared capability and the client name reach the subscribe handler.

Details are in docs/SPIKES.md, "Per-message webhook-id (#113)", and docs/ARCHITECTURE.md, "Which webhook-id".

Known limits

  • A renamed client isn't caught: a TanStack AI or AI SDK application that sets its own client name and declares the extension gets per-message, and its receiver answers 400. The README troubleshooting table and the skill say to set BRIDGE_WEBHOOK_ID_FORMAT=event-id.
  • The id is random, not a hash of subscription and eventId, because the SEP forbids deriving it from eventId. So with per-message, an event's live delivery and its replay have different ids; receivers dedupe on eventId for that overlap.
  • Replay publishing is covered by a unit test of the id helper, not by a test that runs a replay through the bridge.

Tests

npm test: 461 pass, with new tests for both formats in the transformation, the store (including the description size limit), the config, the format choice, migration, and end to end through the SDK client (test/host/bridge.test.ts), including a refresh that switches format.

An independent review found no correctness bugs; its three low-severity findings are fixed in the last commit: the size check counted wid for every subscription, and the subscribe log didn't say when the legacy list or the operator setting chose the format. npm run typecheck and npm run build are clean.

🤖 Generated with Claude Code

Posted by an AI agent with human oversight.

leggetter and others added 4 commits November 13, 2026 13:06
… ones

Each subscription now records which webhook-id its deliveries carry, chosen at
subscribe time:

- event: the eventId, as before. Clients that don't declare the events
  extension get it, as do declaring clients on a legacy list (TanStack AI, the
  Vercel AI SDK and OpenClaw by their default names), which reject a
  webhook-id that isn't the eventId.
- message: msg_ plus 24 random characters, as SEP-3415 requires, for a client
  that declares io.modelcontextprotocol/events in the request's _meta.

BRIDGE_WEBHOOK_ID (subscriptions.webhookId) sets auto (default), event or
message. The mode is stored as wid in the connection description, where the
transformation reads it; replays publish with the same rule. Event Gateway
runs the transformation once per event, so retries keep a generated id
(verified). Dedupe moves from headers.webhook-id to body.eventId, so a
service's resend is still dropped when the id is random.

Refs #113

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ll and changelog

Refs #113

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, event-id and per-message

BRIDGE_WEBHOOK_ID read as if it held an id. The setting picks what each
delivery's webhook-id header holds, so it's now BRIDGE_WEBHOOK_ID_FORMAT
(subscriptions.webhookIdFormat), with auto (the default), event-id and
per-message.

Refs #113

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The description size check counts wid only for a per-message subscription, so an event-id subscription keeps the room it had.
- The subscribe log says when the legacy client list chose event-id, and names both places the format setting can come from.
- BRIDGE_WEBHOOK_ID_FORMAT values are read in any case.
- Tests: a refresh switching format, the size limit with wid, migration giving event-id, and the operator setting in the log.

Refs #113

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leggetter
leggetter merged commit 05ca182 into main Nov 13, 2026
2 checks passed
@leggetter
leggetter deleted the feat/113-webhook-id-mode branch November 13, 2026 18:36
@leggetter leggetter mentioned this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send a per-message webhook-id to SEP-3415 clients, and keep eventId for legacy ones

1 participant