holon-ui 0.0.1-dev.22 → 0.0.1-dev.23

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 CHANGED
@@ -70,6 +70,7 @@ const app = await connect({
70
70
  select_shapes: {
71
71
  description: "Select shapes on the board the person is looking at.",
72
72
  inputSchema: z.object({ ids: z.array(z.string()) }),
73
+ outputSchema: z.object({ selected: z.array(z.string()) }),
73
74
  annotations: { destructiveHint: false, openWorldHint: false },
74
75
  execute: ({ ids }) => ({ selected: board.select(ids) }),
75
76
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holon-ui",
3
- "version": "0.0.1-dev.22",
3
+ "version": "0.0.1-dev.23",
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
@@ -5,20 +5,22 @@ export type { CreateOptions, EndpointBinding, Identity, Contract, RuntimeClient
5
5
  export type { AuthProvider, CallOptions, CallMetadata, ToolResult, ToolClient } from "holon-sh/runtime";
6
6
  export { bindApps, ToolCallError } from "holon-sh/runtime";
7
7
 
8
- /** A tool the page declares. It runs in the browser and acts on what the person is looking at. S is its input schema's type. */
9
- export interface PageTool<S = undefined> {
8
+ /** A tool the page declares. It runs in the browser and acts on what the person is looking at. S and O are its input and output schemas' types. */
9
+ export interface PageTool<S = undefined, O = undefined> {
10
10
  /** Shown to the agent. Required and non-empty. */
11
11
  description: string;
12
12
  /** Validates the agent's arguments, such as a Zod 4 object. Without one the tool takes no arguments. */
13
13
  inputSchema?: S & StandardSchemaWithJSON;
14
+ /** Describes and validates the object execute returns, such as a Zod 4 object. */
15
+ outputSchema?: O & StandardSchemaWithJSON;
14
16
  annotations?: ToolAnnotations;
15
17
  /** Receives validated input. Returns a JSON value, or a promise of one; throwing reports failure. signal aborts when the agent cancels. */
16
- execute: (input: S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : Record<string, never>, options: { signal: AbortSignal }) => unknown;
18
+ execute: (input: S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : Record<string, never>, options: { signal: AbortSignal }) => O extends StandardSchemaV1 ? StandardSchemaV1.InferInput<O> | Promise<StandardSchemaV1.InferInput<O>> : unknown;
17
19
  }
18
- // S is inferred per tool. A tool without an input schema leaves its slot unknown, so the slots are unconstrained.
19
- export interface ConnectOptions<S extends Record<string, unknown> = {}> {
20
+ // S and O are inferred per tool. A tool without a schema leaves its slot unknown, so the slots are unconstrained.
21
+ export interface ConnectOptions<S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}> {
20
22
  /** Page tools by name, offered to the host's agent in an MCP Apps host and to the browser's agent through WebMCP. */
21
- tools?: { [K in keyof S]: PageTool<S[K]> };
23
+ tools?: { [K in keyof S]: PageTool<S[K], O[K & keyof O]> } & { [K in keyof O]: { outputSchema?: O[K] & StandardSchemaWithJSON } };
22
24
  /** On a web page, also offer call_tools, which runs several of the other offered tools in one call. Ignored in an MCP Apps host, whose agent calls the app's tools itself. */
23
25
  batch?: "call_tools" extends keyof S ? false : boolean;
24
26
  /** The ext-apps App's options in an MCP Apps host, and the transport to connect it with; ignored on a web page. */
@@ -50,9 +52,9 @@ export type Page<C> =
50
52
  readonly opened: undefined;
51
53
  });
52
54
  /** 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. */
53
- 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>>;
55
+ export type Connect<C> = <S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(options?: ConnectOptions<S, O> & { tools?: { [K in keyof Tools<C>]?: never }; batch?: "call_tools" extends keyof Tools<C> ? false : boolean }) => Promise<Page<C>>;
54
56
  /** 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. */
55
- export declare function connect<S extends Record<string, unknown> = {}>(
57
+ export declare function connect<S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(
56
58
  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 },
57
- options?: ConnectOptions<S>,
59
+ options?: ConnectOptions<S, O>,
58
60
  ): Promise<Page<RuntimeClient>>;
package/runtime.host.mjs CHANGED
@@ -11,10 +11,14 @@ export async function connect({ identity, contracts, own }, { tools = {}, view:
11
11
  const bind = session => bindApps(identity, contracts, { [own]: { session } })[own];
12
12
  const app = new App({ name: identity.name, version: identity.version }, {}, options);
13
13
  // Registered before connecting, so the view declares the tools capability in ui/initialize.
14
- for (const [name, { description, inputSchema, annotations, execute }] of Object.entries(tools)) {
14
+ for (const [name, { description, inputSchema, outputSchema, annotations, execute }] of Object.entries(tools)) {
15
+ const output = outputSchema?.["~standard"];
15
16
  const run = async (input, { mcpReq: { signal } }) => {
16
17
  try {
17
- return toolResult(await execute(input, { signal }));
18
+ const result = await execute(input, { signal });
19
+ const checked = output ? await output.validate(result) : { value: result };
20
+ if (checked.issues) throw new Error(`Invalid output for ${name}: ${JSON.stringify(checked.issues)}`);
21
+ return toolResult(checked.value);
18
22
  } catch (error) {
19
23
  // A tool's own failure is a result the agent can read, not a protocol error.
20
24
  // https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling
@@ -22,7 +26,7 @@ export async function connect({ identity, contracts, own }, { tools = {}, view:
22
26
  }
23
27
  };
24
28
  // ext-apps validates input against inputSchema first, and calls a tool without one with the request context alone.
25
- app.registerTool(name, { description, inputSchema, annotations }, inputSchema ? run : extra => run({}, extra));
29
+ app.registerTool(name, { description, inputSchema, outputSchema: output && { "~standard": { ...output, validate: value => ({ value }) } }, annotations }, inputSchema ? run : extra => run({}, extra));
26
30
  }
27
31
  // The host sends the call that opened the view once, right after the handshake, so listen before connecting.
28
32
  // https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#data-passing
package/runtime.web.mjs CHANGED
@@ -37,15 +37,20 @@ export async function connect({ identity, contracts, own, endpoint }, { tools =
37
37
  return Object.freeze({ ...client, view: undefined, opened: undefined, close: async () => { lifetime.abort(); await client.close(); } });
38
38
  }
39
39
 
40
- function pageTool(name, { description, inputSchema, annotations, execute }) {
40
+ function pageTool(name, { description, inputSchema, outputSchema, annotations, execute }) {
41
41
  const standard = inputSchema?.["~standard"];
42
+ const output = outputSchema?.["~standard"];
42
43
  return {
43
44
  name, title: annotations?.title, description, annotations: hints(annotations),
44
45
  inputSchema: standard?.jsonSchema.input({ target: "draft-2020-12" }),
46
+ outputSchema: output?.jsonSchema.output({ target: "draft-2020-12" }),
45
47
  execute: async (input, { signal }) => {
46
48
  const parsed = standard ? await standard.validate(input) : { value: {} };
47
49
  if (parsed.issues) throw new Error(`Invalid arguments for ${name}: ${JSON.stringify(parsed.issues)}`);
48
- return execute(parsed.value, { signal });
50
+ const result = await execute(parsed.value, { signal });
51
+ const checked = output ? await output.validate(result) : { value: result };
52
+ if (checked.issues) throw new Error(`Invalid output for ${name}: ${JSON.stringify(checked.issues)}`);
53
+ return checked.value;
49
54
  },
50
55
  };
51
56
  }