holon-ui 0.0.1-dev.20 → 0.0.1-dev.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holon-ui",
3
- "version": "0.0.1-dev.20",
3
+ "version": "0.0.1-dev.21",
4
4
  "description": "Typed MCP clients for browser pages: one connect() for MCP Apps views and WebMCP pages.",
5
5
  "repository": {
6
6
  "type": "git",
package/runtime.d.ts CHANGED
@@ -19,6 +19,7 @@ export interface PageTool<S = undefined> {
19
19
  export interface ConnectOptions<S extends Record<string, unknown> = {}> {
20
20
  /** Page tools by name, offered to the host's agent in an MCP Apps host and to the browser's agent through WebMCP. */
21
21
  tools?: { [K in keyof S]: PageTool<S[K]> };
22
+ batch?: "call_tools" extends keyof S ? false : boolean;
22
23
  /** The ext-apps App's options in an MCP Apps host, and the transport to connect it with; ignored on a web page. */
23
24
  view?: AppOptions & { transport?: Parameters<App["connect"]>[0] };
24
25
  /** The app's binding on a web page, in place of the generated one; its endpoint resolves against the page's origin. Ignored in an MCP Apps host. */
@@ -48,7 +49,7 @@ export type Page<C> =
48
49
  readonly opened: undefined;
49
50
  });
50
51
  /** connect, narrowed by the generated #holon-ui module to the client C of the project's own app. A page tool cannot take the name of one of the app's tools. */
51
- export type Connect<C> = <S extends Record<string, unknown> = {}>(options?: ConnectOptions<S> & { tools?: { [K in keyof Tools<C>]?: never } }) => Promise<Page<C>>;
52
+ export type Connect<C> = <S extends Record<string, unknown> = {}>(options?: ConnectOptions<S> & { tools?: { [K in keyof Tools<C>]?: never }; batch?: "call_tools" extends keyof Tools<C> ? false : boolean }) => Promise<Page<C>>;
52
53
  /** Bind the page to its own app on the surface its build chose, and offer every tool to whichever agent is present. Most pages call the generated connect from #holon-ui. */
53
54
  export declare function connect<S extends Record<string, unknown> = {}>(
54
55
  app: { identity: Identity; contracts: Record<string, Contract | null>; own: string; /** The app's MCP endpoint on the page's origin, such as "/mcp/checkout". */ endpoint: string },
package/runtime.web.mjs CHANGED
@@ -6,7 +6,7 @@ import { bindApps, ToolCallError } from "holon-sh/runtime";
6
6
 
7
7
  export { bindApps, ToolCallError };
8
8
 
9
- export async function connect({ identity, contracts, own, endpoint }, { tools = {}, web = { endpoint } } = {}) {
9
+ export async function connect({ identity, contracts, own, endpoint }, { tools = {}, batch = false, web = { endpoint } } = {}) {
10
10
  const client = bindApps(identity, contracts, { [own]: { ...web, endpoint: new URL(web.endpoint, location.origin) } })[own];
11
11
  const lifetime = new AbortController();
12
12
  const context = globalThis.document?.modelContext;
@@ -14,7 +14,10 @@ export async function connect({ identity, contracts, own, endpoint }, { tools =
14
14
  // Aborting the lifetime unregisters every tool. https://webmachinelearning.github.io/webmcp/#dom-modelcontext-registertool
15
15
  if (context) {
16
16
  const { signal } = lifetime;
17
- const offer = tool => context.registerTool(tool, { signal }).catch(error => console.warn(`WebMCP did not accept the tool ${tool.name}:`, error));
17
+ const offered = new Map();
18
+ const register = tool => context.registerTool(tool, { signal }).then(() => true, error => console.warn(`WebMCP did not accept the tool ${tool.name}:`, error));
19
+ const offer = async tool => await register(tool) && offered.set(tool.name, tool);
20
+ if (batch) register(batchTool(offered));
18
21
  for (const [name, tool] of Object.entries(tools)) offer(pageTool(name, tool));
19
22
  const contracted = name => !contracts[own] || contracts[own].tools.some(tool => tool.name === name);
20
23
  client.listTools({ signal }).then(
@@ -61,6 +64,28 @@ function serverTool(own, client, tool, inputSchema) {
61
64
  };
62
65
  }
63
66
 
67
+ function batchTool(offered) {
68
+ const call = { type: "object", properties: { tool: { type: "string" }, input: { type: "object" } }, required: ["tool", "input"] };
69
+ return {
70
+ name: "call_tools",
71
+ description: "Run several of this page's tools in order, in one call. Stops at the first that fails, and returns the outputs before it and its error.",
72
+ inputSchema: { type: "object", properties: { calls: { type: "array", items: call } }, required: ["calls"] },
73
+ annotations: hints(),
74
+ execute: async ({ calls }, client) => {
75
+ const outputs = [];
76
+ try {
77
+ for (const { tool, input } of calls) {
78
+ client.signal.throwIfAborted();
79
+ outputs.push(await offered.get(tool).execute(input, client));
80
+ }
81
+ } catch (error) {
82
+ return { outputs, error: String(error) };
83
+ }
84
+ return { outputs };
85
+ },
86
+ };
87
+ }
88
+
64
89
  // MCP's hints default to the cautious reading (not read-only, destructive, open-world); WebMCP's all default to false.
65
90
  // So each MCP hint is read with its own default, then translated, and an unannotated tool stays consequential.
66
91
  // https://modelcontextprotocol.io/specification/2026-07-28/schema#toolannotations