GeezerVison is showing github.com — feat(core): publish MCP events on the bus by rekram1-node · Pull Request #63261 · anomalyco/opencode
Conversation
Problem
#63254 added an MCP Events client, but only code inside the MCP service could read a server's events, one stream per caller, with nothing keeping a subscription alive across a broken stream or a reconnect. Clients and plugins could not see them at all.
Change
Experimental, behind the mcp_events flag (MCP Events is a draft extension).
- Public bus event (reaches clients through
/event and plugins through ctx.event.subscribe, like the other MCP events):
experimental.mcp.event { id, server, name, eventId, timestamp, data, cursor, truncated? }: one per event. Delivery is at least once; dedupe on id + eventId.
- Subscription status changes stay internal to core and are queryable through
Mcp.Service.subscriptions().
Mcp.Service: subscribe(server, { name, arguments?, cursor? }), unsubscribe(id), subscriptions(). A subscription has status: pending | active | ended(terminated | rejected | unavailable) (Mcp.SubscriptionStatus) and its last cursor. Its id hashes server, name and arguments with keys sorted at every depth, so the same subscription is returned instead of a second stream.
- Lifecycle, in one place: the service already publishes
mcp.status.changed on every server status change; it listens to it and starts or stops that server's subscriptions. Connected with events: stream. Pending or failed: stop, pending. Removed, disabled or no events: ended: unavailable. Streams run in the service, in its Location, never in a pooled connection's scope.
- Each stream reopens from the last cursor after a close, a break or 60 s of silence, with backoff from 1 s to 30 s.
terminated ends it; so does a rejection (EventStreamRejectedError, JSON-RPC -32601, -32602, -32023, -32024 or -32026). If the server reports a replay gap with a non-null cursor, the next event carries truncated: true. Reopening without a cursor does not imply a gap.
- Client:
events/stream rejections fail with EventStreamRejectedError instead of a bare error. Live events use the existing stream handoff without a new cutoff.
Not included: HTTP routes to create or list subscriptions, persistence across restarts, keeping an idle Location alive for its subscriptions.
Tests
test/mcp.test.ts over Streamable HTTP with a held-open event stream and a working bus: events reach the bus with every field and status follows pending → active; the same arguments in another key order return the same subscription; unsubscribing cancels the stream; a closed stream reopens from the last cursor (heartbeats advance it); terminated and a NotFound rejection end it without reopening; a reconnect resumes from the cursor and disabling ends it; the flag off refuses, and a server without events ends unavailable.
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" stroke="currentColor">
<style>
.e{animation:f 3s linear infinite;opacity:.9}
.e2{animation-delay:-1s;transform:translateX(40px)}.e3{animation-delay:-2s;transform:translateX(80px)}
@keyframes f{0%{transform:translateX(0);opacity:0}10%{opacity:.9}85%{opacity:.9}100%{transform:translateX(118px);opacity:0}}
@media (prefers-reduced-motion:reduce){.e{animation:none}}
</style>
<rect x="12" y="20" width="56" height="32" rx="6" stroke-opacity=".7"/>
<text x="40" y="40" text-anchor="middle" font-family="ui-monospace,monospace" font-size="10" fill="currentColor" stroke="none" opacity=".8">MCP</text>
<path d="M68 36H196" stroke-opacity=".3" stroke-dasharray="3 4"/>
<rect x="196" y="16" width="32" height="40" rx="6" stroke-opacity=".7"/>
<path d="M204 28h16M204 36h16M204 44h16" stroke-opacity=".5"/>
<g fill="currentColor" stroke="none">
<circle class="e" cx="74" cy="36" r="4"/>
<circle class="e e2" cx="74" cy="36" r="4"/>
<circle class="e e3" cx="74" cy="36" r="4"/>
</g>
</svg>
Added by the opencode bot (AI-generated).
Related: #48855
Public API: adds the experimental.mcp.event event, Mcp.SubscriptionStatus and Mcp.Service subscribe/unsubscribe/subscriptions (backwards compatible)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The design looks sound. Subscriptions are deduplicated by ID, cursor resume and reconnect handling are correct, the client buffer is bounded and fails instead of dropping messages, and everything is behind the mcp_events flag. I ran the new MCP Events tests in mcp.test.ts and mcp-events.test.ts and they all pass. The one failing test in mcp.test.ts also fails on the base. tsc --noEmit is clean for packages/core and packages/schema. The packages' typecheck script can't run here because this Bun has no bun check.
Public API impact, all additions and backwards compatible:
- New non-durable events
experimental.mcp.event and experimental.mcp.event.ended, on /event and ctx.event.subscribe, in openapi.json and in the generated client types.
- New config flag
mcp_events.
Mcp.Service gains events, subscribe, unsubscribe and subscriptions, plus EventsUnavailableError.
- Event definitions accept a
description, which appears in the OpenAPI spec.
- When the flag is on, connections declare the
io.modelcontextprotocol/events extension to servers, and the pool key includes it.
One concern, inline: an events/stream request rejected with a permanent error, such as an unknown event name, is retried forever and never publishes ended.
Note: the diff against the base also contains #63254's commits until this pull request is retargeted.
Related: #48855
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rejected events/stream requests now end the subscription as rejected, which fixes my earlier point. The new MCP Events tests pass and tsc --noEmit is clean for packages/core and packages/schema. The one failing test in mcp.test.ts also fails on the base.
Public API, all experimental additions and backwards compatible:
- Events
experimental.mcp.event ({ id, server, name, eventId, timestamp, data, cursor, truncated? }) and experimental.mcp.subscription.changed ({ id }), on /event, in openapi.json and in the client types.
Mcp.SubscriptionStatus schema.
Mcp.Service subscribe / unsubscribe / subscriptions, plus EventsUnavailableError and McpClient.EventStreamRejectedError.
Two new points, inline: the reopen backoff never resets after a healthy stream, and two tests run on the real clock with a fixed sleep.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This push takes experimental.mcp.subscription.changed out of the public event manifest, openapi.json and the client types. Subscription status is now readable only through Mcp.Service.subscriptions(), with the event kept internal to core. The manifest test passes and tsc --noEmit is clean for packages/schema.
Public API, compared with the previous revision: experimental.mcp.subscription.changed is removed from /event and the OpenAPI spec. That event had not shipped, so nothing breaks. The remaining additions are all experimental and backwards compatible: experimental.mcp.event, Mcp.SubscriptionStatus, Mcp.Service subscribe / unsubscribe / subscriptions, EventsUnavailableError and EventStreamRejectedError.
The open points on reopen backoff and live-clock tests are unchanged by this push.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This push removes the description option from event definitions, and with it the description on experimental.mcp.event in openapi.json. tsc --noEmit is clean for packages/schema and packages/core, and the manifest test passes.
Public API, compared with the previous revision: the spec only loses a doc string, which is backwards compatible. Overall the PR still adds, all experimental and backwards compatible: experimental.mcp.event, Mcp.SubscriptionStatus, Mcp.Service subscribe / unsubscribe / subscriptions, EventsUnavailableError and EventStreamRejectedError.
The open points on reopen backoff and live-clock tests aren't touched by this push.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This push sets truncated only when the server reports a gap with a non-null cursor, and drops the per-stream buffer cap. Without a cap the queue is unbounded rather than dropping messages. The updated MCP Events tests pass and tsc --noEmit is clean for packages/core.
The public API is unchanged from the previous revision. It still adds, all experimental and backwards compatible: experimental.mcp.event, Mcp.SubscriptionStatus, Mcp.Service subscribe / unsubscribe / subscriptions, EventsUnavailableError and EventStreamRejectedError.
The open points on reopen backoff and live-clock tests aren't touched by this push.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reopen backoff now resets once a stream sends active, so the delay no longer climbs to 30 s over a long-lived subscription. The terminate/reject test runs on TestClock without the fixed sleep. The MCP Events tests passed on each of 3 runs and tsc --noEmit is clean for packages/core. The public API is unchanged in this push.
One new point, inline: the backoff test intercepts Clock.sleep to pick out retry delays, which is hard to follow.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backoff test no longer wraps Clock. It records when each events/stream open happens under TestClock and checks that failed opens back off 1 s then 2 s, and that the delay resets to 1 s after a stream that sent active closes. That addresses my earlier point about the test. The MCP Events tests passed on all 5 runs and tsc --noEmit is clean for packages/core. The public API is unchanged in this push; nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup with no behaviour change, and nothing new to raise. Key-sorted hashing is now one shared canonicalJson helper, and the instructions test pins the existing hash value. The event stream errors live in a small module, so mcp/index.ts uses instanceof without loading the client module. Event data and arguments are typed as JSON. The MCP Events and instructions tests pass; the one failing test in mcp.test.ts also fails on the base. tsc --noEmit is clean for packages/core and packages/schema.
Public API in this push: the generated ExperimentalMcpEvent.data type is now JsonValue instead of any. It's narrower but experimental and unreleased, so nothing breaks. Mcp.SubscriptionStatus now requires error on terminated and rejected.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
simonklee
added a commit
that referenced
this pull request
Nov 12, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 12, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 12, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 12, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 13, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 13, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 14, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 14, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 15, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 15, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 16, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 16, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 17, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 17, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
simonklee
added a commit
that referenced
this pull request
Nov 18, 2026
Regenerate the API types and the F.7 fold oracle for experimental.mcp.event. No client shows the event: the TS TUI and mini do not subscribe to it, and the store ignores it.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|