pub struct StreamableHttpContext {
pub protocol_version: McpProtocolVersion,
pub session_id: Option<String>,
pub wants_sse_stream: bool,
pub accepts_json: bool,
pub accepts_stream_frames: bool,
pub headers: HashMap<String, String>,
}http only.Expand description
Streamable HTTP request context
Fields§
§protocol_version: McpProtocolVersionProtocol version negotiated
session_id: Option<String>Session ID if provided
wants_sse_stream: boolWhether client wants SSE stream (text/event-stream)
accepts_json: boolWhether client also accepts JSON (application/json or /)
accepts_stream_frames: boolWhether client accepts stream frames (application/json, text/event-stream, or /)
headers: HashMap<String, String>Additional request headers
Implementations§
Source§impl StreamableHttpContext
impl StreamableHttpContext
Sourcepub fn from_request<T>(req: &Request<T>) -> StreamableHttpContext
pub fn from_request<T>(req: &Request<T>) -> StreamableHttpContext
Parse context from HTTP request headers
Sourcepub fn wants_sse_stream(&self) -> bool
pub fn wants_sse_stream(&self) -> bool
Whether client wants SSE stream
Sourcepub fn should_use_sse(&self, request: &JsonRpcRequest) -> bool
pub fn should_use_sse(&self, request: &JsonRpcRequest) -> bool
Choose SSE vs JSON response framing for a single request.
The server may answer a request with either a single JSON object or an SSE stream, and the client must support both — so this is a choice, not a conformance requirement:
- Client only accepts
text/event-stream→ SSE - Client only accepts
application/json→ JSON - Client accepts both → SSE only when the request opted into
request-scoped notifications, via
_meta.progressTokenor_meta."io.modelcontextprotocol/logLevel"
Those two keys are the only per-request opt-ins for server→client
notifications on a response stream, and both are gated on the request
having asked: ProgressNotificationParams.progressToken is required and
must be the token given in the originating request, and a server must not
emit notifications/message for a request that declared no log level. A
request carrying neither cannot legally be sent either notification, so
SSE framing would buy it nothing while costing interoperability — plain
JSON is the broader-support path, and it is the only path that can carry
the -32020/-32021 header/capability errors on HTTP 400 as their
schemas require (chunked SSE commits 200 before dispatch).
subscriptions/listen is unaffected: it is handled on its own path,
which independently requires Accept: text/event-stream.
Sourcepub fn wants_streaming_post(&self) -> bool
pub fn wants_streaming_post(&self) -> bool
Whether client wants streaming POST responses
Sourcepub fn is_streamable_compatible(&self) -> bool
pub fn is_streamable_compatible(&self) -> bool
Check if request is compatible with streamable HTTP
Sourcepub fn validate(&self, method: &Method) -> Result<(), String>
pub fn validate(&self, method: &Method) -> Result<(), String>
Validate request for MCP compliance
Sourcepub fn response_headers(&self) -> HeaderMap
pub fn response_headers(&self) -> HeaderMap
Create response headers for this context
Trait Implementations§
Source§impl Clone for StreamableHttpContext
impl Clone for StreamableHttpContext
Source§fn clone(&self) -> StreamableHttpContext
fn clone(&self) -> StreamableHttpContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Forget for StreamableHttpContext
impl Freeze for StreamableHttpContext
impl Move for StreamableHttpContext
impl RefUnwindSafe for StreamableHttpContext
impl Send for StreamableHttpContext
impl Sync for StreamableHttpContext
impl Unpin for StreamableHttpContext
impl UnsafeUnpin for StreamableHttpContext
impl UnwindSafe for StreamableHttpContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more