公開日: 2026 年 11 月 26 日
| 商品の解説 | ウェブ | 拡張機能 | Chrome ステータス | インテント |
|---|---|---|---|---|
| GitHub | 表示 | テストの目的 |
このページでは、Chrome のリリース全体における WebMCP の API の追加、動作の変更、互換性を破る変更について説明します。
以前のリリースでのコード例は、各変更時点での API の形状を反映しています。最新の使用方法については、Imperative API と Declarative API のドキュメントをご覧ください。
Chrome 160
新しい Tool インターフェースが RegisteredTool 辞書に置き換わる
PR #348 に続いて、getTools() によって返されるオブジェクトが、RegisteredTool 辞書ではなく、新しい Tool インターフェースのインスタンスになりました。また、ツールを登録したドキュメントのウィンドウを公開する window メンバーは、source と呼ばれるようになりました。この変更は Chrome 160.0.8173.0 から適用されます。
getTools() によって返される各 Tool には、一意の内部 ID があります。executeTool() は、この ID を参照してツールを実行します。これにより、実行中にツールの登録が解除されるなど、いくつかの競合状態が修正されます。また、不透明なオリジンドキュメントによって登録されたツールの実行や、将来のワーカー統合にも備えています。
Tool がインターフェース オブジェクトになったため、次の互換性の変更に注意してください。
- 空のままにすると、
inputSchema、outputSchema、annotationsはundefinedではなくnullになります。 JSON.stringify(tool)は"{}"を返し、スプレッド演算子({...tool})は何もコピーしません。代わりに、必要な属性を明示的に読み取ります。Toolはシリアル化できないため、structuredClone(tool)はスローされます。
次の例では、以前の RegisteredTool 辞書との下位互換性を維持しながら、ツールのプロパティを読み取ります。
const tools = await document.modelContext.getTools();
for (const tool of tools) {
// TODO: Remove `tool.window` fallback when Chrome 160 reaches Stable (January 5, 2027).
const source = tool.source ?? tool.window;
// Use explicit properties rather than JSON.stringify(tool) or {...tool}.
const { name, title, description, origin } = tool;
const inputSchema = tool.inputSchema ?? null;
const outputSchema = tool.outputSchema ?? null;
const annotations = tool.annotations ?? null;
console.log({ name, title, description, origin, inputSchema, outputSchema, annotations, source });
}
Chrome 159
registerTool に outputSchema のサポートを追加
Chrome 159.0.8140.0 以降、document.modelContext.registerTool() はオプションの outputSchema プロパティをサポートしています。inputSchema がパラメータを記述するのと同じ方法で、ツールの戻り値の JSON スキーマを宣言するために使用します。仕様の変更は PR #254 に記載されています。
仕様では、ツールの出力が outputSchema と一致しない場合に executeTool() が失敗するかどうかはまだ定義されていません(問題 #92 を参照)。現時点では、エージェント ハーネスは、各ツールの出力を outputSchema と照合してからモデルに返す必要があります。一致しない場合は、不正な形式のデータではなく、明確な検証エラーをモデルに送信します。例については、webmcp-extension PR #98 をご覧ください。
await document.modelContext.registerTool({
name: "getWeather",
description: "Returns the current weather for a city.",
inputSchema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"]
},
outputSchema: {
type: "object",
properties: {
temperature: { type: "number" },
conditions: { type: "string" }
},
required: ["temperature", "conditions"]
},
async execute({ city }) { /* ... */ }
});
Chrome 156
ontoolactivated と ontoolcancel を document.modelContext に再配置する
Chrome 156.0.8076.0 以降、ontoolactivated イベント ハンドラ プロパティと ontoolcancel イベント ハンドラ プロパティは window から document.modelContext に移動します(PR #245 を参照)。これらのイベント ハンドラは、ツールの実行が開始されたときとキャンセルされたときをそれぞれ示します。
次の例では、以前のイベント ハンドラとの下位互換性を維持しながら、両方のイベントを処理します。
const targetFor = (type, listener, options) =>
(`on${type}` in (document.modelContext ?? {}) ? document.modelContext : window)
.addEventListener(type, listener, options);
targetFor("toolactivated", ({ toolName }) => {
console.log(`Tool "${toolName}" started execution.`);
});
targetFor("toolcancel", ({ toolName }) => {
console.log(`Tool "${toolName}" execution is cancelled.`);
});
ToolAnnotations にデバッグ メンバーを追加
Chrome 156.0.8067.0 以降、ToolAnnotations に新しい debugging メンバーが追加されました。
デベロッパー ツール用のツールを登録する場合は、debugging を true に設定します。これには、検査、フレームワーク テスト、Chrome DevTools の AI アシスタンスが含まれます。これにより、汎用エージェントとエンドユーザー エージェントは、デベロッパー向けのツールをフィルタリングできます。技術的な詳細については、PR #253 をご覧ください。
await document.modelContext.registerTool({
name: "getInternalState",
description: "Returns internal component state for diagnostics and troubleshooting.",
inputSchema: {
type: "object",
properties: { componentId: { type: "string", description: "ID of the component to inspect" } },
required: ["componentId"],
},
execute: ({ componentId }) => {
return myFramework.getState(componentId);
},
annotations: {
readOnlyHint: true,
debugging: true, // Diagnostic tool intended for troubleshooting
},
});
Chrome 155
executeTool の入力引数の型を変更する
PR #246 と PR #251 に続いて、executeTool() の入力引数の型が DOMString から Chrome 155.0.8052.0 のオプションの JavaScript オブジェクトに変更されました。
以前は、executeTool() には文字列化された入力引数が必要でした。オプションの JavaScript オブジェクトを直接受け入れることで、JSON.stringify() を手動で呼び出す必要がなくなり、ToolExecuteCallback の inputObject と整合します。入力オブジェクトが有効な JavaScript オブジェクトでも、JSON 文字列にシリアル化可能でもない場合、executeTool() によって返される Promise が拒否されるようになりました。
次の例では、既存の文字列化された入力引数との下位互換性を維持しながら、入力オブジェクトを渡します。
const inputObject = { answer: 42 };
let result;
try {
result = await document.modelContext.executeTool(myTool, inputObject);
} catch (e) {
// TODO: Remove when executeTool doesn't accept JSON stringified inputArgs in Chrome Stable.
if (e.message.startsWith("Failed to parse input")) {
result = await document.modelContext.executeTool(myTool, JSON.stringify(inputObject));
} else {
throw e;
}
}
RegisteredTool の inputSchema タイプを変更
PR #241 に続き、RegisteredTool の inputSchema プロパティ タイプが DOMString から Chrome 155.0.8051.0 の JavaScript オブジェクトに変更されました。この変更は、Chrome 154.0.8014.0 で最初に導入され、一時的に元に戻されました。
以前は、登録時に ModelContextTool#inputSchema がオブジェクトとして定義されていましたが、getTools() を使用して取得すると、RegisteredTool#inputSchema は文字列化された JSON スキーマ(DOMString)を返していました。この変更により、RegisteredTool#inputSchema が常に、登録時に提供されたスキーマのディープコピーである JavaScript オブジェクトを返すようにすることで、この不整合が解消されます。
次の例では、既存の文字列化された JSON スキーマの下位互換性を維持しながら、inputSchema をオブジェクトとして処理します。
const [tool] = await document.modelContext.getTools();
const inputSchemaObject =
typeof tool.inputSchema === "string" ? JSON.parse(tool.inputSchema) : tool.inputSchema;
Chrome 154
ToolAnnotations に consequentialHint メンバーを追加
Chrome 154.0.8017.0 以降、ToolAnnotations に新しい consequentialHint メンバーが追加されました。
フライトの予約、資金の移動、データの削除など、リスクの高い、不可逆的な、または現実世界のアクションを実行するツールを登録する場合は、consequentialHint を true に設定します。このヒントは、実行前にユーザーの明示的な確認を要求するようエージェントに指示し、意図しないアクションや不正なアクションを防ぐのに役立ちます。技術的な詳細については、問題 #176 をご覧ください。
await document.modelContext.registerTool({
name: 'book_flight',
description: 'Book a flight for the user with confirmed flight details.',
inputSchema: {
type: 'object',
properties: {
flightId: { type: 'string', description: 'ID of the flight to book' },
passengers: { type: 'number', description: 'Number of tickets to purchase' },
},
required: ['flightId', 'passengers'],
},
annotations: {
readOnlyHint: false,
consequentialHint: true,
untrustedContentHint: false,
},
execute: async ({ flightId, passengers }) => {
// Add your flight booking transaction logic here.
return `Booked ${passengers} passenger(s) on flight ${flightId}.`;
},
});
Chrome 153
AbortSignal を ModelContextTool の execute 関数に渡す
Chrome 153.0.8009.0 以降、document.modelContext.registerTool() を使用して登録されたツールの execute 関数は、2 番目の引数で常に signal を受け取るようになり、シグネチャが execute(inputObject, { signal }) に変更されました。技術的な詳細については、問題 #48 と PR #247 をご覧ください。
これにより、ツールはユーザーまたはエージェントによって開始された実行のキャンセルを正常に処理できます。このシグナルを長時間実行される非同期タスクやネットワーク オペレーション(fetch() など)に渡すと、不要な作業を防止し、全体的なリソース管理を改善して、潜在的なリークを回避できます。
また、ツールの登録を解除しても、実行中の実行が自動的にキャンセルされなくなり、コンポーネント フレームワークでツールのライフサイクルを管理する際に予期しない副作用が発生しなくなりました。
次の例では、signal を fetch() リクエストに転送して、実行がキャンセルされたときにネットワーク アクティビティが直ちに中止されるようにしています。宣言型 API の使用方法については、PR #321 をご覧ください。
await document.modelContext.registerTool({
name: "fetch_tool",
description: "Fetch the text content of a URL and stream the response.",
inputSchema: {
type: "object",
properties: {
url: { type: "string", description: "The URL to fetch" },
priority: { type: "string", enum: ["high", "low", "auto"] },
},
required: ["url"],
},
execute: async ({ url, priority }, { signal }) => {
// Abort the fetch request when tool execution is aborted.
const response = await fetch(url, { priority, signal });
const stream = response.body.pipeThrough(new TextDecoderStream());
for await (const chunk of stream) {
document.querySelector("pre").textContent += chunk;
}
return "Success";
},
});
Chrome 152
navigator.modelContext を削除
Chrome 150 で非推奨となった navigator.modelContext は、Chrome 152.0.7943.0 で削除されました。代わりに document.modelContext を使用してください
Chrome 151
registerTool から Promise を返す
document.modelContext.registerTool() メソッドは、Chrome 151.0.7922.0 以降で Promise を返します。この変更(問題 #175 で詳しく説明)は、クロスオリジン iframe 統合により、フレームツリー全体でツールを共有できるため、登録が基本的に非同期になるために必要です。Promise は、ツールが他のドキュメントの getTools() で実際に使用可能になった場合にのみ解決されます。これにより、API の進化に伴うエラー処理と上位互換性が向上します。
次の例に示す非同期パターンを使用するようにコードを更新します。具体的な例については、PR #228 で WebMCP デモがどのように更新されたかをご覧ください。
try {
await document.modelContext.registerTool(myTool);
} catch (e) {
console.error('Tool registration failed:', e);
}
Chrome 150
navigator.modelContext を非推奨にし、document.modelContext を推奨
ツールが実質的にドキュメント単位であることを踏まえ、WebML CG は modelContext ゲッターを Navigator インターフェースから Document インターフェースに移動することに合意しました。技術的な詳細については、問題 #173 と PR #184 をご覧ください。
navigator.modelContext は Chrome 150.0.7861.0 で非推奨となり、その後 Chrome 152 で削除されました。代わりに document.modelContext を使用してください。
次の機能検出パターンは、移行前後の Chrome リリース間で互換性を維持します。実用的な例については、PR #189 で WebMCP デモがどのように更新されたかをご覧ください。
const modelContext = document.modelContext || navigator.modelContext;
if (modelContext) {
// Register tools...
}
Chrome 149
ToolAnnotations に untrustedContentHint メンバーを追加
Chrome 149.0.7810.0 以降、ToolAnnotations に新しい untrustedContentHint メンバーが追加されました。
ツールが外部ソースまたは未検証のソースからのデータを処理する場合は、untrustedContentHint を true に明示的に設定して、ツールの出力に、ツールを登録する作成者の観点から信頼できないデータが含まれていることを示します。技術的な詳細については、問題 #136 をご覧ください。
navigator.modelContext.registerTool({
name: "addTodo",
description: "Add a new item to the todo list",
inputSchema: {
type: "object",
properties: { text: { type: "string" } },
},
execute: ({ text }) => {
// You should handle the persistence logic here (omitted for demo)
return `Added todo: ${text}`;
},
annotations: { readOnlyHint: false, untrustedContentHint: true },
});
Chrome 148
registerTool の unregisterTool を AbortSignal に置き換え
WebML CG は、ツールの登録解除には、イベント リスナーの登録解除と同じレベルの所有権が必要であることに同意しました。スクリプトが、作成していないツールを誤って、または悪意を持って登録解除しないように、unregisterTool() は削除されています。
Chrome 148.0.7757.0 以降、registerTool() はオプションの AbortSignal をサポートしています。このシグナルを中止すると、ツールの登録解除がトリガーされます。技術的な詳細については、PR #147 をご覧ください。
リリース間の互換性を維持するには、次の例のようなラッパーを使用します。PR #104 で、WebMCP デモの更新方法を確認することもできます。
const controller = new AbortController();
navigator.modelContext.registerTool(myTool, { signal: controller.signal });
// Unregister tool later...
navigator.modelContext.unregisterTool?.(myTool.name);
controller.abort();
toolparamtitle 属性を削除する
Chrome 148.0.7730.0 以降、toolparamtitle 属性は削除されています。WebML CG の PR #76 で説明されているように、合成された JSON スキーマの title フィールドに寄与するものはなくなりました。この目的で標準の HTML <label> 要素を使用することは、将来的に可能になる可能性があります。
Chrome 147
provideContext と clearContext を削除する
WebMCP API の形状を改善するため、provideContext() メソッドと clearContext() メソッドは Chrome 147.0.7721.0 から削除されました。この変更は、問題 #101 で詳しく説明されています。この変更により、次の 2 つの主なアーキテクチャ上の問題に対処できます。
- 新しいツールを登録する前に既存のツールをクリアすることで、
provideContext()はセキュリティ リスクをもたらしていました。サードパーティのスクリプトが意図せず、または悪意を持って公式ツールを上書きし、ユーザー エージェントの操作を乗っ取る可能性がありました。 - フィードバックによると、「すべて削除」パターンはウェブ API では一般的ではありません。デベロッパーは、
addEventListenerと同様の追加モデルを好んでいました。これにより、スクリプトは独自の登録を個別に管理できます。
よりきめ細かく安全な制御を維持するには、registerTool() と unregisterTool()(Chrome 148 で AbortSignal に置き換えられます)を使用します。