From 533e8c7e1ddad907306a032e38e8e6ea90db8970 Mon Sep 17 00:00:00 2001
From: Dominic Farolino The serialization algorithm above throws exceptions in the following cases: Throws a new {{TypeError}} when the backing " Re-throws exceptions thrown by " Currently, the only implementation of this spec (Chromium) does not throw
+ exceptions in the first case above. And for the second case, Chromium throws new {{TypeError}}
+ exceptions, as opposed to re-throwing the original exception. We should reconcile this difference.
+spec:html; type:dfn;
+ text:form-associated element
+
+
Introduction
WebMCP API is a new JavaScript interface that allows web developers to expose their web application functionality as “tools” - JavaScript functions with natural language descriptions and structured schemas that can be invoked by [=agents=], [=browser's agents=], and [=assistive technologies=]. Web pages that use WebMCP can be thought of as Model Context Protocol [[!MCP]] servers that implement tools in client-side script instead of on the backend. WebMCP enables collaborative workflows where users and agents work together within the same web interface, leveraging existing application logic while maintaining shared context and user control.
@@ -95,14 +101,49 @@ A browser’s agent is an [=agent=] provided by or through the browse
An AI platform is a provider of agentic assistants such as OpenAI’s ChatGPT, Anthropic’s Claude, or Google’s Gemini.
-Security and privacy considerations
+Supporting concepts
-
+A model context is a [=struct=] with the following [=struct/items=]:
-Accessibility considerations
+
+ : tool map
+ :: a [=map=] whose [=map/keys=] are [=strings=] and whose [=map/values=] are [=tool data=]
+ [=structs=].
+
+
+A tool data is a [=struct=] with the following [=struct/items=]:
+
+
+ : name
+ :: a [=string=] uniquely identifying a tool registered within a [=model context=]'s [=model
+ context/tool map=]; it is the same as the [=map/key=] identifying this object.
+
+ : description
+ :: a [=string=].
+
+ : input schema
+ :: a [=string=].
+
+ Note: For tools registered by the imperative form of this API (i.e.,
+ {{ModelContext/registerTool()}}), this is the stringified representation of
+ {{ModelContextTool/inputSchema}}. For tools registered
+ [declaratively](https://github.com/webmachinelearning/webmcp/pull/76), this will be a
+ stringified JSON Schema object created by the
+ [=synthesize a declarative JSON Schema object algorithm=].
+ [[!JSON-SCHEMA]]
+
+ : execute steps
+ :: a set of steps to invoke the tool.
+
+ Note: For tools registered imperatively, these steps will simply invoke the supplied
+ {{ToolExecuteCallback}} callback. For tools registered
+ [declaratively](https://github.com/webmachinelearning/webmcp/pull/76), this will be a set of
+ "internal" steps that have not been defined yet, that describe how to fill out a <{form}> and
+ its [=form-associated elements=].
+
+ : read-only hint
+ :: a [=boolean=], initially false.
+
API
@@ -143,6 +184,10 @@ interface ModelContext {
};
+Each {{ModelContext}} object has an associated internal context, which
+is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
+
+
navigator.{{Navigator/modelContext}}.{{ModelContext/provideContext(options)}}
+
+
+ JSON.stringify()"
+ yields undefined, e.g.,
+ "inputSchema: { toJSON() {return HTMLDivElement;}}", or
+ "innputSchema: { toJSON() {return undefined;}}".JSON.stringify()". For example,
+ "inputSchema: objectWithCircularReference", etc.Declarative WebMCP
+
+This section is entirely a TODO. For now, refer to the [explainer draft](https://github.com/webmachinelearning/webmcp/pull/76).
+
+
{
"mcp": {
@@ -311,6 +424,16 @@ The requestUserInteraction(callba
}
+Security and privacy considerations
+
+
+
+Accessibility considerations
+
+
Acknowledgements
Thanks to
From 625d494ba9fe82e580d26290dc2102c00514036a Mon Sep 17 00:00:00 2001
From: Dominic Farolino inputSchema: { toJSON() {return HTMLDivElement;}}", or
"innputSchema: { toJSON() {return undefined;}}".
Re-throws exceptions thrown by "JSON.stringify()". For example,
- "inputSchema: objectWithCircularReference", etc.
Re-throws exceptions thrown by "JSON.stringify()", e.g., when
+ "inputSchema" is an object with a circular reference, etc.
Currently, the only implementation of this spec (Chromium) does not throw @@ -288,9 +288,14 @@ The registerTool(tool) method step