Repository navigation
feat: Offer monitor events through the MCP Events extension, polled - #91
Merged
Merged
Conversation
…ion (SEP-3415), polled initialize advertises io.modelcontextprotocol/events, and the server answers events/list and events/poll itself, before mcp-go, which has no hook for custom methods: Handler() wraps the Streamable HTTP server and the stdio server filters stdin. Other events/* methods are not found until webhooks come. Two types, both polled: monitor.alert (a monitor changing state, narrowed by monitor, type, states, service and extra CQL) and pattern.anomaly. Each event is the event search's own, its eventId the event's event.id, with a title and a url to it in the app. The cursor is a watermark plus the IDs delivered at or after it: the watermark trails now by two minutes, since search indexing is eventually consistent, and the IDs keep a late search from repeating anything. maxAgeMs and a seven-day replay ceiling move it on, truncated only when that skipped an event.
tuncerkaplankiran
left a comment
Member
There was a problem hiding this comment.
Nice work overall, the stdio filter and the HTTP wrapper look solid to me (body is restored for mcp-go, batches and GET/DELETE fall through, lines don't interleave). Tests pass with -race too. Left a few comments, the first one is the one I'd fix before merging, it can drop events without setting truncated.
… single millisecond, and keep the query argument in its group A cursor holds at most 500 delivered IDs, so a poll caps its batch to what the cursor can take, and when Seen is full of events at one millisecond it moves past them and sets truncated, instead of jumping silently. The event search refuses from == to, so a one-millisecond range is searched with the next one and trimmed. The query argument has to keep its parentheses and quotes balanced, read as CQL's lexer does, so it can't close the group that keeps the monitor domain filter.
gkurt
added a commit
that referenced
this pull request
Nov 2, 2026
Stacked on #91, which adds polling. ## Why Polling runs a search for every subscription every 30 seconds, whether or not anything happened. Webhooks post each event once, as soon as the event search has it. The SEP's webhook mode needs server-side state, and this server holds none. So the library takes a store from the host. Admin, in the edgedelta repo, keeps subscriptions in DynamoDB and runs delivery. ## What - **`events/subscribe` and `events/unsubscribe`**, offered when the host passes `server.WithEventSubscriptions(store, sender)` and puts each caller's principal in the context (`events.WithPrincipal`). Each type then lists `delivery: ["poll","webhook"]`. - Subscriptions are keyed per the SEP by `(principal, url, name, arguments)`. The `id` is a truncated SHA-256 of that key. - Checks: `https` and a public address (`InvalidParams`); a `whsec_` secret of 24 to 64 bytes; push or any other mode is `Unsupported`; no principal is `Forbidden`. - The verification challenge runs once per `(principal, url)` and is cached for a day. A failure is `-32027` with `data.reason`. - Grants are an hour at most. A revoked principal can't refresh, so it stops getting events within the hour, with no access check on every run. `ttlMs: null` gets the same finite hour. - A refresh keeps the subscription's cursor, returns `deliveryStatus`, resumes a suspended subscription, and dual-signs for ten minutes when the secret changes. - A new subscription with a cursor starts from it, with `maxAgeMs` and `truncated` handled as in polling. - **`Handler.Deliver(ctx, sub)`**, which the host runs when a subscription's `NextRun` comes: - It polls from the stored cursor and posts each event in order. Each event is signed per Standard Webhooks, with `X-MCP-Subscription-Id` and the cursor after that event as the safe-to-persist watermark. - The cursor moves only past what the endpoint takes. A failure is retried from there, with doubling backoff up to 15 minutes. After a day of failures, delivery waits for the client's next refresh. - A 413 skips its event. A 410 or a lapsed grant ends the subscription. A stretch that had to be skipped gets a `gap` envelope. A principal that may no longer search gets a `terminated` envelope. - **`Sender`**: one HTTP client for challenges and deliveries. - It follows no redirects and refuses addresses that aren't globally routable. It checks this in the dialer's `Control`, so DNS rebinding can't get past it. - It keeps bodies at 256 KiB or less. - `WithRootCAs` is for private deployments and tests. - Polling is refactored so that the cursor after any number of a batch's events can be computed; delivery needs that. Polling behaves as before. - The README has a new Webhooks section. ## Testing - Table-driven tests: - Subscribe: create, refresh, rotation, one challenge per principal and URL, and each error. - Delivery: ordering, retry after a 503, 413, 410, a lapsed grant, revoked access, the cursor and subscription header on each event, and dual signing inside and after the overlap. - Backoff, and SSRF at both check and dial time. - Also `events/list` over HTTP with a store. - Run end to end with Canvas's own client against a local server built from this branch: - The server used an in-memory store and searched prod. A local endpoint verified signatures the way Canvas's `handleEventsWebhook` does. - Subscribing from a cursor an hour back: one challenge, then that hour's 23 ALERT events, all signed and verified, with no duplicates. - The refresh returned the same `id` and its `deliveryStatus` with no new challenge. Unsubscribing removed it, and a second unsubscribe answered NotFound with `kind: "subscription"`. - `go test ./...` and `go vet` pass, and golangci-lint reports only the 5 issues already on `main`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Clients such as Canvas start work from events on a connector's MCP server through the MCP Events extension,
io.modelcontextprotocol/events(SEP-3415, not merged yet). They subscribe as the team, so no model or session has to be there. With this PR, a client can start work when an Edge Delta monitor alerts, with no agent pollingget_event_search.This PR adds poll delivery only. The hosted server is stateless, and webhooks need a durable subscription store in the backend. That plan lives with the backend in the edgedelta repo.
What
initializeadvertises the extension, through anAfterInitializehook.events/listandevents/pollbefore mcp-go sees them:MCPHTTPServer.Handler()wraps the Streamable HTTP server.HTTPServer()is unchanged, but it doesn't serve events.events/*methods answer-32601.monitor.alert: a monitor changes state. Arguments:monitorId,monitor,type,states,service, plus extra CQL inquery.pattern.anomaly: the same for pattern anomaly monitors, with the log patterns behind the anomaly in the payload.eventIdis the event'sevent.id. Its payload has atitleand aurlto the event in the app (the link monitor notifications use), plus the monitor's state, priority, service, message and values.maxAgeMsmoves the cursor forward, and so does a seven-day limit.truncatedis true only when that skipped an event.maxEventsdefaults to 50 and is capped at 100, withhasMoreset when more are waiting.nextPollMsis 30000.-32023NotFound, withdata.kind: "event".-32602for bad arguments, a cursor the server didn't issue, or CQL the search refuses.-32024when the token can't search events.-32020, with HTTP 400, when anMcp-Nameheader names a different event. The header isn't required yet.WithAppURLoption. By default the app URL follows the API URL: staging getsapp-staging.Testing
pkg/eventscover:nullstart, each event delivered once, events indexed late, backlogs drained in batches with ties at the same millisecond, andmaxAgeMswith and without a gap;servercoverinitialize,events/list, theMcp-Namecheck and core methods still reaching mcp-go over HTTP, and the stdio filter.querycame back as-32602.src/server/connectors/events.tson the MCP SDK) against this branch over HTTPS. It listed both types and polled real events. Bad arguments came back as InvalidParams, an unknown type as NotFound and subscribe as MethodNotFound, and it sentMcp-Nameon everyevents/*request.go test ./...,go vetandgo mod tidypass. golangci-lint reports nothing new; the 5 remaining issues are already onmain.Once this is tagged (v0.2.42), the edgedelta repo bumps to it and switches admin to
Handler().