Skip to main content

PromptHandler

Trait PromptHandler 

Source
pub trait PromptHandler: Send + Sync {
Show 21 methods // Required methods fn definition(&self) -> Prompt; fn get( &self, ctx: &McpContext, arguments: HashMap<String, String>, ) -> McpResult<Vec<PromptMessage>>; // Provided methods fn final_client_direct_https(&self) -> bool { ... } fn declares_final_mrtr(&self) -> bool { ... } fn final_definition(&self) -> Option<FinalPrompt> { ... } fn final_title(&self) -> Option<&str> { ... } fn final_icons(&self) -> Option<&[RawIcon]> { ... } fn final_metadata(&self) -> Option<&OpenMetadata> { ... } fn icon(&self) -> Option<&Icon> { ... } fn version(&self) -> Option<&str> { ... } fn tags(&self) -> &[String] { ... } fn timeout(&self) -> Option<Duration> { ... } fn get_async<'a>( &'a self, ctx: &'a McpContext, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<Vec<PromptMessage>>> { ... } fn get_final( &self, ctx: &McpContext, arguments: HashMap<String, String>, ) -> McpResult<CompleteResult<FinalGetPromptResult>> { ... } fn get_final_outcome( &self, ctx: &McpContext, arguments: HashMap<String, String>, ) -> McpResult<FinalMethodOutcome<FinalGetPromptResult>> { ... } fn get_final_async<'a>( &'a self, ctx: &'a McpContext, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<CompleteResult<FinalGetPromptResult>>> { ... } fn get_final_outcome_async<'a>( &'a self, ctx: &'a McpContext, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<FinalMethodOutcome<FinalGetPromptResult>>> { ... } fn get_async_in_request<'a>( &'a self, ctx: &'a McpContext, _request_cx: &'a Cx, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<Vec<PromptMessage>>> { ... } fn get_final_async_in_request<'a>( &'a self, ctx: &'a McpContext, _request_cx: &'a Cx, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<CompleteResult<FinalGetPromptResult>>> { ... } fn get_final_outcome_async_in_request<'a>( &'a self, ctx: &'a McpContext, _request_cx: &'a Cx, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<FinalMethodOutcome<FinalGetPromptResult>>> { ... } fn get_final_outcome_async_resuming_in_request<'a>( &'a self, ctx: &'a McpContext, request_cx: &'a Cx, arguments: HashMap<String, String>, _resume_inputs: Option<&'a MrtrCompletedInputs>, ) -> BoxFuture<'a, McpOutcome<FinalMethodOutcome<FinalGetPromptResult>>> { ... }
}
Expand description

Handler for a prompt.

This trait is typically implemented via the #[prompt] macro.

§Sync vs Async

By default, implement get() for synchronous execution. For async prompts, override get_async() instead. The router always calls get_async(), which defaults to running get() in an async block.

§Return Type

Async handlers return McpOutcome<Vec<PromptMessage>>, a 4-valued type.

Required Methods§

Source

fn definition(&self) -> Prompt

Returns the prompt definition.

Source

fn get( &self, ctx: &McpContext, arguments: HashMap<String, String>, ) -> McpResult<Vec<PromptMessage>>

Gets the prompt messages synchronously with the given arguments.

This is the default implementation point. Override this for simple synchronous prompts. Returns McpResult which is converted to McpOutcome by the async wrapper.

Provided Methods§

Source

fn final_client_direct_https(&self) -> bool

Returns whether resource links authored by this prompt’s final result may use client-direct HTTPS. Exact MCP 2024-11-05 dispatch never consults this declaration.

Source

fn declares_final_mrtr(&self) -> bool

Declares whether this handler can use final MRTR continuations.

The router consults this immutable capability before invoking a final prompt handler on a context that has no durable modern session partition.

Source

fn final_definition(&self) -> Option<FinalPrompt>

Returns an exact final prompt catalog definition, when this handler owns one. In particular, argument titles and absent-vs-present required values must not be projected through legacy prompt args.

Source

fn final_title(&self) -> Option<&str>

Returns the final display title for this prompt.

Source

fn final_icons(&self) -> Option<&[RawIcon]>

Returns the final icon set for this prompt.

Source

fn final_metadata(&self) -> Option<&OpenMetadata>

Returns final open metadata for this prompt.

Source

fn icon(&self) -> Option<&Icon>

Returns the prompt’s icon, if any.

Default implementation returns None. Override to provide an icon. Note: Icons can also be set directly in definition().

Source

fn version(&self) -> Option<&str>

Returns the prompt’s version, if any.

Default implementation returns None. Override to provide a version. Note: Version can also be set directly in definition().

Source

fn tags(&self) -> &[String]

Returns the prompt’s tags for filtering and organization.

Default implementation returns an empty slice. Override to provide tags. Note: Tags can also be set directly in definition().

Source

fn timeout(&self) -> Option<Duration>

Returns the prompt’s custom timeout duration.

Default implementation returns None, meaning no additional handler ceiling is added. A non-zero value only tightens outer budgets; zero cannot disable an ambient, request, or server deadline. A blocking synchronous get() cannot be preempted; if it returns after the deadline, its result is rejected.

Source

fn get_async<'a>( &'a self, ctx: &'a McpContext, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<Vec<PromptMessage>>>

Gets the prompt messages asynchronously with the given arguments.

Override this for prompts that need true async execution (e.g., template fetching, dynamic content generation).

Returns McpOutcome to properly represent all four states.

The default implementation delegates to the sync get() method.

Source

fn get_final( &self, ctx: &McpContext, arguments: HashMap<String, String>, ) -> McpResult<CompleteResult<FinalGetPromptResult>>

Gets the prompt through the final MCP 2026-07-28 result surface.

Legacy-only handlers retain their exact Self::get behavior. Direct final handlers can override this method to keep final common content and its open fields without a legacy projection.

Source

fn get_final_outcome( &self, ctx: &McpContext, arguments: HashMap<String, String>, ) -> McpResult<FinalMethodOutcome<FinalGetPromptResult>>

Gets the prompt through the complete-or-input-required final algebra.

The default preserves the exact legacy projection by promoting Self::get_final into the complete branch. A final-only handler may override this method to return input_required without coercing that state into a legacy prompt result.

Source

fn get_final_async<'a>( &'a self, ctx: &'a McpContext, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<CompleteResult<FinalGetPromptResult>>>

Asynchronously gets the prompt through the final result surface.

Source

fn get_final_outcome_async<'a>( &'a self, ctx: &'a McpContext, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<FinalMethodOutcome<FinalGetPromptResult>>>

Asynchronously gets the prompt through the complete-or-input-required final algebra.

Source

fn get_async_in_request<'a>( &'a self, ctx: &'a McpContext, _request_cx: &'a Cx, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<Vec<PromptMessage>>>

Gets the prompt from a request-owned structured child.

Modern router dispatch supplies the child Cx that owns this prompt evaluation. Existing handlers preserve their exact behavior through the default delegation to Self::get_async.

Source

fn get_final_async_in_request<'a>( &'a self, ctx: &'a McpContext, _request_cx: &'a Cx, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<CompleteResult<FinalGetPromptResult>>>

Gets the prompt’s final result from a request-owned structured child.

Source

fn get_final_outcome_async_in_request<'a>( &'a self, ctx: &'a McpContext, _request_cx: &'a Cx, arguments: HashMap<String, String>, ) -> BoxFuture<'a, McpOutcome<FinalMethodOutcome<FinalGetPromptResult>>>

Gets the prompt’s complete-or-input-required final outcome from a request-owned structured child.

Source

fn get_final_outcome_async_resuming_in_request<'a>( &'a self, ctx: &'a McpContext, request_cx: &'a Cx, arguments: HashMap<String, String>, _resume_inputs: Option<&'a MrtrCompletedInputs>, ) -> BoxFuture<'a, McpOutcome<FinalMethodOutcome<FinalGetPromptResult>>>

Resumes a final prompt invocation after framework-admitted MRTR input.

#[prompt] maps an Option<&MrtrCompletedInputs> user-function parameter to this hook, keeping it out of prompt arguments.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§