Skip to main content

webmcp/
error.rs

1//! Errors raised while *registering* a tool.
2//!
3//! Errors raised *inside* a handler are not these — they travel back to the
4//! agent as a `ToolResult` with `isError: true`, which is what the protocol
5//! expects. See [`crate::ToolResult::error`].
6
7/// Result alias for registration operations.
8pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// No `modelContext` on this page: an older browser, a non-browser target,
13    /// or the server side of an SSR render.
14    ///
15    /// Callers should treat this as "the agent surface is not here" rather than
16    /// as a failure — see [`crate::is_supported`].
17    #[error("WebMCP is not available in this environment")]
18    Unsupported,
19
20    /// The user agent rejected the descriptor (bad name, malformed schema, or a
21    /// name already registered on this page).
22    #[error("registerTool() rejected the tool: {0}")]
23    Rejected(String),
24
25    /// A required descriptor field is missing or blank.
26    #[error("invalid tool descriptor: {0}")]
27    Descriptor(String),
28
29    /// `inputSchema` did not serialize to a JSON object.
30    #[error("invalid input schema: {0}")]
31    Schema(String),
32}