holon-ui 0.0.1-dev.3 → 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.
- package/README.md +37 -117
- package/package.json +3 -11
- package/runtime.mjs +25 -2
- package/generated/holon-generated.json +0 -4
- package/generated/index.d.ts +0 -12
- package/generated/index.js +0 -4
package/README.md
CHANGED
|
@@ -1,149 +1,69 @@
|
|
|
1
1
|
# holon-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://holon-labs.dev/docs/)
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
+
## Calling your server from a view
|
|
97
23
|
|
|
98
|
-
|
|
99
|
-
import { z } from "zod";
|
|
24
|
+
The server declares the tool's input and output:
|
|
100
25
|
|
|
101
|
-
|
|
26
|
+
```ts
|
|
27
|
+
server.registerTool(
|
|
28
|
+
"greet",
|
|
102
29
|
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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
|
-
|
|
130
|
-
npm install @modelcontextprotocol/ext-apps
|
|
131
|
-
npx vite build
|
|
43
|
+
npx holon types check
|
|
132
44
|
```
|
|
133
45
|
|
|
134
|
-
|
|
46
|
+
```ts
|
|
47
|
+
import { App } from "#holon-ui";
|
|
135
48
|
|
|
136
|
-
|
|
49
|
+
const view = new App({ name: "foo", version: "0.1.0" });
|
|
50
|
+
await view.connect();
|
|
137
51
|
|
|
138
|
-
|
|
52
|
+
const { result } = await view.tools.greet({ name: "Ada" });
|
|
139
53
|
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
##
|
|
67
|
+
## Community
|
|
148
68
|
|
|
149
|
-
[
|
|
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.
|
|
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",
|
|
@@ -13,14 +13,9 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"holon": {
|
|
16
|
-
"
|
|
17
|
-
"contractVersion": 1
|
|
16
|
+
"contractVersion": 2
|
|
18
17
|
},
|
|
19
18
|
"exports": {
|
|
20
|
-
".": {
|
|
21
|
-
"types": "./generated/index.d.ts",
|
|
22
|
-
"import": "./generated/index.js"
|
|
23
|
-
},
|
|
24
19
|
"./runtime": {
|
|
25
20
|
"types": "./runtime.d.ts",
|
|
26
21
|
"import": "./runtime.mjs"
|
|
@@ -29,13 +24,10 @@
|
|
|
29
24
|
"files": [
|
|
30
25
|
"runtime.mjs",
|
|
31
26
|
"runtime.d.ts",
|
|
32
|
-
"generated/",
|
|
33
27
|
"README.md"
|
|
34
28
|
],
|
|
35
29
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"prepack": "npm run build",
|
|
38
|
-
"test": "npm run build && node --test tests/*.test.mjs",
|
|
30
|
+
"test": "node --test tests/*.test.mjs",
|
|
39
31
|
"fixtures": "node scripts/fixtures.mjs"
|
|
40
32
|
},
|
|
41
33
|
"dependencies": {
|
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
|
-
|
|
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
|
|
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
|
}
|
package/generated/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// holon-generated-apps-v1 placeholder
|
|
2
|
-
export type Apps = Record<never, never>;
|
|
3
|
-
export type Inputs = Record<never, never>;
|
|
4
|
-
export type Outputs = Record<never, never>;
|
|
5
|
-
export type InputTypes = Inputs;
|
|
6
|
-
export type OutputTypes = Outputs;
|
|
7
|
-
export type Resources = Record<never, never>;
|
|
8
|
-
export { ToolCallError } from "holon-sh/protocol";
|
|
9
|
-
export type { EndpointBinding, CreateOptions } from "../runtime.js";
|
|
10
|
-
export { exposeTools, registerPageTools } from "../runtime.js";
|
|
11
|
-
import type { CreateOptions } from "../runtime.js";
|
|
12
|
-
export declare function createApps(bindings: Record<string, never>, options?: CreateOptions): Apps;
|
package/generated/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// holon-generated-apps-v1 placeholder
|
|
2
|
-
import {bindApps} from "../runtime.mjs";
|
|
3
|
-
export {ToolCallError,exposeTools,registerPageTools} from "../runtime.mjs";
|
|
4
|
-
export function createApps(bindings, options) { return bindApps({name:"unconfigured",version:"0",requires:{}}, {}, bindings, options); }
|