#[prompt]Expand description
Marks an async function as an MCP prompt handler and generates a companion
{fn_name}_prompt_def() function that returns a mcp::PromptDef.
§Attributes
name = "..."— Prompt name (defaults to function name with-instead of_)description = "..."— Optional descriptionarguments = ["arg1", "arg2:required", "arg3:optional"]— Optional argument list
§Examples
Basic prompt:
ⓘ
use mcp_kit::prelude::*;
#[prompt(name = "greeting", description = "Generate a greeting message")]
async fn greeting(_req: GetPromptRequest) -> McpResult<GetPromptResult> {
Ok(GetPromptResult::new(vec![
PromptMessage::user_text("Hello! How can I help you today?")
]))
}Prompt with arguments:
ⓘ
use mcp_kit::prelude::*;
#[prompt(
name = "code-review",
description = "Generate a code review",
arguments = ["code:required", "language:optional"]
)]
async fn code_review(req: GetPromptRequest) -> McpResult<GetPromptResult> {
let code = req.arguments.get("code").cloned().unwrap_or_default();
let lang = req.arguments.get("language").cloned().unwrap_or_else(|| "unknown".into());
Ok(GetPromptResult::new(vec![
PromptMessage::user_text(format!("Review this {lang} code:\n\n```{lang}\n{code}\n```"))
]))
}