Skip to content
WebMCP Agents
Esc
↑↓navigate↵open⌘Jpreview
On this page

parseSchema

Turns a tool's inputSchema into a SchemaNode object.

Turns a tool’s inputSchema into a SchemaNode object. Chrome returns inputSchema as a JSON string and the polyfill returns an object, so the devtools read both through this; use it when you build a UI from getTools().

Import

import { parseSchema } from "@webmcp-agents/devtools";
import type { SchemaNode } from "@webmcp-agents/devtools";

Example

List each tool’s parameters, whichever shape the browser gave.

import { parseSchema } from "@webmcp-agents/devtools";

// Chrome returns each inputSchema as a JSON string, the polyfill as
// an object: parseSchema reads both.
const tools = await document.modelContext?.getTools();

for (const tool of tools ?? []) {
  const schema = parseSchema(tool.inputSchema);
  console.log(tool.name, Object.keys(schema.properties ?? {}));
}

Options

parseSchema(schema) takes one argument.

Name Type Default Description
schema ModelContextToolInfo["inputSchema"] required The schema from document.modelContext.getTools(): a JSON string (Chrome) or an object (polyfill).

SchemaNode

The slice of JSON Schema the runner understands. Unknown keywords pass through the index signature.

Name Type Description
type string | string[] The JSON Schema type; ["string", "null"] reads as "string".
title string The label SchemaForm shows instead of the property name.
description string The parameter’s description; defaultValueFor takes a sample from e.g. … in it.
default unknown The starting value in the form.
enum unknown[] Allowed values, shown as a select.
const unknown A fixed value.
format string date, email, uri: the form’s input type and sample value.
minimum number Lower bound of a number, and its starting value.
maximum number Upper bound of a number.
maxLength number A string longer than 120 gets a textarea.
properties Record<string, SchemaNode> An object’s parameters.
required string[] Names of the required properties.
items SchemaNode The schema of an array’s items.

Returns

A SchemaNode. An object is returned as is; undefined gives {}. A string is parsed; a string that is not JSON, or does not parse to an object, gives {}.

Notes

  • A broken schema reads as empty rather than throwing.
  • WebMCP input schemas are shallow (a form’s fields, a tool’s zod object), so SchemaNode stays small. Anything else falls back to raw JSON in SchemaForm.
  • ToolView.schema in the store is already parsed with this.

See also

Was this page helpful?