holon-ui 0.0.1-dev.4 → 0.0.1-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +37 -117
  2. package/package.json +1 -1
  3. package/runtime.mjs +25 -2
package/README.md CHANGED
@@ -1,149 +1,69 @@
1
1
  # holon-ui
2
2
 
3
- Typed MCP clients for browser pages: views that run inside an MCP Apps host, or standalone pages that talk to MCP servers directly. The [`holon` CLI](https://github.com/holon-sh/cli) generates your app's clients into its `generated/holon-ui/` directory, beside its `package.json`, and maps `#holon-ui` to them there. Clients validate arguments before each call and results after it, and can expose tools to the page's WebMCP agent.
3
+ [![Docs](https://img.shields.io/badge/docs-holon--labs.dev-blue)](https://holon-labs.dev/docs/)
4
4
 
5
- `holon-ui` contains only browser code. Server code uses `holon-sh` ([Node.js](https://github.com/holon-sh/sdk-ts) or [Python](https://github.com/holon-sh/sdk-py)). Start with the [CLI README](https://github.com/holon-sh/cli) for the walkthrough.
5
+ Typed MCP clients for browser pages: MCP App views, and pages that call MCP servers directly.
6
6
 
7
7
  ## Install
8
8
 
9
- In the app's root directory, next to its `server.json`:
10
-
11
9
  ```sh
12
10
  npm install holon-ui@dev
11
+ npm install -D holon-types typescript
13
12
  ```
14
13
 
15
- Declare `holon-ui` in the app root's `package.json` even when the view's sources live in a subdirectory: `holon types generate` writes browser clients into `generated/holon-ui/` beside the `package.json` that declares `holon-ui` (and Node clients into `generated/holon-sh/` when it declares `holon-sh` too). The generated module imports `holon-ui/runtime` and, for `App`, `@modelcontextprotocol/ext-apps`, so the app installs both.
16
-
17
- ## The generated module
18
-
19
- ```typescript
20
- import { App, ToolCallError, createApps, exposeTools, registerPageTools, type Inputs, type Outputs, type Resources } from "#holon-ui";
21
- ```
22
-
23
- | Export | What it is |
24
- |---|---|
25
- | `App` | The `App` from `@modelcontextprotocol/ext-apps` with your own server's `tools`, `resources` and `callTool` typed. Calls go through the host that embeds the page. |
26
- | `createApps(bindings, options?)` | Clients for servers you reach by endpoint, keyed like `bindings`. |
27
- | `ToolCallError` | Thrown by `tools.<tool>` when a tool reports an error or asks for more input. |
28
- | `exposeTools(client, options?)` | Registers a client's tools with the page's WebMCP agent. |
29
- | `registerPageTools(tools, options?)` | Registers tools implemented by the page itself. |
30
- | `Inputs`, `Outputs`, `Resources` | Argument, result and resource value types, as `Inputs["dep"]["tool"]`. |
31
-
32
- Your own server appears under the last segment of its `server.json` name, e.g. `example.com/checkout` → `checkout`: `Inputs["checkout"]`, `Outputs["checkout"]`, and `createApps({ checkout: { endpoint } })` for a standalone page. Every other key is a dependency declared in `server.json`.
33
-
34
- ## Bind a client
35
-
36
- ### Inside an MCP Apps host
37
-
38
- A view embedded in an MCP Apps host calls its own server through the host, which owns the connection and the credentials. Construct and connect `App` exactly as you would the one from `@modelcontextprotocol/ext-apps`; it is that class with typed members added:
39
-
40
- ```typescript
41
- import { App } from "#holon-ui";
42
-
43
- const view = new App({ name: "checkout-view", version: "1.0.0" });
44
- view.ontoolresult = ({ structuredContent }) => render(structuredContent);
45
- await view.connect();
46
-
47
- const { total } = await view.tools.total({ id: "A-1" });
48
- ```
49
-
50
- The host owns the tool catalog, so `listTools`, `exposeTools` and `watch` need an endpoint binding instead.
51
-
52
- ### Directly to an endpoint
53
-
54
- ```typescript
55
- const apps = createApps({
56
- checkout: { endpoint: new URL("/mcp", location.origin) },
57
- orders: { endpoint: "https://orders.example.com/mcp" },
58
- });
59
-
60
- const order = await apps.orders.tools.lookup({ id: "A-1" }, { timeout: 5000 });
61
- ```
62
-
63
- An endpoint binding takes `endpoint`, and optionally `authProvider`, `fetch`, and `scoped: true` to close the session after every call. Otherwise a client keeps one session open; call `close()` when the page no longer needs it.
64
-
65
- A tool can stop and ask for input through an MCP elicitation. Pass `elicit` to answer it, and the call returns its usual typed output:
14
+ ## Create an app
66
15
 
67
- ```typescript
68
- const { shipped } = await apps.orders.tools.ship({ id: "A-1" }, {
69
- elicit: async params => ({ action: "accept", content: await showForm(params) }),
70
- });
71
- ```
72
-
73
- Without `elicit`, the call throws `ToolCallError` with the question on `.result`.
74
-
75
- ## Read and watch resources
76
-
77
- A server types a JSON resource by registering it with `mimeType: "application/json"` and an `"sh.holon/outputSchema"` JSON Schema in its `_meta`:
78
-
79
- ```typescript
80
- const summary = await apps.orders.resources["orders://summary"].read();
81
-
82
- const lifetime = new AbortController();
83
- await apps.orders.resources["orders://summary"].watch(value => render(value.open), { signal: lifetime.signal });
16
+ ```sh
17
+ npx create-holon-app foo
84
18
  ```
85
19
 
86
- `watch` calls back with the current value and then on every update, until the signal aborts; the server must support resource subscriptions.
87
-
88
- ## Give tools to the page's agent
89
-
90
- `exposeTools` registers the tools of an endpoint-bound client with the page's WebMCP context (`navigator.modelContext`), except those whose `_meta.ui.visibility` omits `"model"`. Calls from the agent go through the client, so they are validated. An agent can only supply arguments, so a question reaches it as a failed call naming the question; to answer for it, pass an `execute` that calls `callTool` with `elicit`. It returns `false` when the browser has no WebMCP context.
91
-
92
- ```typescript
93
- await exposeTools(apps.orders, { signal: lifetime.signal });
94
- ```
20
+ This creates an MCP server with a `greet` tool and a view in `ui/main.ts`.
95
21
 
96
- `registerPageTools` registers tools the page implements itself. Input schemas are Standard Schema validators that can produce JSON Schema, such as Zod 4. Pass `view` to register with the MCP Apps host; without it they go to WebMCP. Aborting the signal unregisters them.
22
+ ## Calling your server from a view
97
23
 
98
- ```typescript
99
- import { z } from "zod";
24
+ The server declares the tool's input and output:
100
25
 
101
- await registerPageTools(
26
+ ```ts
27
+ server.registerTool(
28
+ "greet",
102
29
  {
103
- highlight: {
104
- description: "Highlight an order on the page",
105
- inputSchema: z.object({ id: z.string() }),
106
- execute: ({ id }) => {
107
- select(id);
108
- return { content: [{ type: "text", text: `Highlighted ${id}` }] };
109
- },
110
- },
30
+ inputSchema: z.strictObject({ name: z.string() }),
31
+ outputSchema: z.strictObject({ result: z.string() }),
32
+ },
33
+ ({ name }) => {
34
+ const output = { result: `Hello, ${name}!` };
35
+ return { content: [{ type: "text", text: output.result }], structuredContent: output };
111
36
  },
112
- { view, signal: lifetime.signal },
113
37
  );
114
38
  ```
115
39
 
116
- ## Build and serve a view
117
-
118
- The server serves the view as one HTML file, so bundle it into a single file. With Vite, in the app root:
119
-
120
- ```typescript
121
- // vite.config.ts
122
- import { defineConfig } from "vite";
123
- import { viteSingleFile } from "vite-plugin-singlefile";
124
-
125
- export default defineConfig({ root: "ui", plugins: [viteSingleFile()], build: { outDir: "../dist", emptyOutDir: true } });
126
- ```
40
+ The `App` from `#holon-ui` types the server's tools, so a wrong tool name, argument or result is a type error:
127
41
 
128
42
  ```sh
129
- npm install --save-dev vite vite-plugin-singlefile
130
- npm install @modelcontextprotocol/ext-apps
131
- npx vite build
43
+ npx holon types check
132
44
  ```
133
45
 
134
- Then serve `dist/index.html` from the server as an [MCP App](https://modelcontextprotocol.io/extensions/apps/overview) resource.
46
+ ```ts
47
+ import { App } from "#holon-ui";
135
48
 
136
- ## Low-level runtime
49
+ const view = new App({ name: "foo", version: "0.1.0" });
50
+ await view.connect();
137
51
 
138
- `holon-ui/runtime` exports what the generated module calls: `createApps(identity, contracts, bindings?, options?)`, `bindApps`, `appClass(identity, contracts, own)`, `exposeTools`, `registerPageTools`, `ToolCallError`, and the `EndpointBinding`, `View` and page-tool types. Apps use the generated module instead.
52
+ const { result } = await view.tools.greet({ name: "Ada" });
139
53
 
140
- ## Develop
54
+ await view.tools.great({ name: "Ada" });
55
+ // error TS2551: Property 'great' does not exist on type '{ readonly greet: (input: { name: string; }, options?: ToolCallOptions | undefined) => Promise<{ result: string; }>; }'. Did you mean 'greet'?
141
56
 
142
- ```sh
143
- npm ci
144
- npm test
57
+ await view.tools.greet({ name: 42 });
58
+ // error TS2322: Type 'number' is not assignable to type 'string'.
59
+
60
+ await view.tools.greet({});
61
+ // error TS2741: Property '"name"' is missing in type '{}' but required in type '{ name: string; }'.
62
+
63
+ result.toFixed();
64
+ // error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?
145
65
  ```
146
66
 
147
- ## License
67
+ ## Community
148
68
 
149
- [Apache License 2.0](LICENSE)
69
+ Ask questions and share what you're building on the [Holon Discord](https://discord.gg/jXExyBdy).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holon-ui",
3
- "version": "0.0.1-dev.4",
3
+ "version": "0.0.1-dev.5",
4
4
  "description": "Typed MCP clients for browser views: MCP Apps host bindings and WebMCP tool exposure.",
5
5
  "repository": {
6
6
  "type": "git",
package/runtime.mjs CHANGED
@@ -27,6 +27,26 @@ export function appClass(identity, contracts, own) {
27
27
  };
28
28
  }
29
29
 
30
+ const hasFile = node => Array.isArray(node) ? node.some(hasFile) : typeof node === "object" && node !== null && ("x-mcp-file" in node || Object.values(node).some(hasFile));
31
+
32
+ // An agent writes arguments as tokens, so it is not shown a file argument (x-mcp-file): an anyOf or oneOf branch that
33
+ // holds one is left out, and a tool that still has one is not exposed.
34
+ // https://github.com/modelcontextprotocol/experimental-ext-file-uploads/blob/main/specification/draft/file-uploads.md#file-arguments
35
+ function withoutFiles(schema) {
36
+ const prune = node => {
37
+ if (Array.isArray(node)) return node.map(prune);
38
+ if (typeof node !== "object" || node === null) return node;
39
+ const pruned = Object.fromEntries(Object.entries(node).map(([key, value]) => [key, prune(value)]));
40
+ for (const key of ["anyOf", "oneOf"]) {
41
+ const kept = Array.isArray(pruned[key]) ? pruned[key].filter(branch => !hasFile(branch)) : [];
42
+ if (kept.length) pruned[key] = kept;
43
+ }
44
+ return pruned;
45
+ };
46
+ const pruned = hasFile(schema) ? prune(schema) : schema;
47
+ return hasFile(pruned) ? undefined : pruned;
48
+ }
49
+
30
50
  export async function exposeTools(app, options = {}) {
31
51
  const context = globalThis.document?.modelContext ?? globalThis.navigator?.modelContext;
32
52
  if (!context) return false;
@@ -35,15 +55,18 @@ export async function exposeTools(app, options = {}) {
35
55
  const result = await app.callTool({ name, arguments: args }, { signal });
36
56
  // An agent can only supply arguments, so it cannot answer. A custom execute can.
37
57
  if (result.resultType === "input_required") throw new ToolCallError("page", name, result);
38
- return result;
58
+ const { downloads, ...shown } = result;
59
+ return shown;
39
60
  });
40
61
  const { tools } = await app.listTools({ signal });
41
62
  for (const tool of tools) {
42
63
  // MCP Apps: a tool whose visibility omits "model" must not reach the agent; absent means ["model", "app"].
43
64
  // https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#resource-discovery
44
65
  if (!(tool._meta?.ui?.visibility ?? ["model"]).includes("model")) continue;
66
+ const inputSchema = withoutFiles(tool.inputSchema);
67
+ if (!inputSchema) continue;
45
68
  await context.registerTool({
46
- name: tool.name, title: tool.title, description: tool.description ?? "", inputSchema: tool.inputSchema, annotations: tool.annotations,
69
+ name: tool.name, title: tool.title, description: tool.description ?? "", inputSchema, annotations: tool.annotations,
47
70
  execute: args => execute(tool.name, args ?? {}),
48
71
  }, { signal });
49
72
  }