From e3c23c060df2d6b4a5508d0e9fde42ce626f46cc Mon Sep 17 00:00:00 2001 From: Alex Nahas Date: Tue, 16 Sep 2025 21:07:14 -0700 Subject: [PATCH] add wip explainer for the declarative api --- docs/declarative.md | 507 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 docs/declarative.md diff --git a/docs/declarative.md b/docs/declarative.md new file mode 100644 index 0000000..0a16789 --- /dev/null +++ b/docs/declarative.md @@ -0,0 +1,507 @@ +# Declarative WebMCP API Proposal — Draft + +> September 16, 2025 +> +> <alexmnahas@gmail.com> + +Status: Draft for discussion. This document proposes a minimal, declarative way for web pages to expose WebMCP tools directly from HTML. The core idea is simple: HTML is the contract. Agents derive parameter schemas from standard form/anchor semantics and validation. No custom validation attributes. Complex/edge cases remain the domain of JavaScript tools registered via [`window.mcp.registerTool`](./proposal.md) (or whatever API we end up with). For broader context, see the main explainer in `webmcp/README.md`. + +Related: original proposal discussion — GitHub issue #22: https://github.com/webmachinelearning/webmcp/issues/22 + + +## TL;DR + +This HTML form declares a tool the browser can expose to agents: + +```html +
+ + + + + + + +
+``` + +Equivalent JavaScript tool definition (what the browser synthesizes conceptually): + +```js +// Conceptual shape of the synthesized JS tool: +window.mcp.registerTool("add_todo", { + description: "Create a todo item", + inputSchema: { + type: "object", + additionalProperties: false, + properties: { + text: { type: "string", minLength: 3, maxLength: 140, description: "Text" }, + priority: { type: "string", enum: ["low", "medium", "high"] }, + projectId: { type: "string" } + }, + required: ["text"] + }, + async ({ text, priority = "medium", projectId }) => { + const res = await fetch("/todos", { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json" + }, + body: JSON.stringify({ text, priority, projectId }) + }); + return await res.json(); // MCP-compatible JSON + } +}); + +``` + +## 0) Principles +- HTML is the single source of truth. If a human can submit it, an agent can submit it. Validation and structure come from ordinary HTML ([required](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/required), [pattern](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/pattern), [min](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/min), [max](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/max), [minlength](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/minlength), [maxlength](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/maxlength), [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/step), [`