Skip to main content

headless_lms_mcp/handlers/
guide.rs

1//! The `guide` tool: block schemas from the CMS and the hand-written topics.
2
3use async_trait::async_trait;
4
5use crate::guide;
6use crate::state::McpState;
7use crate::tools::args::GuideArgs;
8use crate::tools::{RequestContext, ToolError, ToolHandler, ToolOutcome, ToolResult};
9
10/// Handler of the `guide` tool.
11pub struct Guide;
12
13#[async_trait(?Send)]
14impl ToolHandler<McpState> for Guide {
15    type Args = GuideArgs;
16
17    async fn call(
18        &self,
19        state: &McpState,
20        _: &RequestContext,
21        args: GuideArgs,
22    ) -> Result<ToolOutcome, ToolError> {
23        let block_types = args.block_types.unwrap_or_default();
24        let topics = args.topics.unwrap_or_default();
25        let schemas = if block_types.is_empty() && !topics.is_empty() {
26            None
27        } else {
28            Some(state.block_schemas().await?)
29        };
30        Ok(ToolResult::success(guide::answer(schemas.as_deref(), &block_types, &topics)?).into())
31    }
32}