useWebMcp
useWebMcp registers a tool with the browser's experimental WebMCP API and removes it when the component unmounts. Import it from @rspress/core/runtime:
Mount the component where the capability belongs. Keep site-wide tools in a persistent component; mount tools specific to a page with that page. Tool names must be unique across the document, including the built-in tools.
Custom tools work independently of the webMcp config option. See the WebMCP guide for browser requirements.
Options
Use WebMcpOptions<TInput, TResult> or parameter annotations for types, and validate inputs and handle cancellation in execute.
Return value and lifecycle
Returns WebMcpState:
supported: whether the browser supports WebMCP.registered: whether registration succeeded.error: the registration error, ornullon success.
Tool calls use the latest committed props and state. Updating the handler does not re-register the tool. Disabling or unmounting the component unregisters it.