MCP Events: Client-side ProvenanceEnvelope and EventQueue utilities#2419
Closed
elijahr wants to merge 28 commits intomodelcontextprotocol:mainfrom
Closed
MCP Events: Client-side ProvenanceEnvelope and EventQueue utilities#2419elijahr wants to merge 28 commits intomodelcontextprotocol:mainfrom
elijahr wants to merge 28 commits intomodelcontextprotocol:mainfrom
Conversation
…ntextprotocol#1928) Co-authored-by: Jacem Elwaar <jacem@mcpappsbuilders.com>
…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 ", < for <) with exact string equality - Fix 5 (test_from_event_extracts_fields): replace "T" in string check with datetime.fromisoformat() validation
Author
|
Opened against wrong repo. This should be on axiomantic/python-sdk. |
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.
Summary
ProvenanceEnvelopedataclass for wrapping event payloads with client-generated provenance metadata (server identity, trust tier, topic, source, timestamp) before LLM context injectionEventQueuewith priority-awaredrain()API that returns events in strict priority order (urgent > high > normal > low)mcp.client.eventsas standalone helpersTest plan
tests/client/test_events.pycovering serialization, XML escaping, priority ordering, drain semanticsuv run pytest tests/ -k event -x