cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `WebMCP` domain.
//!
//! Types, command parameters and event payloads for the `WebMCP`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Tool annotations
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Annotation {
    /// A hint indicating that the tool does not modify any state.
    #[serde(rename = "readOnly", default, skip_serializing_if = "Option::is_none")]
    pub read_only: Option<bool>,
    /// A hint indicating that the tool output may contain untrusted content, ex:
    /// UGC, 3rd party data.
    #[serde(
        rename = "untrustedContent",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub untrusted_content: Option<bool>,
    /// A hint indicating that executing the tool will result in consequential
    /// actions, ex: booking a flight, transferring money.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub consequential: Option<bool>,
    /// If true, indicates that the tool is intended for debugging and developer
    /// tooling rather than end-user interactions.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub debugging: Option<bool>,
    /// If the declarative tool was declared with the autosubmit attribute.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub autosubmit: Option<bool>,
}

/// Represents the status of a tool invocation.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum InvocationStatus {
    /// `Completed`
    Completed,
    /// `Canceled`
    Canceled,
    /// `Error`
    Error,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Unique identifier of a registered tool. A new identifier is created every
/// time a tool is registered, so a tool that is unregistered and then
/// registered again under the same name gets a different identifier. Clients
/// should treat it as an opaque string.
pub type ToolId = String;

/// Definition of a tool that can be invoked.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Tool {
    /// Tool identifier.
    #[serde(rename = "toolId")]
    pub tool_id: ToolId,
    /// Tool name.
    pub name: String,
    /// Tool description.
    pub description: String,
    /// Schema for the tool's input parameters.
    #[serde(
        rename = "inputSchema",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub input_schema: Option<serde_json::Value>,
    /// Schema for the tool's output structure.
    #[serde(
        rename = "outputSchema",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub output_schema: Option<serde_json::Value>,
    /// Optional annotations for the tool.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub annotations: Option<Annotation>,
    /// Frame identifier associated with the tool registration.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// Optional node ID for declarative tools.
    #[serde(
        rename = "backendNodeId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub backend_node_id: Option<crate::protocol::dom::BackendNodeId>,
    /// The stack trace at the time of the registration.
    #[serde(
        rename = "stackTrace",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub stack_trace: Option<crate::protocol::runtime::StackTrace>,
}

/// Definition of a tool that was removed.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemovedTool {
    /// Identifier of the removed tool.
    #[serde(rename = "toolId")]
    pub tool_id: ToolId,
    /// Tool name.
    pub name: String,
    /// Frame identifier associated with the tool registration.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
}

/// Enables the WebMCP domain, allowing events to be sent. Enabling the domain
/// will trigger a toolsAdded event for all currently registered tools.
///
/// Parameters of `WebMCP.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "WebMCP.enable";
    type Returns = crate::typed::NoReturns;
}

/// Disables the WebMCP domain.
///
/// Parameters of `WebMCP.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "WebMCP.disable";
    type Returns = crate::typed::NoReturns;
}

/// Invokes a registered tool.
///
/// Parameters of `WebMCP.invokeTool`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct InvokeToolParams {
    /// Frame in which to invoke the tool.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// Name of the tool to invoke.
    #[serde(rename = "toolName")]
    pub tool_name: String,
    /// Input parameters for the tool, matching the tool's inputSchema.
    pub input: serde_json::Value,
}

/// What `WebMCP.invokeTool` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct InvokeToolReturns {
    /// Unique identifier for this invocation. Response is sent before tool
    /// events.
    #[serde(rename = "invocationId")]
    pub invocation_id: String,
}

impl crate::typed::Command for InvokeToolParams {
    const METHOD: &'static str = "WebMCP.invokeTool";
    type Returns = InvokeToolReturns;
}

/// Cancels a pending tool invocation.
///
/// Parameters of `WebMCP.cancelInvocation`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CancelInvocationParams {
    /// Invocation identifier to cancel.
    #[serde(rename = "invocationId")]
    pub invocation_id: String,
}

impl crate::typed::Command for CancelInvocationParams {
    const METHOD: &'static str = "WebMCP.cancelInvocation";
    type Returns = crate::typed::NoReturns;
}

/// Event fired when new tools are added.
///
/// Payload of the `WebMCP.toolsAdded` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ToolsAddedEvent {
    /// Array of tools that were added.
    pub tools: Vec<Tool>,
}

impl crate::typed::Event for ToolsAddedEvent {
    const METHOD: &'static str = "WebMCP.toolsAdded";
}

/// Event fired when tools are removed.
///
/// Payload of the `WebMCP.toolsRemoved` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ToolsRemovedEvent {
    /// Array of tools that were removed.
    pub tools: Vec<RemovedTool>,
}

impl crate::typed::Event for ToolsRemovedEvent {
    const METHOD: &'static str = "WebMCP.toolsRemoved";
}

/// Event fired when a tool invocation starts.
///
/// Payload of the `WebMCP.toolInvoked` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ToolInvokedEvent {
    /// Frame id
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// Invocation identifier.
    #[serde(rename = "invocationId")]
    pub invocation_id: String,
    /// The input parameters used for the invocation.
    pub input: String,
    /// Name of the tool to invoke. Missing if the tool was invoked by its
    /// identifier, but could not be found (e.g., it was already unregistered), so
    /// its name could not be recovered.
    #[serde(rename = "toolName", default, skip_serializing_if = "Option::is_none")]
    pub tool_name: Option<String>,
    /// Identifier of the tool to invoke. Missing if the tool was invoked by name,
    /// but could not be found, so its identifier could not be recovered.
    #[serde(rename = "toolId", default, skip_serializing_if = "Option::is_none")]
    pub tool_id: Option<ToolId>,
}

impl crate::typed::Event for ToolInvokedEvent {
    const METHOD: &'static str = "WebMCP.toolInvoked";
}

/// Event fired when a tool invocation completes or fails.
///
/// Payload of the `WebMCP.toolResponded` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ToolRespondedEvent {
    /// Invocation identifier.
    #[serde(rename = "invocationId")]
    pub invocation_id: String,
    /// Status of the invocation.
    pub status: InvocationStatus,
    /// Output or error delivered as delivered to the agent. Missing if `status`
    /// is anything other than Completed. Note: The output is untrusted and poses
    /// a prompt injection risk. Clients should treat this as potentially
    /// malicious user input.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub output: Option<serde_json::Value>,
    /// Error text for protocol users.
    #[serde(rename = "errorText", default, skip_serializing_if = "Option::is_none")]
    pub error_text: Option<String>,
    /// The exception object, if the javascript tool threw an error\>
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exception: Option<crate::protocol::runtime::RemoteObject>,
}

impl crate::typed::Event for ToolRespondedEvent {
    const METHOD: &'static str = "WebMCP.toolResponded";
}