[{"data":1,"prerenderedAt":1350},["ShallowReactive",2],{"blog-webmcp-in-practice-registering-browser-tools":3,"blog-webmcp-in-practice-registering-browser-tools-favor-of":1349},{"id":4,"title":5,"body":6,"cover_image":1331,"date":1332,"description":1333,"extension":1334,"meta":1335,"navigation":201,"path":1337,"seo":1338,"stem":1339,"tags":1340,"type":1347,"__hash__":1348},"blog\u002Fblog\u002Fwebmcp-in-practice-registering-browser-tools.md","Registering Browser AI Tools With WebMCP and TypeScript",{"type":7,"value":8,"toc":1323},"minimark",[9,13,40,49,56,61,81,84,107,124,128,144,157,164,713,728,732,739,1026,1032,1036,1043,1192,1202,1206,1223,1262,1281,1290,1294,1319],[10,11,5],"h1",{"id":12},"registering-browser-ai-tools-with-webmcp-and-typescript",[14,15,16,17,21,22,29,30,35,36,39],"p",{},"When a browser extension or built-in assistant wants to help a user inside a web app, it normally falls back to reading screenshots or walking the DOM tree and clicking buttons by CSS selector. Developers usually handle that by adding extra ",[18,19,20],"code",{},"data-testid"," attributes or maintaining a separate backend ",[23,24,28],"a",{"href":25,"rel":26},"https:\u002F\u002Fmodelcontextprotocol.io\u002F",[27],"nofollow","Model Context Protocol (MCP)"," server that duplicates half of the front-end's filter and form state. In this guide I walk through the client-side alternative: registering typed JavaScript tools directly inside your Vue or TypeScript app using ",[23,31,34],{"href":32,"rel":33},"https:\u002F\u002Fgithub.com\u002Fwebmachinelearning\u002Fwebmcp",[27],"WebMCP"," and ",[18,37,38],{},"document.modelContext",".",[14,41,42,43,48],{},"If you are looking for the higher-level product and governance trade-offs rather than the browser code, I also wrote a companion architecture guide on ",[23,44,47],{"href":45,"rel":46},"https:\u002F\u002Finnovi.pro\u002Fblog\u002Fmcp-vs-webmcp-architecture-guide",[27],"when to use backend MCP servers vs. browser WebMCP tools"," over on Innovi Pro.",[14,50,51],{},[52,53],"img",{"alt":54,"src":55},"Client tool lifecycle in Vue: view mounts with AbortController, registers a schema on document.modelContext, browser agent queries getTools() and invokes execute(), and onBeforeUnmount calls controller.abort() when leaving the route.","\u002Fimages\u002Fblog\u002Fwebmcp-tool-lifecycle-poster.png",[57,58,60],"h2",{"id":59},"how-webmcp-turns-existing-ui-logic-into-tools","How WebMCP turns existing UI logic into tools",[14,62,63,64,69,70,72,73,76,77,80],{},"The ",[23,65,68],{"href":66,"rel":67},"https:\u002F\u002Fwebmachinelearning.github.io\u002Fwebmcp\u002F",[27],"W3C WebMCP specification draft"," exposes ",[18,71,38],{},", which works like a lightweight in-page tool registry. Rather than forcing an agent to guess which dropdown opens a date filter, your page calls ",[18,74,75],{},"document.modelContext.registerTool()"," with a name, a plain description, a JSON Schema for arguments, and an ",[18,78,79],{},"execute"," callback that calls the exact client-side function your button already invokes.",[14,82,83],{},"Because the callback runs inside the active tab, two annoying integration problems disappear:",[85,86,87,98],"ol",{},[88,89,90,94,95,97],"li",{},[91,92,93],"strong",{},"You keep your existing auth session."," API requests inside ",[18,96,79],{}," carry the user's normal cookies or bearer headers, so you do not have to stand up a separate OAuth bridge just to let an assistant filter a table.",[88,99,100,103,104,106],{},[91,101,102],{},"The UI stays in sync with the agent."," When ",[18,105,79],{}," updates reactive state in Vue or React, the user watches the interface change immediately and stays in control before any final checkout or form submission happens.",[14,108,109,110,113,114,35,117,120,121,123],{},"The repository also hosts a separate exploratory explainer for declarative HTML ",[18,111,112],{},"\u003Cform>"," attributes such as ",[18,115,116],{},"toolname",[18,118,119],{},"tooldescription",", though the formal specification focuses on the imperative ",[18,122,38],{}," API because real single-page apps need tools to appear and disappear dynamically as routes change.",[57,125,127],{"id":126},"progressive-enhancement-with-a-vue-composable","Progressive enhancement with a Vue composable",[14,129,130,131,136,137,139,140,143],{},"According to the ",[23,132,135],{"href":133,"rel":134},"https:\u002F\u002Fgithub.com\u002Fwebmachinelearning\u002Fwebmcp\u002Fblob\u002Fmain\u002Fimplementation-status.md",[27],"WebMCP implementation status",", Origin Trials are currently running in Chrome 149 and Edge 150 alongside support in ChatGPT Desktop, while Mozilla and WebKit still have open standards positions. That means ",[18,138,38],{}," will be ",[18,141,142],{},"undefined"," for many visitors today, so every registration path needs a quiet feature check and cleanup hook.",[14,145,146,147,150,151,156],{},"TypeScript definitions ship in the ",[18,148,149],{},"webmcp-types"," package referenced in the official README, or you can declare the small interface surface locally if you want zero extra runtime dependencies. The most important design rule from ",[23,152,155],{"href":153,"rel":154},"https:\u002F\u002Fdeveloper.chrome.com\u002Fdocs\u002Fai\u002Fwebmcp",[27],"Chrome's WebMCP documentation"," is keeping the registered tool list small and scoped to the active screen, because every schema eats prompt tokens and increases tool-selection mistakes.",[14,158,159,160,163],{},"Here is a clean Vue 3 or Nuxt composable that registers a tool when a component mounts and unregisters it automatically via ",[18,161,162],{},"AbortController"," when the user navigates away:",[165,166,171],"pre",{"className":167,"code":168,"language":169,"meta":170,"style":170},"language-ts shiki shiki-themes github-dark-default","import { onBeforeUnmount, onMounted } from \"vue\";\n\ninterface WebMcpTool {\n  name: string;\n  description: string;\n  inputSchema?: Record\u003Cstring, unknown>;\n  execute: (input: Record\u003Cstring, unknown>) => Promise\u003Cunknown> | unknown;\n}\n\ninterface ModelContextApi {\n  registerTool: (\n    tool: WebMcpTool,\n    options?: { signal?: AbortSignal; exposedTo?: string[] },\n  ) => Promise\u003Cvoid>;\n}\n\nexport function useWebMcpTool(tool: WebMcpTool) {\n  let controller: AbortController | null = null;\n\n  onMounted(async () => {\n    const ctx = (document as Document & { modelContext?: ModelContextApi })\n      .modelContext;\n    if (!ctx) return;\n\n    controller = new AbortController();\n    try {\n      await ctx.registerTool(tool, { signal: controller.signal });\n    } catch (err) {\n      \u002F\u002F Permissions-Policy or cross-origin restrictions reject with NotAllowedError.\n      console.warn(`WebMCP registration skipped for ${tool.name}:`, err);\n    }\n  });\n\n  onBeforeUnmount(() => {\n    controller?.abort();\n    controller = null;\n  });\n}\n","ts","",[18,172,173,196,203,216,231,243,270,321,327,332,342,353,366,398,415,420,425,450,477,482,500,535,541,560,565,582,590,605,617,624,651,657,663,668,681,692,703,708],{"__ignoreMap":170},[174,175,178,182,186,189,193],"span",{"class":176,"line":177},"line",1,[174,179,181],{"class":180},"suJrU","import",[174,183,185],{"class":184},"sZEs4"," { onBeforeUnmount, onMounted } ",[174,187,188],{"class":180},"from",[174,190,192],{"class":191},"s9uIt"," \"vue\"",[174,194,195],{"class":184},";\n",[174,197,199],{"class":176,"line":198},2,[174,200,202],{"emptyLinePlaceholder":201},true,"\n",[174,204,206,209,213],{"class":176,"line":205},3,[174,207,208],{"class":180},"interface",[174,210,212],{"class":211},"sQhOw"," WebMcpTool",[174,214,215],{"class":184}," {\n",[174,217,219,222,225,229],{"class":176,"line":218},4,[174,220,221],{"class":211},"  name",[174,223,224],{"class":180},":",[174,226,228],{"class":227},"sFSAA"," string",[174,230,195],{"class":184},[174,232,234,237,239,241],{"class":176,"line":233},5,[174,235,236],{"class":211},"  description",[174,238,224],{"class":180},[174,240,228],{"class":227},[174,242,195],{"class":184},[174,244,246,249,252,255,258,261,264,267],{"class":176,"line":245},6,[174,247,248],{"class":211},"  inputSchema",[174,250,251],{"class":180},"?:",[174,253,254],{"class":211}," Record",[174,256,257],{"class":184},"\u003C",[174,259,260],{"class":227},"string",[174,262,263],{"class":184},", ",[174,265,266],{"class":227},"unknown",[174,268,269],{"class":184},">;\n",[174,271,273,277,279,282,285,287,289,291,293,295,297,300,303,306,308,310,313,316,319],{"class":176,"line":272},7,[174,274,276],{"class":275},"sc3cj","  execute",[174,278,224],{"class":180},[174,280,281],{"class":184}," (",[174,283,284],{"class":211},"input",[174,286,224],{"class":180},[174,288,254],{"class":211},[174,290,257],{"class":184},[174,292,260],{"class":227},[174,294,263],{"class":184},[174,296,266],{"class":227},[174,298,299],{"class":184},">) ",[174,301,302],{"class":180},"=>",[174,304,305],{"class":211}," Promise",[174,307,257],{"class":184},[174,309,266],{"class":227},[174,311,312],{"class":184},"> ",[174,314,315],{"class":180},"|",[174,317,318],{"class":227}," unknown",[174,320,195],{"class":184},[174,322,324],{"class":176,"line":323},8,[174,325,326],{"class":184},"}\n",[174,328,330],{"class":176,"line":329},9,[174,331,202],{"emptyLinePlaceholder":201},[174,333,335,337,340],{"class":176,"line":334},10,[174,336,208],{"class":180},[174,338,339],{"class":211}," ModelContextApi",[174,341,215],{"class":184},[174,343,345,348,350],{"class":176,"line":344},11,[174,346,347],{"class":275},"  registerTool",[174,349,224],{"class":180},[174,351,352],{"class":184}," (\n",[174,354,356,359,361,363],{"class":176,"line":355},12,[174,357,358],{"class":211},"    tool",[174,360,224],{"class":180},[174,362,212],{"class":211},[174,364,365],{"class":184},",\n",[174,367,369,372,374,377,380,382,385,388,391,393,395],{"class":176,"line":368},13,[174,370,371],{"class":211},"    options",[174,373,251],{"class":180},[174,375,376],{"class":184}," { ",[174,378,379],{"class":211},"signal",[174,381,251],{"class":180},[174,383,384],{"class":211}," AbortSignal",[174,386,387],{"class":184},"; ",[174,389,390],{"class":211},"exposedTo",[174,392,251],{"class":180},[174,394,228],{"class":227},[174,396,397],{"class":184},"[] },\n",[174,399,401,404,406,408,410,413],{"class":176,"line":400},14,[174,402,403],{"class":184},"  ) ",[174,405,302],{"class":180},[174,407,305],{"class":211},[174,409,257],{"class":184},[174,411,412],{"class":227},"void",[174,414,269],{"class":184},[174,416,418],{"class":176,"line":417},15,[174,419,326],{"class":184},[174,421,423],{"class":176,"line":422},16,[174,424,202],{"emptyLinePlaceholder":201},[174,426,428,431,434,437,440,443,445,447],{"class":176,"line":427},17,[174,429,430],{"class":180},"export",[174,432,433],{"class":180}," function",[174,435,436],{"class":275}," useWebMcpTool",[174,438,439],{"class":184},"(",[174,441,442],{"class":211},"tool",[174,444,224],{"class":180},[174,446,212],{"class":211},[174,448,449],{"class":184},") {\n",[174,451,453,456,459,461,464,467,470,473,475],{"class":176,"line":452},18,[174,454,455],{"class":180},"  let",[174,457,458],{"class":184}," controller",[174,460,224],{"class":180},[174,462,463],{"class":211}," AbortController",[174,465,466],{"class":180}," |",[174,468,469],{"class":227}," null",[174,471,472],{"class":180}," =",[174,474,469],{"class":227},[174,476,195],{"class":184},[174,478,480],{"class":176,"line":479},19,[174,481,202],{"emptyLinePlaceholder":201},[174,483,485,488,490,493,496,498],{"class":176,"line":484},20,[174,486,487],{"class":275},"  onMounted",[174,489,439],{"class":184},[174,491,492],{"class":180},"async",[174,494,495],{"class":184}," () ",[174,497,302],{"class":180},[174,499,215],{"class":184},[174,501,503,506,509,511,514,517,520,523,525,528,530,532],{"class":176,"line":502},21,[174,504,505],{"class":180},"    const",[174,507,508],{"class":227}," ctx",[174,510,472],{"class":180},[174,512,513],{"class":184}," (document ",[174,515,516],{"class":180},"as",[174,518,519],{"class":211}," Document",[174,521,522],{"class":180}," &",[174,524,376],{"class":184},[174,526,527],{"class":211},"modelContext",[174,529,251],{"class":180},[174,531,339],{"class":211},[174,533,534],{"class":184}," })\n",[174,536,538],{"class":176,"line":537},22,[174,539,540],{"class":184},"      .modelContext;\n",[174,542,544,547,549,552,555,558],{"class":176,"line":543},23,[174,545,546],{"class":180},"    if",[174,548,281],{"class":184},[174,550,551],{"class":180},"!",[174,553,554],{"class":184},"ctx) ",[174,556,557],{"class":180},"return",[174,559,195],{"class":184},[174,561,563],{"class":176,"line":562},24,[174,564,202],{"emptyLinePlaceholder":201},[174,566,568,571,574,577,579],{"class":176,"line":567},25,[174,569,570],{"class":184},"    controller ",[174,572,573],{"class":180},"=",[174,575,576],{"class":180}," new",[174,578,463],{"class":275},[174,580,581],{"class":184},"();\n",[174,583,585,588],{"class":176,"line":584},26,[174,586,587],{"class":180},"    try",[174,589,215],{"class":184},[174,591,593,596,599,602],{"class":176,"line":592},27,[174,594,595],{"class":180},"      await",[174,597,598],{"class":184}," ctx.",[174,600,601],{"class":275},"registerTool",[174,603,604],{"class":184},"(tool, { signal: controller.signal });\n",[174,606,608,611,614],{"class":176,"line":607},28,[174,609,610],{"class":184},"    } ",[174,612,613],{"class":180},"catch",[174,615,616],{"class":184}," (err) {\n",[174,618,620],{"class":176,"line":619},29,[174,621,623],{"class":622},"sH3jZ","      \u002F\u002F Permissions-Policy or cross-origin restrictions reject with NotAllowedError.\n",[174,625,627,630,633,635,638,640,642,645,648],{"class":176,"line":626},30,[174,628,629],{"class":184},"      console.",[174,631,632],{"class":275},"warn",[174,634,439],{"class":184},[174,636,637],{"class":191},"`WebMCP registration skipped for ${",[174,639,442],{"class":184},[174,641,39],{"class":191},[174,643,644],{"class":184},"name",[174,646,647],{"class":191},"}:`",[174,649,650],{"class":184},", err);\n",[174,652,654],{"class":176,"line":653},31,[174,655,656],{"class":184},"    }\n",[174,658,660],{"class":176,"line":659},32,[174,661,662],{"class":184},"  });\n",[174,664,666],{"class":176,"line":665},33,[174,667,202],{"emptyLinePlaceholder":201},[174,669,671,674,677,679],{"class":176,"line":670},34,[174,672,673],{"class":275},"  onBeforeUnmount",[174,675,676],{"class":184},"(() ",[174,678,302],{"class":180},[174,680,215],{"class":184},[174,682,684,687,690],{"class":176,"line":683},35,[174,685,686],{"class":184},"    controller?.",[174,688,689],{"class":275},"abort",[174,691,581],{"class":184},[174,693,695,697,699,701],{"class":176,"line":694},36,[174,696,570],{"class":184},[174,698,573],{"class":180},[174,700,469],{"class":227},[174,702,195],{"class":184},[174,704,706],{"class":176,"line":705},37,[174,707,662],{"class":184},[174,709,711],{"class":176,"line":710},38,[174,712,326],{"class":184},[14,714,715,716,719,720,723,724,727],{},"Wrapping registration inside ",[18,717,718],{},"onMounted"," avoids server-side rendering mismatches in Nuxt where ",[18,721,722],{},"document"," does not exist on the Cloudflare Worker or Node server, and aborting the signal inside ",[18,725,726],{},"onBeforeUnmount"," guarantees stale route tools vanish from the browser registry immediately.",[57,729,731],{"id":730},"wiring-a-real-interactive-tool-without-breaking-manual-users","Wiring a real interactive tool without breaking manual users",[14,733,734,735,738],{},"Suppose you have an interactive cost calculator or clinical schedule filter where a user normally drags three sliders or checks two boxes. You can keep the standard form inputs intact for everyone, then attach a single composable call inside ",[18,736,737],{},"\u003Cscript setup>"," so WebMCP-capable browsers can inspect and set those same reactive refs:",[165,740,742],{"className":167,"code":741,"language":169,"meta":170,"style":170},"useWebMcpTool({\n  name: \"compare_saas_vs_custom\",\n  description:\n    \"Updates the 5-year SaaS vs. custom cost calculator inputs and returns the estimated crossover month.\",\n  inputSchema: {\n    type: \"object\",\n    properties: {\n      startUsers: { type: \"number\", description: \"Active users in month 1\" },\n      endUsers: { type: \"number\", description: \"Projected users at year 3\" },\n      monthlyPerUser: {\n        type: \"number\",\n        description: \"Base SaaS price per seat in USD\",\n      },\n    },\n    required: [\"startUsers\", \"endUsers\", \"monthlyPerUser\"],\n  },\n  async execute(input) {\n    startUsers.value = Number(input.startUsers);\n    endUsers.value = Number(input.endUsers);\n    monthlyPerUser.value = Number(input.monthlyPerUser);\n\n    return {\n      content: [\n        {\n          type: \"text\",\n          text: JSON.stringify({\n            saasTotal: saas5YearTotal.value,\n            customTotal: custom5YearTotal.value,\n            crossoverMonth: crossoverMonth.value,\n          }),\n        },\n      ],\n    };\n  },\n});\n",[18,743,744,752,762,767,774,779,789,794,811,825,830,839,849,854,859,880,885,899,912,924,936,940,947,952,957,967,982,987,992,997,1002,1007,1012,1017,1021],{"__ignoreMap":170},[174,745,746,749],{"class":176,"line":177},[174,747,748],{"class":275},"useWebMcpTool",[174,750,751],{"class":184},"({\n",[174,753,754,757,760],{"class":176,"line":198},[174,755,756],{"class":184},"  name: ",[174,758,759],{"class":191},"\"compare_saas_vs_custom\"",[174,761,365],{"class":184},[174,763,764],{"class":176,"line":205},[174,765,766],{"class":184},"  description:\n",[174,768,769,772],{"class":176,"line":218},[174,770,771],{"class":191},"    \"Updates the 5-year SaaS vs. custom cost calculator inputs and returns the estimated crossover month.\"",[174,773,365],{"class":184},[174,775,776],{"class":176,"line":233},[174,777,778],{"class":184},"  inputSchema: {\n",[174,780,781,784,787],{"class":176,"line":245},[174,782,783],{"class":184},"    type: ",[174,785,786],{"class":191},"\"object\"",[174,788,365],{"class":184},[174,790,791],{"class":176,"line":272},[174,792,793],{"class":184},"    properties: {\n",[174,795,796,799,802,805,808],{"class":176,"line":323},[174,797,798],{"class":184},"      startUsers: { type: ",[174,800,801],{"class":191},"\"number\"",[174,803,804],{"class":184},", description: ",[174,806,807],{"class":191},"\"Active users in month 1\"",[174,809,810],{"class":184}," },\n",[174,812,813,816,818,820,823],{"class":176,"line":329},[174,814,815],{"class":184},"      endUsers: { type: ",[174,817,801],{"class":191},[174,819,804],{"class":184},[174,821,822],{"class":191},"\"Projected users at year 3\"",[174,824,810],{"class":184},[174,826,827],{"class":176,"line":334},[174,828,829],{"class":184},"      monthlyPerUser: {\n",[174,831,832,835,837],{"class":176,"line":344},[174,833,834],{"class":184},"        type: ",[174,836,801],{"class":191},[174,838,365],{"class":184},[174,840,841,844,847],{"class":176,"line":355},[174,842,843],{"class":184},"        description: ",[174,845,846],{"class":191},"\"Base SaaS price per seat in USD\"",[174,848,365],{"class":184},[174,850,851],{"class":176,"line":368},[174,852,853],{"class":184},"      },\n",[174,855,856],{"class":176,"line":400},[174,857,858],{"class":184},"    },\n",[174,860,861,864,867,869,872,874,877],{"class":176,"line":417},[174,862,863],{"class":184},"    required: [",[174,865,866],{"class":191},"\"startUsers\"",[174,868,263],{"class":184},[174,870,871],{"class":191},"\"endUsers\"",[174,873,263],{"class":184},[174,875,876],{"class":191},"\"monthlyPerUser\"",[174,878,879],{"class":184},"],\n",[174,881,882],{"class":176,"line":422},[174,883,884],{"class":184},"  },\n",[174,886,887,890,893,895,897],{"class":176,"line":427},[174,888,889],{"class":180},"  async",[174,891,892],{"class":275}," execute",[174,894,439],{"class":184},[174,896,284],{"class":211},[174,898,449],{"class":184},[174,900,901,904,906,909],{"class":176,"line":452},[174,902,903],{"class":184},"    startUsers.value ",[174,905,573],{"class":180},[174,907,908],{"class":275}," Number",[174,910,911],{"class":184},"(input.startUsers);\n",[174,913,914,917,919,921],{"class":176,"line":479},[174,915,916],{"class":184},"    endUsers.value ",[174,918,573],{"class":180},[174,920,908],{"class":275},[174,922,923],{"class":184},"(input.endUsers);\n",[174,925,926,929,931,933],{"class":176,"line":484},[174,927,928],{"class":184},"    monthlyPerUser.value ",[174,930,573],{"class":180},[174,932,908],{"class":275},[174,934,935],{"class":184},"(input.monthlyPerUser);\n",[174,937,938],{"class":176,"line":502},[174,939,202],{"emptyLinePlaceholder":201},[174,941,942,945],{"class":176,"line":537},[174,943,944],{"class":180},"    return",[174,946,215],{"class":184},[174,948,949],{"class":176,"line":543},[174,950,951],{"class":184},"      content: [\n",[174,953,954],{"class":176,"line":562},[174,955,956],{"class":184},"        {\n",[174,958,959,962,965],{"class":176,"line":567},[174,960,961],{"class":184},"          type: ",[174,963,964],{"class":191},"\"text\"",[174,966,365],{"class":184},[174,968,969,972,975,977,980],{"class":176,"line":584},[174,970,971],{"class":184},"          text: ",[174,973,974],{"class":227},"JSON",[174,976,39],{"class":184},[174,978,979],{"class":275},"stringify",[174,981,751],{"class":184},[174,983,984],{"class":176,"line":592},[174,985,986],{"class":184},"            saasTotal: saas5YearTotal.value,\n",[174,988,989],{"class":176,"line":607},[174,990,991],{"class":184},"            customTotal: custom5YearTotal.value,\n",[174,993,994],{"class":176,"line":619},[174,995,996],{"class":184},"            crossoverMonth: crossoverMonth.value,\n",[174,998,999],{"class":176,"line":626},[174,1000,1001],{"class":184},"          }),\n",[174,1003,1004],{"class":176,"line":653},[174,1005,1006],{"class":184},"        },\n",[174,1008,1009],{"class":176,"line":659},[174,1010,1011],{"class":184},"      ],\n",[174,1013,1014],{"class":176,"line":665},[174,1015,1016],{"class":184},"    };\n",[174,1018,1019],{"class":176,"line":670},[174,1020,884],{"class":184},[174,1022,1023],{"class":176,"line":683},[174,1024,1025],{"class":184},"});\n",[14,1027,1028,1029,1031],{},"Notice what ",[18,1030,79],{}," does not do: it does not invent a hidden API call or bypass client validation. It drives the exact reactive state already backing the visible SVG chart and summary table, so a person watching the tab sees the numbers update right in front of them.",[57,1033,1035],{"id":1034},"testing-tools-locally-in-chrome","Testing tools locally in Chrome",[14,1037,1038,1039,1042],{},"To try your registered tools without deploying an Origin Trial token yet, open ",[18,1040,1041],{},"about:flags#enable-webmcp-testing"," in Chrome 149 or newer and turn the flag on. Once restarted, you can inspect and invoke your own page tools directly from the DevTools Console or Chrome's Application panel:",[165,1044,1048],{"className":1045,"code":1046,"language":1047,"meta":170,"style":170},"language-js shiki shiki-themes github-dark-default","\u002F\u002F Inspect tools currently active on the page\nconst tools = await document.modelContext.getTools();\nconsole.log(tools.map((t) => ({ name: t.name, inputSchema: t.inputSchema })));\n\n\u002F\u002F Execute one directly with test arguments\nconst result = await document.modelContext.executeTool(\n  \"compare_saas_vs_custom\",\n  {\n    startUsers: 80,\n    endUsers: 220,\n    monthlyPerUser: 95,\n  },\n);\nconsole.log(result);\n","js",[18,1049,1050,1055,1076,1104,1108,1113,1132,1139,1144,1154,1164,1174,1178,1183],{"__ignoreMap":170},[174,1051,1052],{"class":176,"line":177},[174,1053,1054],{"class":622},"\u002F\u002F Inspect tools currently active on the page\n",[174,1056,1057,1060,1063,1065,1068,1071,1074],{"class":176,"line":198},[174,1058,1059],{"class":180},"const",[174,1061,1062],{"class":227}," tools",[174,1064,472],{"class":180},[174,1066,1067],{"class":180}," await",[174,1069,1070],{"class":184}," document.modelContext.",[174,1072,1073],{"class":275},"getTools",[174,1075,581],{"class":184},[174,1077,1078,1081,1084,1087,1090,1093,1096,1099,1101],{"class":176,"line":205},[174,1079,1080],{"class":184},"console.",[174,1082,1083],{"class":275},"log",[174,1085,1086],{"class":184},"(tools.",[174,1088,1089],{"class":275},"map",[174,1091,1092],{"class":184},"((",[174,1094,1095],{"class":211},"t",[174,1097,1098],{"class":184},") ",[174,1100,302],{"class":180},[174,1102,1103],{"class":184}," ({ name: t.name, inputSchema: t.inputSchema })));\n",[174,1105,1106],{"class":176,"line":218},[174,1107,202],{"emptyLinePlaceholder":201},[174,1109,1110],{"class":176,"line":233},[174,1111,1112],{"class":622},"\u002F\u002F Execute one directly with test arguments\n",[174,1114,1115,1117,1120,1122,1124,1126,1129],{"class":176,"line":245},[174,1116,1059],{"class":180},[174,1118,1119],{"class":227}," result",[174,1121,472],{"class":180},[174,1123,1067],{"class":180},[174,1125,1070],{"class":184},[174,1127,1128],{"class":275},"executeTool",[174,1130,1131],{"class":184},"(\n",[174,1133,1134,1137],{"class":176,"line":272},[174,1135,1136],{"class":191},"  \"compare_saas_vs_custom\"",[174,1138,365],{"class":184},[174,1140,1141],{"class":176,"line":323},[174,1142,1143],{"class":184},"  {\n",[174,1145,1146,1149,1152],{"class":176,"line":329},[174,1147,1148],{"class":184},"    startUsers: ",[174,1150,1151],{"class":227},"80",[174,1153,365],{"class":184},[174,1155,1156,1159,1162],{"class":176,"line":334},[174,1157,1158],{"class":184},"    endUsers: ",[174,1160,1161],{"class":227},"220",[174,1163,365],{"class":184},[174,1165,1166,1169,1172],{"class":176,"line":344},[174,1167,1168],{"class":184},"    monthlyPerUser: ",[174,1170,1171],{"class":227},"95",[174,1173,365],{"class":184},[174,1175,1176],{"class":176,"line":355},[174,1177,884],{"class":184},[174,1179,1180],{"class":176,"line":368},[174,1181,1182],{"class":184},");\n",[174,1184,1185,1187,1189],{"class":176,"line":400},[174,1186,1080],{"class":184},[174,1188,1083],{"class":275},[174,1190,1191],{"class":184},"(result);\n",[14,1193,1194,1195,35,1198,1201],{},"Because ",[18,1196,1197],{},"getTools()",[18,1199,1200],{},"executeTool()"," work directly for in-page and extension harnesses, you can also exercise your WebMCP tool contracts inside Playwright integration tests rather than relying on fragile UI click scripts alone.",[57,1203,1205],{"id":1204},"permissions-policy-iframes-and-backend-boundaries","Permissions Policy, iframes, and backend boundaries",[14,1207,1208,1209,1214,1215,1218,1219,1222],{},"Because third-party widgets and embedded frames live inside modern web apps, WebMCP ties tool discovery to the browser's ",[23,1210,1213],{"href":1211,"rel":1212},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FHTTP\u002FGuides\u002FPermissions_Policy",[27],"Permissions Policy",". By default, ",[18,1216,1217],{},"registerTool()"," works in top-level documents and same-origin frames, while cross-origin iframes fail with ",[18,1220,1221],{},"NotAllowedError"," unless the parent frame grants access explicitly:",[165,1224,1228],{"className":1225,"code":1226,"language":1227,"meta":170,"style":170},"language-html shiki shiki-themes github-dark-default","\u003Ciframe src=\"https:\u002F\u002Fassistant.example.com\u002F\" allow=\"tools\">\u003C\u002Fiframe>\n","html",[18,1229,1230],{"__ignoreMap":170},[174,1231,1232,1234,1238,1241,1243,1246,1249,1251,1254,1257,1259],{"class":176,"line":177},[174,1233,257],{"class":184},[174,1235,1237],{"class":1236},"sPWt5","iframe",[174,1239,1240],{"class":227}," src",[174,1242,573],{"class":184},[174,1244,1245],{"class":191},"\"https:\u002F\u002Fassistant.example.com\u002F\"",[174,1247,1248],{"class":227}," allow",[174,1250,573],{"class":184},[174,1252,1253],{"class":191},"\"tools\"",[174,1255,1256],{"class":184},">\u003C\u002F",[174,1258,1237],{"class":1236},[174,1260,1261],{"class":184},">\n",[14,1263,1264,1265,1268,1269,1272,1273,35,1275,1272,1278,1280],{},"If you want to disable browser tool registration across an entire sensitive route such as an admin billing screen, send ",[18,1266,1267],{},"Permissions-Policy: tools=()"," from your reverse proxy or Nuxt route rule. When you intentionally share tools across trusted frames in the same tree, pass ",[18,1270,1271],{},"exposedTo: [\"https:\u002F\u002Ftrusted-origin.example\"]"," to ",[18,1274,1217],{},[18,1276,1277],{},"fromOrigins",[18,1279,1197],{}," so unrelated third-party embeds stay locked out.",[14,1282,1283,1284,1289],{},"One final rule applies even when WebMCP works smoothly: keep real tenant and role authorization on your server and database. Client-side tools run inside a browser the user controls, so any API endpoint invoked by a WebMCP tool still needs proper session checks and ",[23,1285,1288],{"href":1286,"rel":1287},"https:\u002F\u002Fmihai.ltd\u002Fblog\u002Frow-level-security-ai-coding-agents\u002F",[27],"PostgreSQL Row-Level Security (RLS)"," underneath.",[57,1291,1293],{"id":1292},"where-to-go-next","Where to go next",[14,1295,1296,1297,1301,1302,1307,1308,1313,1314,39],{},"WebMCP fits best as a clean layer over interactive screens, while backend MCP servers and durable workflows still own background sync, scheduled jobs, and multi-system automation. If your team is designing that split across an existing SaaS or enterprise portal, read the ",[23,1298,1300],{"href":45,"rel":1299},[27],"backend MCP vs. browser WebMCP architecture breakdown"," on Innovi Pro. When you are ready to build or review the architecture, take a look at our ",[23,1303,1306],{"href":1304,"rel":1305},"https:\u002F\u002Finnovi.pro\u002Fservices\u002Fmcp-ai-integration",[27],"MCP and AI integration engineering services",", commission a ",[23,1309,1312],{"href":1310,"rel":1311},"https:\u002F\u002Finnovi.pro\u002Fservices\u002Fsoftware-architecture-audit",[27],"software architecture audit",", or ",[23,1315,1318],{"href":1316,"rel":1317},"https:\u002F\u002Finnovi.pro\u002F#contact",[27],"request a scoping call",[1320,1321,1322],"style",{},"html pre.shiki code .suJrU, html code.shiki .suJrU{--shiki-default:#FF7B72}html pre.shiki code .sZEs4, html code.shiki .sZEs4{--shiki-default:#E6EDF3}html pre.shiki code .s9uIt, html code.shiki .s9uIt{--shiki-default:#A5D6FF}html pre.shiki code .sQhOw, html code.shiki .sQhOw{--shiki-default:#FFA657}html pre.shiki code .sFSAA, html code.shiki .sFSAA{--shiki-default:#79C0FF}html pre.shiki code .sc3cj, html code.shiki .sc3cj{--shiki-default:#D2A8FF}html pre.shiki code .sH3jZ, html code.shiki .sH3jZ{--shiki-default:#8B949E}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sPWt5, html code.shiki .sPWt5{--shiki-default:#7EE787}",{"title":170,"searchDepth":198,"depth":198,"links":1324},[1325,1326,1327,1328,1329,1330],{"id":59,"depth":198,"text":60},{"id":126,"depth":198,"text":127},{"id":730,"depth":198,"text":731},{"id":1034,"depth":198,"text":1035},{"id":1204,"depth":198,"text":1205},{"id":1292,"depth":198,"text":1293},"\u002Fimages\u002Fcovers\u002Fwebmcp-in-practice-registering-browser-tools.png","2026-11-19","How to expose typed client-side actions from a Vue or TypeScript web app with document.modelContext.registerTool, clean up tools on route change with AbortController, and enforce origin boundaries.","md",{"canonical_url":1336},"https:\u002F\u002Fmihai.ltd\u002Fblog\u002Fwebmcp-in-practice-registering-browser-tools\u002F","\u002Fblog\u002Fwebmcp-in-practice-registering-browser-tools",{"title":5,"description":1333},"blog\u002Fwebmcp-in-practice-registering-browser-tools",[1341,1342,1343,1344,1345,1346],"webmcp","mcp","typescript","vue","ai-agents","browser-apis","blog_post","ihfBi0SQehvU-nnDXUfOGWpJYvDxWkorZbH5FIh_h4A",null,1795106686318]