Surface callerOrigin on ModelContextClient passed to ToolExecuteCallback
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- html
- 领域
- api
调研方向
Start with the ModelContextClient interface and the tool execution steps in the current WebMCP spec, then trace how the existing exposedTo allowlist check computes the invoking origin. Update the IDL and execute algorithm together, ensuring native-agent invocations produce null. The issue identifies the relevant spec sections and related issues, but implementation may require coordination around the unresolved native-agent exposure question.
由索引模型根据 Issue 内容生成。
描述
Background
PR #179 adds the toolchange event and establishes the cross-origin tool discovery model: a tool registered with exposedTo: ["https://agent.example"] becomes visible to agent.example via toolchange, and that document can subsequently invoke it. This closes the consumer side of the cross-origin relationship the permitted origin learns when tools become available.
The gap
The registrant side has no equivalent signal. When agent.example invokes the tool, the current ToolExecuteCallback fires:
webidlcallback ToolExecuteCallback = Promise (object input, ModelContextClient client);
The client object carries no information about which origin triggered the call. This is consequential when exposedTo lists multiple origins:
jsdocument.modelContext.registerTool({
name: "get-record",
description: "Fetches a record by ID",
inputSchema: { type: "object", properties: { id: { type: "string" } } },
execute(input, client) {
// client.callerOrigin does not exist
// both callers below receive identical behavior
return getFullRecord(input.id);
}
}, {
exposedTo: [
"https://internal-agent.example",
"https://partner-agent.example"
]
});
The browser already enforces that only listed origins may invoke the tool the exposedTo allowlist check happens during IPC routing before execute() fires. But the result of that check which specific listed origin passed is not forwarded to the callback. The registrant cannot observe it from any other available surface.
The exposedTo declaration creates a named, multi-party relationship at registration time. Without caller identity at invocation time, the registrant cannot implement differentiated behavior within that relationship serving different response shapes to different permitted callers, or making dynamic decisions based on which party in an established relationship is acting.
Proposal
Add callerOrigin as a USVString? attribute on ModelContextClient:
webidlinterface ModelContextClient {
// ... existing members ...
readonly attribute USVString? callerOrigin;
};
callerOrigin is the serialization of the invoking document's origin, produced by running the serialize an origin algorithm. It is null when the invoking agent is a browser's agent.
The browser already computes this value during the exposedTo allowlist check it is the target origin in the tool is visible to an origin algorithm. This proposal forwards it to the callback rather than discarding it.
Usage:
jsexecute(input, client) {
if (client.callerOrigin === "https://partner-agent.example") {
return { summary: getSummary(input.id) };
}
return { full: getFullRecord(input.id) };
}
Precedent
MessageEvent.origin (HTML §9.4.3) is the closest parallel. In postMessage, the browser enforces origin-based routing; MessageEvent.origin lets the receiver differentiate among already-permitted senders rather than gate access. The motivation here is identical: exposedTo is the allowlist, the browser enforces it, and callerOrigin lets the registrant distinguish which permitted party acted.
Spec delta
The change touches two places in the current spec:
§4.2.3 ModelContextClient interface add the callerOrigin attribute to the IDL and define its value as the serialized origin of the invoking document, set by the browser when constructing the ModelContextClient instance passed to execute.
§3 tool definition / execute steps the execute steps for imperatively-registered tools (currently "steps that invoke the supplied ToolExecuteCallback") need to specify that the ModelContextClient passed to the callback is constructed with callerOrigin set to the serialized origin of the invoking document at the point the allowlist check passes.
The native-agent case
For tools invoked by a browser's agent (no explicit exposedTo, or invoked natively), callerOrigin should be null.
Rationale: a browser's agent has no document origin in the sense the web platform uses that term. Using null (rather than a sentinel string like "browser") is the correct type-safe choice it avoids introducing an unstructured magic string into an otherwise origin-typed field, it is consistent with how the platform handles absent origins elsewhere (e.g. opaque origins serializing to "null" is already a known footgun, so we should not add another string consumers need to guard against), and it gives registrants a clean boolean branch: if (client.callerOrigin === null) means native agent. This does intersect with the open question in the explainer about native-agent exposure and should be resolved in coordination with that discussion.
Related issues
- #179 adds toolchange and the cross-origin discovery model this proposal's registrant-side signal completes
- #178 ModelContextClient interface definition; callerOrigin is an addition to this interface
- #180 cross-origin invocation mechanics; the IPC routing path that already computes the value being proposed here
- #159 / #160 multi-origin exposedTo use cases that motivated tiered tool access and are the primary driver for needing caller identity at invocation time
- 主要语言
- Bikeshed
- 星标
- 4.7k
- 派生
- 328
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 16
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
webmachinelearning/webmcp 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 72/100
webmachinelearning/webmcp#360 ·
维护者通常 1 天内回复
-
Say how an agent should weigh annotations that the page wrote about itself可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
webmachinelearning/webmcp#353 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
webmachinelearning/webmcp#343 · 1 个 reaction ·
维护者通常 1 天内回复
-
Agenda+ i18n-tracker
难度 2/5 1-3 小时 新手友好度 75/100
webmachinelearning/webmcp#273 · 3 条评论 ·
维护者通常 1 天内回复
-
a11y-tracker Agenda+
难度 2/5 1-3 小时 新手友好度 67/100
webmachinelearning/webmcp#272 · 4 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
查看 webmachinelearning/webmcp 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
ansys/pyansys-common-mcp#213 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
priority:P1 status:in-review type:bug
难度 2/5 1-3 小时 新手友好度 75/100
randomparity/kdive#3317 · 1 条评论 ·
维护者通常 1 天内回复
-
bug medium-priority mobile
难度 2/5 1-3 小时 新手友好度 76/100
lognorman20/monaco#6229 ·