Skip to content

MCP Events: Client-side ProvenanceEnvelope and EventQueue utilities#2419

Closed
elijahr wants to merge 28 commits intomodelcontextprotocol:mainfrom
axiomantic:mcp-events
Closed

MCP Events: Client-side ProvenanceEnvelope and EventQueue utilities#2419
elijahr wants to merge 28 commits intomodelcontextprotocol:mainfrom
axiomantic:mcp-events

Conversation

@elijahr
Copy link
Copy Markdown

@elijahr elijahr commented Apr 10, 2026

Summary

  • Adds ProvenanceEnvelope dataclass for wrapping event payloads with client-generated provenance metadata (server identity, trust tier, topic, source, timestamp) before LLM context injection
  • Adds EventQueue with priority-aware drain() API that returns events in strict priority order (urgent > high > normal > low)
  • Both utilities live in mcp.client.events as standalone helpers

Test plan

  • 17 new tests in tests/client/test_events.py covering serialization, XML escaping, priority ordering, drain semantics
  • All 67 existing event tests still pass
  • uv run pytest tests/ -k event -x

maxisbey and others added 28 commits January 22, 2026 13:56
…odelcontextprotocol#1945)

Co-authored-by: Maxime <67350340+max-rousseau@users.noreply.github.com>
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
…ontextprotocol#2090)

Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
…#2101)

Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
…ol#2137)

Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
…est (modelcontextprotocol#2334)

Co-authored-by: Owen Devereaux <owendevereaux@users.noreply.github.com>
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
…nt events

Implements events/subscribe, events/unsubscribe, events/list, and events/emit
as new MCP protocol methods. Includes subscription registry with MQTT-style
wildcard matching (+/#), retained value store with TTL expiry, and client-side
event handler with topic filtering and subscription tracking.

Reference implementation for MCP SEP (Specification Enhancement Proposal)
for topic-based server-to-client events.
Read session_id from InitializeResult._meta after initialize and expose
as session.session_id property. Enables client-side construction of
session-scoped event topics for the {session_id} authorization convention.
ProvenanceEnvelope wraps events with client-assessed provenance metadata
(server, trust tier, topic, source) for safe injection into LLM context,
with to_dict(), to_xml() (XML-escaped), and from_event() factory methods.

EventQueue provides priority-aware buffering with 4 deques (urgent/high/
normal/low) that drain in strict priority order, supporting partial drains
via max_count. Priority is resolved from the highest-priority
requestedEffect; events without effects default to normal.

Fixed a bug in the plan's _resolve_priority where the baseline was "normal"
(rank 2), causing "low" priority events to be promoted to "normal".
Changed baseline to "low" (rank 3) so all priority levels resolve correctly.
- Fix 1 (test_priority_from_multiple_effects): add low-priority event and drain with max_count=1 to prove multi-effect event lands in urgent bucket
- Fix 2 (test_priority_no_effects): add low-priority event enqueued first and assert drain order proves no-effects defaults to normal
- Fix 3 (test_to_xml_basic): exact string equality, assert event_id/received_at absent when not set
- Fix 4 (test_to_xml_with_special_chars_in_attrs): verify escaped forms (single-quote wrapping for ", &lt; for <) with exact string equality
- Fix 5 (test_from_event_extracts_fields): replace "T" in string check with datetime.fromisoformat() validation
@elijahr
Copy link
Copy Markdown
Author

elijahr commented Apr 10, 2026

Opened against wrong repo. This should be on axiomantic/python-sdk.

@elijahr elijahr closed this Apr 10, 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.

6 participants