pub struct RequestContext { /* private fields */ }Expand description
Context information for an MCP request.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn with_session(self, session: Arc<dyn McpSession>) -> Self
pub fn with_session(self, session: Arc<dyn McpSession>) -> Self
Set the session handle for bidirectional communication.
Sourcepub async fn elicit_form(
&self,
message: impl Into<String>,
schema: Value,
) -> McpResult<ElicitResult>
pub async fn elicit_form( &self, message: impl Into<String>, schema: Value, ) -> McpResult<ElicitResult>
Request user input via a form.
Sourcepub async fn elicit_url(
&self,
message: impl Into<String>,
url: impl Into<String>,
elicitation_id: impl Into<String>,
) -> McpResult<ElicitResult>
pub async fn elicit_url( &self, message: impl Into<String>, url: impl Into<String>, elicitation_id: impl Into<String>, ) -> McpResult<ElicitResult>
Request user action via a URL.
Sourcepub async fn sample(
&self,
request: CreateMessageRequest,
) -> McpResult<CreateMessageResult>
pub async fn sample( &self, request: CreateMessageRequest, ) -> McpResult<CreateMessageResult>
Request LLM sampling from the client.
Sourcepub fn with_id(id: impl Into<String>) -> Self
pub fn with_id(id: impl Into<String>) -> Self
Create a new request context with a specific request ID.
Sourcepub fn with_transport(self, transport: TransportType) -> Self
pub fn with_transport(self, transport: TransportType) -> Self
Set the transport type.
Sourcepub fn with_headers(self, headers: HashMap<String, String>) -> Self
pub fn with_headers(self, headers: HashMap<String, String>) -> Self
Set the HTTP headers.
Sourcepub fn with_user_id(self, user_id: impl Into<String>) -> Self
pub fn with_user_id(self, user_id: impl Into<String>) -> Self
Set the user ID.
Sourcepub fn with_session_id(self, session_id: impl Into<String>) -> Self
pub fn with_session_id(self, session_id: impl Into<String>) -> Self
Set the session ID.
Sourcepub fn with_client_id(self, client_id: impl Into<String>) -> Self
pub fn with_client_id(self, client_id: impl Into<String>) -> Self
Set the client ID.
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self
Add a metadata key-value pair.
Sourcepub fn with_cancellation_token(self, token: Arc<CancellationToken>) -> Self
pub fn with_cancellation_token(self, token: Arc<CancellationToken>) -> Self
Set the cancellation token.
Sourcepub fn request_id(&self) -> &str
pub fn request_id(&self) -> &str
Get the request ID.
Sourcepub fn transport(&self) -> TransportType
pub fn transport(&self) -> TransportType
Get the transport type.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Get a specific HTTP header (case-insensitive).
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Get the session ID.
Sourcepub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn get_metadata(&self, key: &str) -> Option<&Value>
Get a metadata value.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if the request has been cancelled.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the user is authenticated.
Sourcepub fn to_core_context(&self) -> RequestContext
pub fn to_core_context(&self) -> RequestContext
Convert to the core RequestContext type.
This method creates a minimal context compatible with the unified
turbomcp_core::McpHandler trait. Headers and auth fields are
encoded as metadata with standard prefixes.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more