Skip to main content

cdp_driver/protocol/
web_mcp.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! The `WebMCP` domain.
5//!
6//! Types, command parameters and event payloads for the `WebMCP`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14/// Tool annotations
15#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
16pub struct Annotation {
17    /// A hint indicating that the tool does not modify any state.
18    #[serde(rename = "readOnly", default, skip_serializing_if = "Option::is_none")]
19    pub read_only: Option<bool>,
20    /// A hint indicating that the tool output may contain untrusted content, ex:
21    /// UGC, 3rd party data.
22    #[serde(
23        rename = "untrustedContent",
24        default,
25        skip_serializing_if = "Option::is_none"
26    )]
27    pub untrusted_content: Option<bool>,
28    /// A hint indicating that executing the tool will result in consequential
29    /// actions, ex: booking a flight, transferring money.
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub consequential: Option<bool>,
32    /// If true, indicates that the tool is intended for debugging and developer
33    /// tooling rather than end-user interactions.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub debugging: Option<bool>,
36    /// If the declarative tool was declared with the autosubmit attribute.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub autosubmit: Option<bool>,
39}
40
41/// Represents the status of a tool invocation.
42#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
43pub enum InvocationStatus {
44    /// `Completed`
45    Completed,
46    /// `Canceled`
47    Canceled,
48    /// `Error`
49    Error,
50    /// A value this vendored schema does not list. Chrome adds values ahead of
51    /// the published protocol, so an unrecognised one is kept as it arrived
52    /// rather than failing the payload it came in.
53    #[serde(untagged)]
54    Unrecognized(String),
55}
56
57/// Unique identifier of a registered tool. A new identifier is created every
58/// time a tool is registered, so a tool that is unregistered and then
59/// registered again under the same name gets a different identifier. Clients
60/// should treat it as an opaque string.
61pub type ToolId = String;
62
63/// Definition of a tool that can be invoked.
64#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65pub struct Tool {
66    /// Tool identifier.
67    #[serde(rename = "toolId")]
68    pub tool_id: ToolId,
69    /// Tool name.
70    pub name: String,
71    /// Tool description.
72    pub description: String,
73    /// Schema for the tool's input parameters.
74    #[serde(
75        rename = "inputSchema",
76        default,
77        skip_serializing_if = "Option::is_none"
78    )]
79    pub input_schema: Option<serde_json::Value>,
80    /// Schema for the tool's output structure.
81    #[serde(
82        rename = "outputSchema",
83        default,
84        skip_serializing_if = "Option::is_none"
85    )]
86    pub output_schema: Option<serde_json::Value>,
87    /// Optional annotations for the tool.
88    #[serde(default, skip_serializing_if = "Option::is_none")]
89    pub annotations: Option<Annotation>,
90    /// Frame identifier associated with the tool registration.
91    #[serde(rename = "frameId")]
92    pub frame_id: crate::protocol::page::FrameId,
93    /// Optional node ID for declarative tools.
94    #[serde(
95        rename = "backendNodeId",
96        default,
97        skip_serializing_if = "Option::is_none"
98    )]
99    pub backend_node_id: Option<crate::protocol::dom::BackendNodeId>,
100    /// The stack trace at the time of the registration.
101    #[serde(
102        rename = "stackTrace",
103        default,
104        skip_serializing_if = "Option::is_none"
105    )]
106    pub stack_trace: Option<crate::protocol::runtime::StackTrace>,
107}
108
109/// Definition of a tool that was removed.
110#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
111pub struct RemovedTool {
112    /// Identifier of the removed tool.
113    #[serde(rename = "toolId")]
114    pub tool_id: ToolId,
115    /// Tool name.
116    pub name: String,
117    /// Frame identifier associated with the tool registration.
118    #[serde(rename = "frameId")]
119    pub frame_id: crate::protocol::page::FrameId,
120}
121
122/// Enables the WebMCP domain, allowing events to be sent. Enabling the domain
123/// will trigger a toolsAdded event for all currently registered tools.
124///
125/// Parameters of `WebMCP.enable`.
126#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
127pub struct EnableParams {}
128
129impl crate::typed::Command for EnableParams {
130    const METHOD: &'static str = "WebMCP.enable";
131    type Returns = crate::typed::NoReturns;
132}
133
134/// Disables the WebMCP domain.
135///
136/// Parameters of `WebMCP.disable`.
137#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
138pub struct DisableParams {}
139
140impl crate::typed::Command for DisableParams {
141    const METHOD: &'static str = "WebMCP.disable";
142    type Returns = crate::typed::NoReturns;
143}
144
145/// Invokes a registered tool.
146///
147/// Parameters of `WebMCP.invokeTool`.
148#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
149pub struct InvokeToolParams {
150    /// Frame in which to invoke the tool.
151    #[serde(rename = "frameId")]
152    pub frame_id: crate::protocol::page::FrameId,
153    /// Name of the tool to invoke.
154    #[serde(rename = "toolName")]
155    pub tool_name: String,
156    /// Input parameters for the tool, matching the tool's inputSchema.
157    pub input: serde_json::Value,
158}
159
160/// What `WebMCP.invokeTool` answers with.
161#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
162pub struct InvokeToolReturns {
163    /// Unique identifier for this invocation. Response is sent before tool
164    /// events.
165    #[serde(rename = "invocationId")]
166    pub invocation_id: String,
167}
168
169impl crate::typed::Command for InvokeToolParams {
170    const METHOD: &'static str = "WebMCP.invokeTool";
171    type Returns = InvokeToolReturns;
172}
173
174/// Cancels a pending tool invocation.
175///
176/// Parameters of `WebMCP.cancelInvocation`.
177#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
178pub struct CancelInvocationParams {
179    /// Invocation identifier to cancel.
180    #[serde(rename = "invocationId")]
181    pub invocation_id: String,
182}
183
184impl crate::typed::Command for CancelInvocationParams {
185    const METHOD: &'static str = "WebMCP.cancelInvocation";
186    type Returns = crate::typed::NoReturns;
187}
188
189/// Event fired when new tools are added.
190///
191/// Payload of the `WebMCP.toolsAdded` event.
192#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
193pub struct ToolsAddedEvent {
194    /// Array of tools that were added.
195    pub tools: Vec<Tool>,
196}
197
198impl crate::typed::Event for ToolsAddedEvent {
199    const METHOD: &'static str = "WebMCP.toolsAdded";
200}
201
202/// Event fired when tools are removed.
203///
204/// Payload of the `WebMCP.toolsRemoved` event.
205#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
206pub struct ToolsRemovedEvent {
207    /// Array of tools that were removed.
208    pub tools: Vec<RemovedTool>,
209}
210
211impl crate::typed::Event for ToolsRemovedEvent {
212    const METHOD: &'static str = "WebMCP.toolsRemoved";
213}
214
215/// Event fired when a tool invocation starts.
216///
217/// Payload of the `WebMCP.toolInvoked` event.
218#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
219pub struct ToolInvokedEvent {
220    /// Frame id
221    #[serde(rename = "frameId")]
222    pub frame_id: crate::protocol::page::FrameId,
223    /// Invocation identifier.
224    #[serde(rename = "invocationId")]
225    pub invocation_id: String,
226    /// The input parameters used for the invocation.
227    pub input: String,
228    /// Name of the tool to invoke. Missing if the tool was invoked by its
229    /// identifier, but could not be found (e.g., it was already unregistered), so
230    /// its name could not be recovered.
231    #[serde(rename = "toolName", default, skip_serializing_if = "Option::is_none")]
232    pub tool_name: Option<String>,
233    /// Identifier of the tool to invoke. Missing if the tool was invoked by name,
234    /// but could not be found, so its identifier could not be recovered.
235    #[serde(rename = "toolId", default, skip_serializing_if = "Option::is_none")]
236    pub tool_id: Option<ToolId>,
237}
238
239impl crate::typed::Event for ToolInvokedEvent {
240    const METHOD: &'static str = "WebMCP.toolInvoked";
241}
242
243/// Event fired when a tool invocation completes or fails.
244///
245/// Payload of the `WebMCP.toolResponded` event.
246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
247pub struct ToolRespondedEvent {
248    /// Invocation identifier.
249    #[serde(rename = "invocationId")]
250    pub invocation_id: String,
251    /// Status of the invocation.
252    pub status: InvocationStatus,
253    /// Output or error delivered as delivered to the agent. Missing if `status`
254    /// is anything other than Completed. Note: The output is untrusted and poses
255    /// a prompt injection risk. Clients should treat this as potentially
256    /// malicious user input.
257    #[serde(default, skip_serializing_if = "Option::is_none")]
258    pub output: Option<serde_json::Value>,
259    /// Error text for protocol users.
260    #[serde(rename = "errorText", default, skip_serializing_if = "Option::is_none")]
261    pub error_text: Option<String>,
262    /// The exception object, if the javascript tool threw an error\>
263    #[serde(default, skip_serializing_if = "Option::is_none")]
264    pub exception: Option<crate::protocol::runtime::RemoteObject>,
265}
266
267impl crate::typed::Event for ToolRespondedEvent {
268    const METHOD: &'static str = "WebMCP.toolResponded";
269}