isWebMCPAvailable
Returns true when the page has document.modelContext, from native WebMCP or the polyfill.
Returns true when the page has document.modelContext, from native WebMCP or the polyfill. Use it to decide whether to show tool-related UI.
Import
import { isWebMCPAvailable } from "@webmcp-agents/core";
Example
Show a hint only where an agent could use the page. @webmcp-agents/react reads it the same way in useWebTool.
import { isWebMCPAvailable } from "@webmcp-agents/core";
const hint = document.querySelector("#agent-hint");
if (hint instanceof HTMLElement) {
hint.hidden = !isWebMCPAvailable();
}
Options
None: isWebMCPAvailable() takes no arguments.
Returns
true when document exists and document.modelContext is set; false otherwise, including on the server.
Notes
- It is a plain check with no events: while
createWebAgents(or<WebAgentsProvider>) loads the polyfill it isfalse, so ask again later, or wait withwhenModelContext. - It says nothing about tools: an empty
modelContextis still available.