Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- **Arguments that don't match an event's inputSchema say what's wrong:** `poll_events` and `wait_for_event` returned only "arguments do not match the inputSchema", dropping the protocol error's `data.detail`, so an agent couldn't tell which argument was wrong (seen on 5 Nov: Claude Code passed `action` for `github.issues`, whose filter is `actions`, a list, then dropped the filter). The tool error now includes the detail, which names the unknown or wrong argument and lists the event's arguments: `arguments do not match the inputSchema: unknown argument "action". github.issues takes repository (string), actions (string[]), sender (string)`. `events/poll` and `events/subscribe` return the same `data.detail`, which was the validator's raw JSON, and `watch` and `watches add` print it. Unknown arguments were already refused, not ignored.
- **Poll tools on a bridge with no subscriptions:** `wait_for_event`, `poll_events`, `events/poll`, `watch`, `get_event` and `list_events` returned no events until something subscribed. A source has a connection only per subscription, and Event Gateway rejects requests to a source with no connection as `NO_CONNECTION` (the sender still gets `200`, and the request is kept); the bridge listed only accepted requests. It now also reads verified requests rejected as `NO_CONNECTION`. Broken since 0.8.0.
- **`setup` registers again a webhook deleted at the service:** on a re-run with nothing changed, it reported `webhook existing` for a Resend or GitHub source whose webhook had been deleted at the service, so no events arrived. It now checks the saved webhook (Resend's webhook by its id; GitHub's in each repository, or the organization, by the source URL) and, if it's missing, logs `the <service> webhook saved on bridge-<id> is missing at <service>; registering it again` and reports `registered`. If it can't check (a key or token that can't read webhooks, or the service didn't answer), it keeps the saved webhook, reports `existing`, and logs a warning. Sources defined with `defineSource` can opt in with an optional `webhookExists`.

## 0.9.0 (2026-11-05)

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ You need:
npx mcp-events-bridge setup
```

The first run generates an MCP secret: add it to `.env` as `BRIDGE_MCP_SECRET`. Setup is safe to re-run, and updates the webhooks when you add sources or change events or repositories. Removing a source or a repository deletes nothing: delete its webhook (and its Event Gateway source) yourself. Upgrading from 0.7, setup offers to migrate your subscriptions: see [`docs/UPGRADING.md`](docs/UPGRADING.md).
The first run generates an MCP secret: add it to `.env` as `BRIDGE_MCP_SECRET`. Setup is safe to re-run, and updates the webhooks when you add sources or change events or repositories. A Resend or GitHub webhook deleted at the service is registered again. Removing a source or a repository deletes nothing: delete its webhook (and its Event Gateway source) yourself. Upgrading from 0.7, setup offers to migrate your subscriptions: see [`docs/UPGRADING.md`](docs/UPGRADING.md).

5. **Run the bridge:**

Expand Down Expand Up @@ -488,6 +488,8 @@ Three TypeScript MCP client libraries have experimental MCP Events support, and
| ``Config: `providers` in the config is now `sources` ...`` (or another name "removed in 0.8.0") | A name deprecated in 0.6.0 | Rename it as the message says |
| `serve` logs `subscription ... is for "...", which this bridge doesn't offer` | The source was removed, its `id` renamed, or the subscription is from 0.1.0 (before `{id}.{event}` names); or it belongs to another bridge in the same Hookdeck project | The agent subscribes again, to a name from `events/list`; ignore another bridge's |
| `events/subscribe` fails with "Unknown event" | An old or wrong name | Use a name from `events/list` |
| No events from Resend or GitHub reach the source | The webhook was deleted at the service | Run `setup` again: it checks the saved webhook, and registers it again if it's missing |
| `setup` logs `warning: could not confirm the <service> webhook saved on bridge-<id> still exists` | The API key or token can't read webhooks, or the service didn't answer | Setup kept the saved webhook. Fix the key or token (GitHub: Webhooks permission) and run `setup` again |
| A sender gets 401 | Wrong signature, header, encoding or secret | Match the source's `verification` or secret; a new secret can take about a minute to apply |
| An agent doesn't get an event | The subscription's filter didn't match, the event type isn't enabled, or the callback is failing | In the Event Gateway dashboard, the subscription's connection, `mcp-sub-<id>`, shows each request: `FILTERED` for a filter or an event type it doesn't offer, or the failed attempts. `list_sources` shows each source's events and subscriptions |
| `serve` logs `warning: <name> is a pass-through callback URL` | A subscription uses a callback URL created without a secret | Expected for Hermes Agent and the client libraries; the receiver must verify every delivery |
Expand Down
3 changes: 2 additions & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ const resend = defineSource({
runtimeConfig: undefined, // JSON, passed to the runtime
register?(ctx): Promise<{ webhookId: string; signingSecret: string }>,
unregister?(ctx): Promise<void>,
webhookExists?(ctx): Promise<boolean>, // on a re-run with nothing changed: false re-registers, a rejection keeps it and warns
sourceConfig?(options), missingCredentials?(options), setupHint?(ctx), ...
});

Expand Down Expand Up @@ -673,7 +674,7 @@ GitHub has about 70 webhook event types, most with several actions, and payloads
- **Scope:** a list of repositories (`{ repos: ['owner/name', ...] }`) or an organization (`{ org: 'name' }`). Personal accounts have no account-wide webhooks, and organization webhooks need an org admin, so the list is the common case. Every repository's webhook points at the same `GITHUB` source with the same secret; the payload names the repository, and subscribers filter on it.
- **Secret:** GitHub lets the caller choose it, so `register()` generates one and sets it on the source, which verifies `X-Hub-Signature-256`.
- **Manual mode:** `github({ webhookSecret })`, with no token or scope. Setup creates the source with that secret and prints the source URL; you add webhooks to any repositories yourself. Only deliveries signed with the secret get past Event Gateway, so "any repository" means any repository you configured. A GitHub App would make this automatic across installations; that's later.
- **No ids stored:** the bridge finds its webhooks by URL (the source URL), so it doesn't keep an id per repository in the 500-character source description. Registering updates a webhook in place if one already delivers to the source, so re-running after a partial failure doesn't duplicate webhooks.
- **No ids stored:** the bridge finds its webhooks by URL (the source URL), so it doesn't keep an id per repository in the 500-character source description. Registering updates a webhook in place if one already delivers to the source, so re-running after a partial failure doesn't duplicate webhooks. On a re-run with nothing changed, setup lists each repository's (or the organization's) webhooks: if one has none delivering to the source URL (deleted on GitHub), it registers again, reusing the source's secret, so the other repositories' webhooks keep verifying.
- **Changing the list:** setup keeps a fingerprint of the repositories and the enabled events in the source description. When either changes, it updates the webhooks and reuses the source's secret, so deliveries in flight still verify. Removing a repository from the list leaves its webhook in place; delete it in the repository's settings, or its events keep arriving (subscribers filtering by repository won't see them).
- **Event id:** `X-GitHub-Delivery`, so also the `webhook-id` each subscription's connection dedupes on. **Occurred-at:** the main object's latest timestamp, else the push's head commit, else the time received. The `ping` sent when a webhook is created matches no event and is ignored.

Expand Down
4 changes: 3 additions & 1 deletion skills/mcp-events-bridge/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Write `.env` with `HOOKDECK_API_KEY`, `HOOKDECK_SIGNING_SECRET` and each source'
npx mcp-events-bridge setup
```

- **Success:** a line per source (`source resend: https://hkdk.events/..., transformation bridge-resend-envelope, webhook registered`; on a re-run, `updated` or `existing`), then the MCP endpoint. Exit code 0. With a local bridge it also logs the Hookdeck CLI in to the bridge's project in `.hookdeck/config.toml`, so `hookdeck` commands run in this directory use that project.
- **Success:** a line per source (`source resend: https://hkdk.events/..., transformation bridge-resend-envelope, webhook registered`; on a re-run, `updated` or `existing`, or `registered` again if the Resend or GitHub webhook was deleted at the service, after the log line `the <service> webhook saved on bridge-<id> is missing at <service>; registering it again`), then the MCP endpoint. Exit code 0. With a local bridge it also logs the Hookdeck CLI in to the bridge's project in `.hookdeck/config.toml`, so `hookdeck` commands run in this directory use that project.
- **First run:** it generates an MCP secret and prints a `BRIDGE_MCP_SECRET=...` line. Add that line to `.env` as printed. `setup` prints the full MCP URL, secret included, on every run: don't repeat it in your replies or write it anywhere but `.env`.
- **Exit code 1 with "Setup isn't complete":** a `source()`'s secret is missing (step 3). Everything else was set up.
- **Data from 0.7:** setup says "The bridge's data model in Event Gateway changed in 0.8" and asks `Migrate now? [Y/n]`. Answer `y`; it ends with `migrated <n> subscription(s) and <m> callback URL(s)`. Declining exits 1, and `serve` won't start until it's migrated.
Expand Down Expand Up @@ -115,6 +115,8 @@ Every event is named **`{source id}.{event}`**: the source `id` (by default its
| Log: `subscription ... is for "...", which this bridge doesn't offer` | The source was removed, its `id` renamed, or the subscription is from 0.1.0; or it belongs to another bridge in the same Hookdeck project | The agent subscribes again, to a name from `events/list`; ignore another bridge's |
| `events/subscribe` fails: "Unknown event" | Old or wrong name | Use a name from `events/list` |
| A sender gets 401 | Wrong signature, header, encoding or secret | Match the source's `verification` or secret; a new secret can take about a minute |
| No events from Resend or GitHub reach the source | The webhook was deleted at the service | Run `setup` again: it checks the saved webhook, and registers it again if it's missing |
| `setup` logs `warning: could not confirm the <service> webhook saved on bridge-<id> still exists` | The API key or token can't read webhooks, or the service didn't answer | Setup kept the saved webhook. Fix the key or token (GitHub: Webhooks permission) and run `setup` again |
| An agent doesn't get an event | Its filter or event type didn't match, or its callback is failing | Check the subscription's connection, `mcp-sub-<id>`, in the Event Gateway dashboard (`FILTERED`, or failed attempts), and its name and arguments |
| An event arrives after a minute or two | `hookdeck listen` occasionally takes ~30s to connect; Event Gateway occasionally queues a CLI delivery | Wait; missed deliveries are retried by the bridge |
| The same event twice | A retry, or a replay | Receivers dedupe by `webhook-id` |
Expand Down
34 changes: 29 additions & 5 deletions src/core/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { ensureTransformations } from './transformation.js';
* `setup`: creates or updates everything the config describes in Event Gateway and at services: each source, its
* webhook at the service, and the transformation its subscriptions share. Idempotent: a webhook is registered once
* and its id is kept in the source description, so re-running doesn't create another. If the enabled events or the
* registration target (for example GitHub repositories) change, the webhook is updated. Subscriptions themselves are
* registration target (for example GitHub repositories) change, the webhook is updated; if it was deleted at the
* service (for sources that can check, `webhookExists`), it's registered again. Subscriptions themselves are
* connections the bridge creates on each source when clients subscribe.
*/

Expand Down Expand Up @@ -129,6 +130,22 @@ export async function ensureSource(hookdeck: HookdeckClient, provider: ResolvedS
return { source, existing, configured, missing };
}

/**
* Whether the webhook saved in the source description is still at the service. True when the source can't check, and
* when the check fails for another reason than the webhook being gone (a key without read access, the network): setup
* then keeps the saved webhook, as before it checked, and warns.
*/
async function savedWebhookExists(deps: SetupDeps, provider: ResolvedSource, sourceUrl: string, webhookId: string, log: (message: string) => void) {
const { definition } = provider;
if (!definition.webhookExists) return true;
try {
return await definition.webhookExists({ webhookId, sourceUrl, options: provider.options, fetch: deps.fetch });
} catch (error) {
log(`warning: could not confirm the ${definition.displayName} webhook saved on ${providerSourceName(provider.id)} still exists, so keeping it: ${(error as Error).message}`);
return true;
}
}

async function setupProvider(deps: SetupDeps, provider: ResolvedSource) {
const { config, hookdeck } = deps;
const log = deps.log ?? (() => {});
Expand Down Expand Up @@ -164,10 +181,17 @@ async function setupProvider(deps: SetupDeps, provider: ResolvedSource) {
const changed =
!sameList(existing.events, provider.events) || existing.target !== target || (configured !== undefined && configured !== secret);
if (typeof secret === 'string' && secret) {
if (!changed) return report('existing');
log(`the ${definition.displayName} events, registration target or secret changed; updating the webhook`);
currentSecret = secret;
previousId = existing.webhookId;
if (!changed) {
if (await savedWebhookExists(deps, provider, source.url, existing.webhookId, log)) return report('existing');
// Deleted at the service: register it again, as on a first run. The source's secret is offered for reuse, so
// a service that lets the caller choose it (GitHub) keeps the one its other webhooks and Event Gateway have.
log(`the ${definition.displayName} webhook saved on ${sourceName} is missing at ${definition.displayName}; registering it again`);
currentSecret = secret;
} else {
log(`the ${definition.displayName} events, registration target or secret changed; updating the webhook`);
currentSecret = secret;
previousId = existing.webhookId;
}
} else {
// The source lost its signing secret: replace the provider webhook, since its secret can't be read back.
log(`${sourceName} has no signing secret; replacing the ${definition.displayName} webhook`);
Expand Down
14 changes: 14 additions & 0 deletions src/core/sources/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,18 @@ export const githubProvider: SourceDefinition<GithubOptions> = {
}
}
},

/**
* True when every repository in scope (or the organization) has a webhook delivering to the source URL. Webhooks
* are matched by URL, so there's no id to look up. A failed listing (GitHub answers 404 for a repository the token
* can't see) rejects rather than resolving false. Manual-mode webhooks are added by hand, with no token to check.
*/
async webhookExists({ webhookId, sourceUrl, options, fetch: fetchFn }) {
if (webhookId === MANUAL || !options.scope) return true;
if (!options.token) throw new Error('github: a token is needed to check the webhooks (GITHUB_TOKEN)');
for (const path of hookPaths(options.scope)) {
if (!(await hooksForUrl(fetchFn, options.token, path, sourceUrl)).length) return false;
}
return true;
},
};
19 changes: 18 additions & 1 deletion src/core/sources/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ export const emailReceived: SourceEvent<EmailReceivedArguments> = {
payloadSchema: z.toJSONSchema(emailReceivedPayload) as Record<string, unknown>,
};

class ResendApiError extends Error {
constructor(message: string, readonly status: number) {
super(message);
}
}

async function resendApi(fetchFn: typeof fetch, apiKey: string, path: string, init: { method: string; body?: unknown }) {
const res = await fetchFn(`${RESEND_API}${path}`, {
method: init.method,
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: init.body === undefined ? undefined : JSON.stringify(init.body),
});
const text = await res.text();
if (!res.ok) throw new Error(`Resend ${init.method} ${path} -> ${res.status} ${text.slice(0, 300)}`);
if (!res.ok) throw new ResendApiError(`Resend ${init.method} ${path} -> ${res.status} ${text.slice(0, 300)}`, res.status);
return text ? (JSON.parse(text) as Record<string, unknown>) : {};
}

Expand All @@ -136,4 +142,15 @@ export const resendProvider: SourceDefinition<ResendOptions> = {
async unregister({ webhookId, options, fetch: fetchFn }) {
await resendApi(fetchFn, options.apiKey, `/webhooks/${encodeURIComponent(webhookId)}`, { method: 'DELETE' });
},

/** A 404 means the webhook was deleted at Resend; any other failure means setup can't tell. */
async webhookExists({ webhookId, options, fetch: fetchFn }) {
try {
await resendApi(fetchFn, options.apiKey, `/webhooks/${encodeURIComponent(webhookId)}`, { method: 'GET' });
return true;
} catch (error) {
if (error instanceof ResendApiError && error.status === 404) return false;
throw error;
}
},
};
7 changes: 7 additions & 0 deletions src/core/sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export interface SourceDefinition<Options = Record<string, unknown>, Config = an
*/
register?(ctx: RegisterContext<Options>): Promise<{ webhookId: string; signingSecret: string }>;
unregister?(ctx: { webhookId: string; sourceUrl: string; options: Options; fetch: typeof fetch }): Promise<void>;
/**
* Whether the webhook `register` returned still exists at the service. On a re-run with nothing changed, setup asks
* before reporting the webhook as existing, and registers it again when this resolves false (someone deleted it at
* the service). Rejects when it can't tell (for example the key can't read webhooks, or the network fails): setup
* then keeps the saved webhook and warns. Without it, setup trusts the saved webhook id.
*/
webhookExists?(ctx: { webhookId: string; sourceUrl: string; options: Options; fetch: typeof fetch }): Promise<boolean>;
}

/** `Name <addr@example.com>` or `addr@example.com` to `addr@example.com`, lower-cased. For parsing arguments. */
Expand Down
Loading
Loading