holon-ui 0.0.1-dev.2 → 0.0.1-dev.4
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 +11 -12
- package/package.json +4 -12
- package/runtime.mjs +3 -4
- 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,6 +1,6 @@
|
|
|
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
|
|
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.
|
|
4
4
|
|
|
5
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.
|
|
6
6
|
|
|
@@ -12,12 +12,12 @@ In the app's root directory, next to its `server.json`:
|
|
|
12
12
|
npm install holon-ui@dev
|
|
13
13
|
```
|
|
14
14
|
|
|
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 `
|
|
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
16
|
|
|
17
17
|
## The generated module
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import { App, ToolCallError, createApps, exposeTools, registerPageTools, type Inputs, type Outputs, type Resources } from "holon-ui";
|
|
20
|
+
import { App, ToolCallError, createApps, exposeTools, registerPageTools, type Inputs, type Outputs, type Resources } from "#holon-ui";
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
| Export | What it is |
|
|
@@ -38,7 +38,7 @@ Your own server appears under the last segment of its `server.json` name, e.g. `
|
|
|
38
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
39
|
|
|
40
40
|
```typescript
|
|
41
|
-
import { App } from "holon-ui";
|
|
41
|
+
import { App } from "#holon-ui";
|
|
42
42
|
|
|
43
43
|
const view = new App({ name: "checkout-view", version: "1.0.0" });
|
|
44
44
|
view.ontoolresult = ({ structuredContent }) => render(structuredContent);
|
|
@@ -62,17 +62,16 @@ const order = await apps.orders.tools.lookup({ id: "A-1" }, { timeout: 5000 });
|
|
|
62
62
|
|
|
63
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
64
|
|
|
65
|
-
A tool can stop and ask for input through an MCP elicitation.
|
|
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:
|
|
66
66
|
|
|
67
67
|
```typescript
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
endpoint: "https://orders.example.com/mcp",
|
|
71
|
-
elicit: async ({ params }) => ({ action: "accept", content: await showForm(params) }),
|
|
72
|
-
},
|
|
68
|
+
const { shipped } = await apps.orders.tools.ship({ id: "A-1" }, {
|
|
69
|
+
elicit: async params => ({ action: "accept", content: await showForm(params) }),
|
|
73
70
|
});
|
|
74
71
|
```
|
|
75
72
|
|
|
73
|
+
Without `elicit`, the call throws `ToolCallError` with the question on `.result`.
|
|
74
|
+
|
|
76
75
|
## Read and watch resources
|
|
77
76
|
|
|
78
77
|
A server types a JSON resource by registering it with `mimeType: "application/json"` and an `"sh.holon/outputSchema"` JSON Schema in its `_meta`:
|
|
@@ -88,7 +87,7 @@ await apps.orders.resources["orders://summary"].watch(value => render(value.open
|
|
|
88
87
|
|
|
89
88
|
## Give tools to the page's agent
|
|
90
89
|
|
|
91
|
-
`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
|
|
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.
|
|
92
91
|
|
|
93
92
|
```typescript
|
|
94
93
|
await exposeTools(apps.orders, { signal: lifetime.signal });
|
|
@@ -132,7 +131,7 @@ npm install @modelcontextprotocol/ext-apps
|
|
|
132
131
|
npx vite build
|
|
133
132
|
```
|
|
134
133
|
|
|
135
|
-
Then serve `dist/index.html` from the server
|
|
134
|
+
Then serve `dist/index.html` from the server as an [MCP App](https://modelcontextprotocol.io/extensions/apps/overview) resource.
|
|
136
135
|
|
|
137
136
|
## Low-level runtime
|
|
138
137
|
|
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.4",
|
|
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,17 +24,14 @@
|
|
|
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": {
|
|
42
|
-
"holon-sh": "^0.0.1-dev.
|
|
34
|
+
"holon-sh": "^0.0.1-dev.6"
|
|
43
35
|
},
|
|
44
36
|
"peerDependencies": {
|
|
45
37
|
"@modelcontextprotocol/ext-apps": ">=1.0.0"
|
package/runtime.mjs
CHANGED
|
@@ -33,10 +33,9 @@ export async function exposeTools(app, options = {}) {
|
|
|
33
33
|
const { signal } = options;
|
|
34
34
|
const execute = options.execute ?? (async (name, args) => {
|
|
35
35
|
const result = await app.callTool({ name, arguments: args }, { signal });
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return { isError: true, content: [{ type: "text", text: [`${name} needs input this page cannot provide`, ...questions].join(": ") }] };
|
|
36
|
+
// An agent can only supply arguments, so it cannot answer. A custom execute can.
|
|
37
|
+
if (result.resultType === "input_required") throw new ToolCallError("page", name, result);
|
|
38
|
+
return result;
|
|
40
39
|
});
|
|
41
40
|
const { tools } = await app.listTools({ signal });
|
|
42
41
|
for (const tool of tools) {
|
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); }
|