Skip to main content
Prompts, resources, sampling, and elicitation are MCP-B extension features, not part of the strict WebMCP core. They require @mcp-b/global (which installs BrowserMcpServer as document.modelContext). For background on this distinction, see Strict Core vs MCP-B Extensions.

Register a prompt

A prompt is a reusable message template that AI clients can discover and invoke with arguments.
1

Import @mcp-b/global

2

Register the prompt

3

Unregister when done

React

Use the useWebMCPPrompt hook from @mcp-b/react-webmcp. It handles registration and cleanup on unmount.

Register a resource

A resource exposes readable data (configuration, documents, state) to AI clients.
1

Import @mcp-b/global

2

Register the resource

3

Unregister when done

React

Use the useWebMCPResource hook from @mcp-b/react-webmcp.

Use sampling and elicitation

Sampling lets your page request LLM completions from the connected client. Elicitation lets your page request structured input from the user through the client. Both methods delegate to the MCP SDK and require an active transport connection. See the @mcp-b/webmcp-ts-sdk reference for parameter and return type details.

React

@mcp-b/react-webmcp provides useSampling and useElicitation hooks that manage loading state, errors, and request counts.