pub trait PromptHandler: Send + Sync {
// Required methods
fn definition(&self) -> Prompt;
fn get(
&self,
ctx: &McpContext,
arguments: HashMap<String, String>,
) -> McpResult<Vec<PromptMessage>>;
// Provided methods
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>>> { ... }
}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§
Sourcefn definition(&self) -> Prompt
fn definition(&self) -> Prompt
Returns the prompt definition.
Sourcefn get(
&self,
ctx: &McpContext,
arguments: HashMap<String, String>,
) -> McpResult<Vec<PromptMessage>>
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§
Sourcefn icon(&self) -> Option<&Icon>
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().
Sourcefn version(&self) -> Option<&str>
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().
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().
Sourcefn timeout(&self) -> Option<Duration>
fn timeout(&self) -> Option<Duration>
Returns the prompt’s custom timeout duration.
Default implementation returns None, meaning the server’s default
timeout applies. Override to specify a per-handler timeout.
Sourcefn get_async<'a>(
&'a self,
ctx: &'a McpContext,
arguments: HashMap<String, String>,
) -> BoxFuture<'a, McpOutcome<Vec<PromptMessage>>>
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.