Skip to content

feat(mcp): follow the MCP Events beta for push delivery - #65271

Merged
rekram1-node merged 13 commits into
devfrom
mcp-event-headers
Nov 22, 2026
Merged

rekram1-node merged 13 commits into
devfrom
mcp-event-headers

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Brings the experimental MCP Events client (push delivery) up to the beta of SEP-3415. Poll and webhook are still out of scope.

  • Header mirroring: events/stream sends Mcp-Param-* headers for subscription arguments marked with x-mcp-header, as tool calls do. On HeaderMismatch (-32020) it relists and retries once. The SDK keeps its header scan and encoding private, so a small port lives in client.ts; it matches the SDK's output on the schemas and values I compared.
  • 2026-07-28 only: Events are exposed only when the connection negotiated 2026-07-28 and the server advertises the extension, since the spec defines them for that revision only. Attached connections can now pick a protocol, which the event test fixtures use.
  • Checks in the client: events/list skips event types that are malformed or whose schemas can't be checked. events.check refuses an unknown event type, one without push, or arguments that don't match inputSchema; stream runs it first. Events whose data doesn't match payloadSchema are dropped with a warning.
  • Heartbeats: a stream is dead after three of the server's granted heartbeat intervals pass in silence (30s each before the grant). Reopens back off from 1s to 30s with jitter.
  • List changes: when the server advertises listChanged, the client opens subscriptions/listen with eventsListChanged and relists on notifications/events/list_changed.
  • Replay: resuming from a cursor asks for at most an hour of backlog (maxAgeMs), and the last 100 event IDs are remembered per subscription so a replayed event isn't delivered twice.
  • Mcp.follow: following an event type now lives in the MCP service: it reopens broken streams, waits for a disconnected server, dedupes, and yields each event with the position after it. Automation watches only store that position next to the run's result, and Mcp.subscribe is built on it too. A watch now waits for its server to come back instead of pausing after three failed reopens.
  • No more mcp_events flag: Events are always on. Nothing happens unless a server offers them and something subscribes, and automations: false still turns event watches off. A leftover experimental.mcp_events is ignored like any unknown key.
  • Gaps: a watch no longer pauses when the server can't replay from its saved position. It keeps going from now.

How did you verify your code works?

Moved the event fixtures to the 2026-07-28 handshake and extended the existing tests rather than adding new ones. MCP, MCP events, automation and tool suites pass, plus bun run check.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound. I ran the pull request's MCP test file against the base code: the new Streamable HTTP events test fails there because the server rejects the stream for the missing Mcp-Param-Job header, and it passes with this change. I also checked the installed patched SDK: the ESM shortened names (D/k) and the CJS require_src exports both resolve to buildMcpParamHeaders and scanXMcpHeaderDeclarations. With the pull request, test/mcp.test.ts and test/mcp-events.test.ts pass except one subprocess test ("terminates MCP descendants after the wrapper exits successfully") that also fails on the base. typecheck:tsc is clean.

The stream retry follows the same relist-and-retry-once pattern as callTool. Event types with invalid x-mcp-header annotations are dropped with a warning, as the spec requires.

Public API is unchanged: the only new exports come from the project's private SDK patch.

@rekram1-node
rekram1-node force-pushed the mcp-event-headers branch 3 times, most recently from fa2dd51 to 24715dc Compare November 21, 2026 00:34
@rekram1-node rekram1-node changed the title feat(mcp): mirror event subscription arguments into Mcp-Param headers feat(mcp): follow the MCP Events beta for push delivery Nov 21, 2026
@rekram1-node
rekram1-node force-pushed the mcp-event-headers branch 2 times, most recently from 7514332 to b6e2b16 Compare November 21, 2026 01:21
@rekram1-node
rekram1-node force-pushed the mcp-event-headers branch 4 times, most recently from 117d7f9 to 8f635ad Compare November 21, 2026 23:39
@rekram1-node
rekram1-node merged commit 1645a8a into dev Nov 22, 2026
11 checks passed
@rekram1-node
rekram1-node deleted the mcp-event-headers branch November 22, 2026 03:48
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.

1 participant