listToolDescriptors
Lists the WebMCP tools registered on this page right now, as a model reads them.
Lists the WebMCP tools registered on this page right now, as a model reads them. Use it in an adapter or a request of your own that does not go through the session.
Import
import { listToolDescriptors } from "@webmcp-agents/chat";
import type { ToolDescriptor } from "@webmcp-agents/chat";
Example
Send the page’s current tools with a chat request.
import { listToolDescriptors } from "@webmcp-agents/chat";
// The tools on this page right now, as a model reads them.
const tools = await listToolDescriptors();
const res = await fetch("/api/chat", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
messages: [
{
id: "u-1",
role: "user",
parts: [{ type: "text", text: "Hi" }],
},
],
tools,
page: { url: location.href },
}),
});
console.log(res.status);
Options
None. listToolDescriptors() takes no arguments and reads document.modelContext at the moment you call it.
Returns
A Promise<ToolDescriptor[]> from document.modelContext.getTools(). A ToolDescriptor is { name, description, inputSchema }.
- Tools whose
originis another origin are left out (Chrome reports where a tool lives). descriptionfalls back to the tool’stitle, then itsname.inputSchemais parsed when it is a JSON string. A missing or unreadable schema becomes{ type: "object", properties: {} }.- Without
document.modelContext(no WebMCP, or on the server) it resolves to[].
Notes
- Tools change as the page changes (a route swaps, a form hides itself). Read the list again before every model call;
useAgentSessionrefreshes it on everytoolchangeand after each tool call. - It rejects if
getTools()rejects;useAgentSessiontreats that as an empty list.
See also
- Add the chat
callModelContextToolToolDescriptorinspectTools, where each tool’s cursor would go