holon-sh 0.0.1-dev.5 → 0.0.1-dev.6

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
@@ -10,7 +10,7 @@ This repository contains the Node.js runtime for [`holon`](https://github.com/ho
10
10
 
11
11
  ```sh
12
12
  npm install holon-sh@dev
13
- npm install -D holon-types
13
+ npm install -D holon-types@next
14
14
  ```
15
15
 
16
16
  `holon-types` is the `holon` CLI. `holon types check` brings its own TypeScript compiler and uses the project's `typescript` when one is installed.
@@ -65,7 +65,7 @@ try {
65
65
  ```ts
66
66
  const result = await apps.bar.callTool({ name: "greet", arguments: { name: "world" } });
67
67
  if (result.resultType === "input_required") {
68
- // call again with inputResponses and requestState, or bind elicit to answer in place
68
+ // call again with inputResponses and requestState
69
69
  } else if (result.isError) {
70
70
  // inspect result.content
71
71
  } else {
@@ -78,20 +78,15 @@ if (result.resultType === "input_required") {
78
78
  <details open>
79
79
  <summary><h3>Answer a server's question</h3></summary>
80
80
 
81
- A tool can stop and ask for input through an [MCP elicitation](https://modelcontextprotocol.io/specification/2026-07-28/client/elicitation). Bind `elicit` to answer in place, and the call returns its usual typed output:
81
+ A tool can stop and ask for input through an [MCP elicitation](https://modelcontextprotocol.io/specification/2026-07-28/client/elicitation). Pass `elicit` to answer in place, and the call returns its usual typed output:
82
82
 
83
83
  ```ts
84
- const apps = createApps({
85
- bar: {
86
- endpoint: "https://bar.example.com/mcp",
87
- elicit: async ({ params }) => ({ action: "accept", content: await ask(params.message) }),
88
- },
84
+ const greeting = await apps.bar.tools.greet({ name: "world" }, {
85
+ elicit: async ({ message }) => ({ action: "accept", content: await ask(message) }),
89
86
  });
90
-
91
- const greeting = await apps.bar.tools.greet({ name: "world" });
92
87
  ```
93
88
 
94
- To answer later, for example in another request, declare `capabilities: { elicitation: { form: {} } }` instead. The question then arrives as an `input_required` result from `callTool`, or on `ToolCallError.result` from `tools`. Without either option, a server that needs the capability rejects the call.
89
+ Without `elicit`, the question arrives on `ToolCallError.result`, or as an `input_required` result from `callTool`. To answer later, for example in another request, call again with `inputResponses` and `requestState`.
95
90
 
96
91
  </details>
97
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holon-sh",
3
- "version": "0.0.1-dev.5",
3
+ "version": "0.0.1-dev.6",
4
4
  "description": "Typed MCP clients and app view resources for Node.js.",
5
5
  "repository": {
6
6
  "type": "git",
package/protocol.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- import type { CallToolRequest, CallToolResult, ClientCapabilities as McpClientCapabilities, ClientContext, ElicitRequest, ElicitResult, InputRequiredResult, InputResponses, ListToolsResult, RequestOptions } from "@modelcontextprotocol/client";
1
+ import type { CallToolRequest, CallToolResult, ElicitRequestParams, ElicitResult, InputRequiredResult, InputResponses, ListToolsResult, RequestOptions } from "@modelcontextprotocol/client";
2
2
 
3
3
  /** Bearer-token or OAuth provider accepted by the MCP transport. */
4
4
  export type AuthProvider =
5
5
  | { token(): Promise<string | undefined>; onUnauthorized?(context: unknown): Promise<void> }
6
6
  | { tokens(): unknown; redirectUrl: unknown; clientMetadata: unknown };
7
- /** MCP client capabilities, such as `{ elicitation: { form: {} } }`. */
8
- export type ClientCapabilities = McpClientCapabilities;
9
- /** Answers a server's elicitation so the call that asked can complete. */
10
- export type ElicitHandler = (request: ElicitRequest, context: ClientContext) => ElicitResult | Promise<ElicitResult>;
7
+ /** Answers a server's question so the call that asked can complete. `params.mode` tells a form from a URL to open. */
8
+ export type ElicitHandler = (params: ElicitRequestParams) => ElicitResult | Promise<ElicitResult>;
11
9
 
12
10
  /** MCP request options, including AbortSignal and timeout in milliseconds. Input-required responses are enabled by the runtime. */
13
11
  export type CallOptions = Omit<RequestOptions, "allowInputRequired">;
12
+ /** Call options for a tool. `elicit` answers its questions in place, so the call returns the completed result. */
13
+ export type ToolCallOptions = CallOptions & { elicit?: ElicitHandler };
14
14
  /** MCP request metadata and input continuation fields. Pass inputResponses and requestState when continuing an input-required result. */
15
15
  export type CallMetadata = Omit<CallToolRequest["params"], "name" | "arguments"> & { inputResponses?: InputResponses; requestState?: string };
16
16
  /** @internal */
@@ -23,7 +23,7 @@ export type ToolResult<Output> =
23
23
  | (Omit<Fields<CallToolResult>, "structuredContent" | "isError"> & { resultType: "complete"; isError: true; structuredContent?: unknown })
24
24
  | InputRequiredResult;
25
25
 
26
- /** Error thrown by the tools convenience methods for error or input_required results. Inspect the original result; bind elicit to answer questions in place, or use callTool to continue later. */
26
+ /** Error thrown by the tools convenience methods for error or input_required results. Inspect the original result; pass elicit to answer questions in place, or continue later through callTool. */
27
27
  export declare class ToolCallError extends Error {
28
28
  readonly result: Extract<ToolResult<unknown>, { isError: true } | { resultType: "input_required" }>;
29
29
  constructor(app: string, tool: string, result: ToolCallError["result"]);
@@ -40,8 +40,8 @@ export interface ToolClient<I, O, R> {
40
40
  readonly read: (options?: CallOptions) => Promise<R[U]>;
41
41
  readonly watch: (onChange: (value: R[U]) => void | Promise<void>, options?: { signal?: AbortSignal }) => Promise<void>;
42
42
  } };
43
- /** Convenience methods returning structured output, or the complete result for a tool without an output schema. Error results throw ToolCallError, as do input-required results when the binding has no elicit. Reserved object method names remain callable through callTool. */
44
- readonly tools: { readonly [K in Exclude<keyof I, "then" | "toJSON" | "toString" | "valueOf" | "toLocaleString">]: (input: I[K], options?: CallOptions) => Promise<K extends keyof O ? O[K] : CompleteResult<unknown>> };
45
- /** Return the full MCP result, preserving error results and, when the binding has no elicit, input-required results. Arguments and successful output are contract-validated. */
46
- readonly callTool: <K extends keyof I & string>(request: CallMetadata & { name: K; arguments: I[K] }, options?: CallOptions) => Promise<ToolResult<K extends keyof O ? O[K] : unknown>>;
43
+ /** Convenience methods returning structured output, or the complete result for a tool without an output schema. Error results throw ToolCallError, as do questions left unanswered. Reserved object method names remain callable through callTool. */
44
+ readonly tools: { readonly [K in Exclude<keyof I, "then" | "toJSON" | "toString" | "valueOf" | "toLocaleString">]: (input: I[K], options?: ToolCallOptions) => Promise<K extends keyof O ? O[K] : CompleteResult<unknown>> };
45
+ /** Return the full MCP result, preserving error results and questions left unanswered. Arguments and successful output are contract-validated. */
46
+ readonly callTool: <K extends keyof I & string>(request: CallMetadata & { name: K; arguments: I[K] }, options?: ToolCallOptions) => Promise<ToolResult<K extends keyof O ? O[K] : unknown>>;
47
47
  }
package/runtime.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { AuthProvider, CallOptions, ClientCapabilities, ElicitHandler, ToolClient } from "./protocol.js";
1
+ import type { AuthProvider, CallOptions, ToolClient } from "./protocol.js";
2
2
  export { ToolCallError } from "./protocol.js";
3
- export type { AuthProvider, CallOptions, CallMetadata, ClientCapabilities, ElicitHandler, ToolResult, ToolClient } from "./protocol.js";
3
+ export type { AuthProvider, CallOptions, CallMetadata, ElicitHandler, ToolCallOptions, ToolResult, ToolClient } from "./protocol.js";
4
4
 
5
5
  /** Connection settings for an MCP endpoint. */
6
6
  export interface Binding {
@@ -14,10 +14,6 @@ export interface Binding {
14
14
  installationUID?: string;
15
15
  /** Close the session after every call instead of keeping one connection open. */
16
16
  scoped?: boolean;
17
- /** Client capabilities declared to the server. On protocol 2026-07-28 every request carries them in `_meta["io.modelcontextprotocol/clientCapabilities"]` ([spec](https://modelcontextprotocol.io/specification/2026-07-28/client/elicitation#capabilities)); declare `{ elicitation: { form: {} } }` to receive form elicitations in input-required results, or set `elicit` to answer them. */
18
- capabilities?: ClientCapabilities;
19
- /** Answers elicitations in place, so `tools.x` and `callTool` return the completed result. Declares `{ elicitation: { form: {} } }` unless `capabilities` sets `elicitation`. */
20
- elicit?: ElicitHandler;
21
17
  }
22
18
  /** Alias for an endpoint binding. */
23
19
  export type EndpointBinding = Binding;
package/runtime.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { Client, MissingRequiredClientCapabilityError, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
1
+ import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
2
2
  import { validator as defaultValidator } from "./validate.mjs";
3
3
 
4
4
  // Shared with the private @holon-sh/sdk and existing hosts.
@@ -21,10 +21,11 @@ function environment(identity, name) {
21
21
 
22
22
  export class ToolCallError extends Error {
23
23
  constructor(app, tool, result) {
24
- const detail = result.content?.find(part => part.type === "text")?.text;
25
- const message = result.resultType === "input_required" ? "additional input required"
26
- : detail ? `tool failed: ${detail}` : "tool failed";
27
- super(`${app}.${tool}: ${message}`);
24
+ const asking = result.resultType === "input_required";
25
+ const detail = asking
26
+ ? Object.values(result.inputRequests ?? {}).flatMap(({ params }) => [params?.message, params?.url]).filter(Boolean).join(" ")
27
+ : result.content?.find(part => part.type === "text")?.text;
28
+ super(`${app}.${tool}: ${asking ? "additional input required" : "tool failed"}${detail ? `: ${detail}` : ""}`);
28
29
  this.name = "ToolCallError";
29
30
  this.result = result;
30
31
  }
@@ -69,10 +70,9 @@ export function createApps(identity, contracts, bindings, options) {
69
70
  const current = () => binding ?? (bindings ? undefined : resolve(name));
70
71
  let connection;
71
72
  const connect = resolved => {
73
+ // Every client can be asked: a call answers with elicit, or the question reaches its caller. Servers must not assume a client answers: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr#server-requirements-basic-workflow
72
74
  // On 2026-07-28 the client sends these capabilities in every request's _meta: https://github.com/modelcontextprotocol/typescript-sdk/blob/fcef852f6cdafea07f36cf6fae69b37c8adf85be/packages/client/src/client/client.ts#L700-L711
73
- const capabilities = resolved.elicit ? { elicitation: { form: {} }, ...resolved.capabilities } : resolved.capabilities;
74
- const client = new Client({ name: identity.name, version: identity.version }, { capabilities, versionNegotiation: { mode: "auto" } });
75
- if (resolved.elicit) client.setRequestHandler("elicitation/create", resolved.elicit);
75
+ const client = new Client({ name: identity.name, version: identity.version }, { capabilities: { elicitation: { form: {}, url: {} } }, versionNegotiation: { mode: "auto" } });
76
76
  const transport = new StreamableHTTPClientTransport(new URL(resolved.endpoint), { authProvider: resolved.authProvider, fetch: resolved.fetch, requestInit: { credentials: "include", redirect: "error", headers: resolved.installationUID ? { "X-Holon-Installation-UID": resolved.installationUID } : {} } });
77
77
  const current = { client, close: async () => {
78
78
  await transport.close();
@@ -100,12 +100,12 @@ export function createApps(identity, contracts, bindings, options) {
100
100
  const active = scoped ? connect(resolved) : (connection ??= connect(resolved));
101
101
  try {
102
102
  await untilAborted(active.ready, options?.signal);
103
- return await run(active.client, resolved);
103
+ return await run(active.client);
104
104
  } finally { if (scoped) await active.close(); }
105
105
  };
106
106
  const tools = Object.create(null);
107
107
  const definitions = new Map((contract?.tools ?? []).map(definition => [definition.name, { definition }]));
108
- const callTool = async (request, options) => {
108
+ const callTool = async (request, { elicit, ...options } = {}) => {
109
109
  const tool = definitions.get(request.name);
110
110
  if (!tool && contract) throw new Error(`Unknown tool ${name}.${request.name}.`);
111
111
  let validation;
@@ -117,13 +117,19 @@ export function createApps(identity, contracts, bindings, options) {
117
117
  };
118
118
  validate(validation.input, request.arguments, `arguments for ${name}.${request.name}`);
119
119
  }
120
- // With a handler the MCP client answers input requests and retries; without one the caller gets the question.
121
- const result = await session(options, (client, resolved) => client.callTool(request, {
122
- ...options, allowInputRequired: !resolved?.elicit,
123
- ...(tool && { toolDefinition: { ...tool.definition, outputSchema: undefined } }),
124
- })).catch(error => {
125
- if (error instanceof MissingRequiredClientCapabilityError) error.message = `${name}.${request.name}: ${error.message}. Set elicit or capabilities on the binding.`;
126
- throw error;
120
+ const result = await session(options, async client => {
121
+ const send = request => client.callTool(request, {
122
+ ...options, allowInputRequired: true,
123
+ ...(tool && { toolDefinition: { ...tool.definition, outputSchema: undefined } }),
124
+ });
125
+ let result = await send(request);
126
+ // A server may keep asking, so answering stops after ten rounds, the MCP clients' own limit, and the last question reaches the caller.
127
+ for (let round = 0; elicit && result.resultType === "input_required" && round < 10; round++) {
128
+ const inputResponses = {};
129
+ for (const [key, { params }] of Object.entries(result.inputRequests ?? {})) inputResponses[key] = await elicit(params);
130
+ result = await send({ ...request, inputResponses, requestState: result.requestState });
131
+ }
132
+ return result;
127
133
  });
128
134
  if (result.resultType === "input_required") return result;
129
135
  if (!result.isError && validation?.output) {