feat: add Default and constructors to ServerSseMessage#794
Open
erenatas wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
feat: add Default and constructors to ServerSseMessage#794erenatas wants to merge 2 commits intomodelcontextprotocol:mainfrom
erenatas wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
DaleSeo
reviewed
Apr 8, 2026
Member
DaleSeo
left a comment
There was a problem hiding this comment.
Can we add lightweight tests that assert field values for ServerSseMessage::new, ServerSseMessage::priming and Default? It would guard against accidental regressions if the type or helpers evolve.
Author
Yes, thank you for the suggestion. On it |
Author
|
I updated with basic tests, if you won't mind I fixed couple issues with tests that prevented me to run |
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.
Motivation and Context
ServerSseMessage is #[non_exhaustive] but has no public constructor,
Defaultimpl, or builder, making it impossible for downstreamSessionManagerimplementations to produce these values withoutunsafe.This change adds
#[derive(Default)]and two named constructors covering the common patterns:ServerSseMessage::new(event_id, message)— JSON-RPC content withan event ID
ServerSseMessage::priming(event_id, retry)— priming event perSEP-1699
Update all internal call sites in tower.rs and local.rs to use the new API.
How Has This Been Tested?
Tested in an rmcp based project. Pre-existing tests in
tower.rsandlocal.rscontinue to pass — these exercise the SSE stream paths that now use the new constructors.Note: the existing
http_headertest module on main has a pre-existing compilation error (references a renamed functionextract_scope_from_header); this is unrelated to this change.Breaking Changes
None. This is a purely additive change:
Default is a new trait impl on an existing public type.
new() and priming() are new inherent methods.
No existing API surface is modified or removed.
Types of changes
Checklist