Skip to content

Commit a1bf6d8

Browse files
jpagnuccoChromium LUCI CQ
authored andcommitted
[WebMCP] Implement consequentialHint annotation
This change implements the consequentialHint annotation for WebMCP script tools (webmachinelearning/webmcp#176), matching the existing untrustedContentHint implementation. When a tool is registered with consequentialHint: true, this hint is plumbed through Blink's script tool declarations, Mojom IPC annotations, the ScriptTool actor layer, and the Chrome DevTools Protocol (CDP) WebMCP domain. This allows the browser and DevTools to identify tools that perform consequential actions (e.g., booking flights, transferring money). Bug: 520004016 Test: ModelContextTest.* unit tests This change implements the consequentialHint annotation for WebMCP script tools, matching the existing untrustedContentHint implementation. When a tool is registered with consequentialHint: true, this hint is plumbed through Blink's script tool declarations, Mojom IPC annotations, the ScriptTool actor layer, and the Chrome DevTools Protocol (CDP) WebMCP domain. This allows the browser and DevTools to identify tools that perform consequential actions (e.g., booking flights, transferring money). Bug: 520004016 Test: ModelContextTest.* unit tests This change implements the consequentialHint annotation for WebMCP script tools, see: webmachinelearning/webmcp#176. Bug: 520004016 Test: ModelContextTest.* unit tests Change-Id: I9afce4e86ef9f93f860b7ba80740cb08ed7c3f36 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7985884 Reviewed-by: Dominic Farolino <[email protected]> Reviewed-by: Daniel Cheng <[email protected]> Commit-Queue: Julia Pagnucco <[email protected]> Cr-Commit-Position: refs/heads/main@{#1684148}
1 parent 698ef05 commit a1bf6d8

16 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎chrome/renderer/actor/script_tool.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ mojom::ActionResultPtr OnToolExecuted(
6161
script_tool_response->tool->name = name;
6262
script_tool_response->tool->description = tool->description.Utf8();
6363
script_tool_response->tool->input_schema = tool->input_schema.Utf8();
64-
if (tool->read_only.has_value() || tool->untrusted_content.has_value()) {
64+
if (tool->read_only.has_value() || tool->untrusted_content.has_value() ||
65+
tool->consequential.has_value()) {
6566
script_tool_response->tool->annotations =
6667
blink::mojom::ScriptToolAnnotations::New();
6768
if (tool->read_only.has_value()) {
@@ -72,6 +73,10 @@ mojom::ActionResultPtr OnToolExecuted(
7273
script_tool_response->tool->annotations->untrusted_content =
7374
tool->untrusted_content.value();
7475
}
76+
if (tool->consequential.has_value()) {
77+
script_tool_response->tool->annotations->consequential =
78+
tool->consequential.value();
79+
}
7580
}
7681
if (!response->IsEmpty()) {
7782
script_tool_response->result = response->Utf8();

‎third_party/blink/public/devtools_protocol/domains/WebMCP.pdl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ experimental domain WebMCP
1717
optional boolean readOnly
1818
# A hint indicating that the tool output may contain untrusted content, ex: UGC, 3rd party data.
1919
optional boolean untrustedContent
20+
# A hint indicating that executing the tool will result in consequential actions, ex: booking a flight, transferring money.
21+
optional boolean consequential
2022
# If the declarative tool was declared with the autosubmit attribute.
2123
optional boolean autosubmit
2224

‎third_party/blink/public/mojom/content_extraction/script_tools.mojom‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import "mojo/public/mojom/base/unguessable_token.mojom";
1313
struct ScriptToolAnnotations {
1414
bool read_only;
1515
bool untrusted_content;
16+
bool consequential;
1617
};
1718

1819
// See ModelContextTool in model_context_tool.idl for details of

‎third_party/blink/public/web/web_script_tool_types.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct WebScriptToolDeclaration {
4343
WebString input_schema;
4444
std::optional<bool> read_only;
4545
std::optional<bool> untrusted_content;
46+
std::optional<bool> consequential;
4647
};
4748

4849
using WebScriptToolResultCallback =

‎third_party/blink/renderer/core/exported/web_document.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ bool WebDocument::ExecuteScriptTool(
444444
web_tool_declaration->read_only = script_tool_declaration->read_only;
445445
web_tool_declaration->untrusted_content =
446446
script_tool_declaration->untrusted_content;
447+
web_tool_declaration->consequential =
448+
script_tool_declaration->consequential;
447449
}
448450
return model_context->ExecuteTool(
449451
invocation_id, name, input_arguments,

‎third_party/blink/renderer/core/inspector/inspector_web_mcp_agent.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ std::unique_ptr<protocol::WebMCP::Annotation> BuildAnnotations(
7171
if (annotations) {
7272
builder.setReadOnly(annotations->read_only);
7373
builder.setUntrustedContent(annotations->untrusted_content);
74+
builder.setConsequential(annotations->consequential);
7475
has_annotations = true;
7576
}
7677
if (element && element->FastHasAttribute(html_names::kToolautosubmitAttr)) {

‎third_party/blink/renderer/core/script_tools/model_context.cc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ ScriptPromise<IDLUndefined> ModelContext::registerTool(
460460
CHECK(tool->annotations()->hasUntrustedContentHint());
461461
script_tool->annotations->untrusted_content =
462462
tool->annotations()->untrustedContentHint();
463+
CHECK(tool->annotations()->hasConsequentialHint());
464+
script_tool->annotations->consequential =
465+
tool->annotations()->consequentialHint();
463466
}
464467

465468
auto* tool_data = MakeGarbageCollected<ToolData>(
@@ -507,6 +510,7 @@ std::optional<ScriptToolDeclaration> ModelContext::GetScriptToolDeclaration(
507510
if (script_tool.annotations) {
508511
declaration.read_only = script_tool.annotations->read_only;
509512
declaration.untrusted_content = script_tool.annotations->untrusted_content;
513+
declaration.consequential = script_tool.annotations->consequential;
510514
}
511515
return declaration;
512516
}
@@ -1049,6 +1053,7 @@ void ModelContext::OnGetScriptToolsCompleted(
10491053
auto* annotations = ToolAnnotations::Create();
10501054
annotations->setReadOnlyHint(t->annotations->read_only);
10511055
annotations->setUntrustedContentHint(t->annotations->untrusted_content);
1056+
annotations->setConsequentialHint(t->annotations->consequential);
10521057
result->setAnnotations(annotations);
10531058
}
10541059

‎third_party/blink/renderer/core/script_tools/model_context_test.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ TEST_F(ModelContextTest, ExecuteToolReturnsObject) {
284284
},
285285
annotations: {
286286
readOnlyHint: true,
287-
untrustedContentHint: true
287+
untrustedContentHint: true,
288+
consequentialHint: false,
288289
},
289290
});
290291
</script>

‎third_party/blink/renderer/core/script_tools/model_context_tool.idl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dictionary ModelContextTool {
2020
dictionary ToolAnnotations {
2121
boolean readOnlyHint = false;
2222
boolean untrustedContentHint = false;
23+
boolean consequentialHint = false;
2324
};
2425

2526
dictionary ToolExecuteCallbackOptions {

‎third_party/blink/renderer/core/script_tools/script_tool_types.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct ScriptToolDeclaration {
4242
String input_schema;
4343
std::optional<bool> read_only;
4444
std::optional<bool> untrusted_content;
45+
std::optional<bool> consequential;
4546
};
4647

4748
using ScriptToolExecutedCallback =

0 commit comments

Comments
 (0)