prompt_router

Attribute Macro prompt_router 

Source
#[prompt_router]
Expand description

§prompt_router

This macro generates a prompt router based on functions marked with #[rmcp::prompt] in an implementation block.

It creates a function that returns a PromptRouter instance.

§Usage

fieldtypeusage
routerIdentThe name of the router function to be generated. Defaults to prompt_router.
visVisibilityThe visibility of the generated router function. Defaults to empty.

§Example

#[prompt_router]
impl MyPromptHandler {
    #[prompt]
    pub async fn greeting_prompt(&self, Parameters(args): Parameters<GreetingArgs>) -> Result<Vec<PromptMessage>, Error> {
        // Generate greeting prompt using args
    }

    pub fn new() -> Self {
        Self {
            // the default name of prompt router will be `prompt_router`
            prompt_router: Self::prompt_router(),
        }
    }
}