holon-ui 0.0.1-dev.23 → 0.0.1-dev.24
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/dist/page.d.ts +86 -0
- package/dist/page.js +1 -0
- package/dist/runtime.host.d.ts +4 -0
- package/dist/runtime.host.js +67 -0
- package/dist/runtime.web.d.ts +6 -0
- package/dist/runtime.web.js +137 -0
- package/{vite.d.ts → dist/vite.d.ts} +0 -1
- package/dist/vite.js +44 -0
- package/package.json +10 -13
- package/runtime.d.ts +0 -60
- package/runtime.host.mjs +0 -62
- package/runtime.web.mjs +0 -125
- package/vite.mjs +0 -39
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { App, AppOptions } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { StandardSchemaV1, StandardSchemaWithJSON, ToolAnnotations } from "@modelcontextprotocol/client";
|
|
3
|
+
import type { EndpointBinding, Identity, Contract, RuntimeClient, SessionClient, ToolClient } from "holon-sh/runtime";
|
|
4
|
+
export type { CreateOptions, EndpointBinding, Identity, Contract, RuntimeClient } from "holon-sh/runtime";
|
|
5
|
+
export type { AuthProvider, CallOptions, CallMetadata, ToolResult, ToolClient } from "holon-sh/runtime";
|
|
6
|
+
/** 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. */
|
|
7
|
+
export interface PageTool<S = undefined, O = undefined> {
|
|
8
|
+
/** Shown to the agent. Required and non-empty. */
|
|
9
|
+
description: string;
|
|
10
|
+
/** Validates the agent's arguments, such as a Zod 4 object. Without one the tool takes no arguments. */
|
|
11
|
+
inputSchema?: S & StandardSchemaWithJSON;
|
|
12
|
+
/** Describes and validates the object execute returns, such as a Zod 4 object. */
|
|
13
|
+
outputSchema?: O & StandardSchemaWithJSON;
|
|
14
|
+
annotations?: ToolAnnotations;
|
|
15
|
+
/** 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: {
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
}): O extends StandardSchemaV1 ? StandardSchemaV1.InferInput<O> | Promise<StandardSchemaV1.InferInput<O>> : unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface AnyPageTool {
|
|
21
|
+
description: string;
|
|
22
|
+
inputSchema?: StandardSchemaWithJSON;
|
|
23
|
+
outputSchema?: StandardSchemaWithJSON;
|
|
24
|
+
annotations?: ToolAnnotations;
|
|
25
|
+
execute(input: unknown, options: {
|
|
26
|
+
signal: AbortSignal;
|
|
27
|
+
}): unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ConnectOptions<S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}> {
|
|
30
|
+
/** Page tools by name, offered to the host's agent in an MCP Apps host and to the browser's agent through WebMCP. */
|
|
31
|
+
tools?: {
|
|
32
|
+
[K in keyof S]: PageTool<S[K], O[K & keyof O]>;
|
|
33
|
+
} & {
|
|
34
|
+
[K in keyof O]: {
|
|
35
|
+
outputSchema?: O[K] & StandardSchemaWithJSON;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** 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. */
|
|
39
|
+
batch?: "call_tools" extends keyof S ? false : boolean;
|
|
40
|
+
/** The ext-apps App's options in an MCP Apps host, and the transport to connect it with; ignored on a web page. */
|
|
41
|
+
view?: AppOptions & {
|
|
42
|
+
transport?: Parameters<App["connect"]>[0];
|
|
43
|
+
};
|
|
44
|
+
/** 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. */
|
|
45
|
+
web?: EndpointBinding;
|
|
46
|
+
}
|
|
47
|
+
type Client = ToolClient<any, any, any, any>;
|
|
48
|
+
/** The tool call that opened a view: typed by its tool, or untyped when the host does not say which tool it was. */
|
|
49
|
+
export type Opened<C extends Client> = {
|
|
50
|
+
[K in keyof C["tools"] & string]: C["tools"][K] extends (input: infer I, ...rest: never[]) => Promise<infer O> ? {
|
|
51
|
+
tool: K;
|
|
52
|
+
input: I;
|
|
53
|
+
output: O;
|
|
54
|
+
} : never;
|
|
55
|
+
}[keyof C["tools"] & string] | {
|
|
56
|
+
tool: undefined;
|
|
57
|
+
input: Record<string, unknown>;
|
|
58
|
+
output: unknown;
|
|
59
|
+
};
|
|
60
|
+
/** The page's own app C, as a view in an MCP Apps host or as a web page, told apart by view. Only a web page can list the app's tools, watch a resource or subscribe to events. close() also unregisters the page's tools and closes the view. */
|
|
61
|
+
export type Page<C extends Client> = (SessionClient<C> & {
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
/** The connected ext-apps App, for host-only features. */
|
|
64
|
+
readonly view: App;
|
|
65
|
+
/** The tool call that opened the view, with the output its tool returns. */
|
|
66
|
+
readonly opened: Promise<Opened<C>>;
|
|
67
|
+
}) | (C & {
|
|
68
|
+
/** Undefined on a web page. */
|
|
69
|
+
readonly view: undefined;
|
|
70
|
+
readonly opened: undefined;
|
|
71
|
+
});
|
|
72
|
+
/** 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. */
|
|
73
|
+
export type Connect<C extends Client> = <S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(options?: ConnectOptions<S, O> & {
|
|
74
|
+
tools?: {
|
|
75
|
+
[K in keyof C["tools"]]?: never;
|
|
76
|
+
};
|
|
77
|
+
batch?: "call_tools" extends keyof C["tools"] ? false : boolean;
|
|
78
|
+
}) => Promise<Page<C>>;
|
|
79
|
+
export interface OwnApp {
|
|
80
|
+
identity: Identity;
|
|
81
|
+
contracts: Record<string, Contract | null>;
|
|
82
|
+
own: string;
|
|
83
|
+
/** The app's MCP endpoint on the page's origin, such as "/mcp/checkout". */
|
|
84
|
+
endpoint: string;
|
|
85
|
+
}
|
|
86
|
+
export type Runtime = <S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(app: OwnApp, options?: ConnectOptions<S, O>) => Promise<Page<RuntimeClient>>;
|
package/dist/page.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// holon-ui/runtime for an MCP Apps view in a host's iframe: package.json resolves to it under the mcp-app condition,
|
|
2
|
+
// which the view's build sets. The host is the app's MCP client, so its agent already has the app's tools: the view
|
|
3
|
+
// offers it only the page's own tools, and calls its app through the host.
|
|
4
|
+
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#standard-mcp-messages
|
|
5
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
6
|
+
import { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
7
|
+
export { bindApps, ToolCallError };
|
|
8
|
+
export const connect = async ({ identity, contracts, own }, { tools = {}, view: { transport, ...options } = {} } = {}) => {
|
|
9
|
+
const bind = (session) => bindApps(identity, contracts, { [own]: { session } })[own];
|
|
10
|
+
const app = new App({ name: identity.name, version: identity.version }, {}, options);
|
|
11
|
+
const session = {
|
|
12
|
+
callTool: (request, { signal, timeout } = {}) => app.callServerTool(request, { signal, timeout }),
|
|
13
|
+
readResource: (request, { signal, timeout } = {}) => app.readServerResource(request, { signal, timeout }),
|
|
14
|
+
};
|
|
15
|
+
// Registered before connecting, so the view declares the tools capability in ui/initialize.
|
|
16
|
+
for (const [name, { description, inputSchema, outputSchema, annotations, execute }] of Object.entries(tools)) {
|
|
17
|
+
const output = outputSchema?.["~standard"];
|
|
18
|
+
const run = async (input, { mcpReq: { signal } }) => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await execute(input, { signal });
|
|
21
|
+
const checked = output ? await output.validate(result) : { value: result };
|
|
22
|
+
if (checked.issues)
|
|
23
|
+
throw new Error(`Invalid output for ${name}: ${JSON.stringify(checked.issues)}`);
|
|
24
|
+
return toolResult(checked.value);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
// A tool's own failure is a result the agent can read, not a protocol error.
|
|
28
|
+
// https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling
|
|
29
|
+
return { isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }] };
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// ext-apps validates input against inputSchema first, and calls a tool without one with the request context alone.
|
|
33
|
+
const listed = output && { "~standard": { ...output, validate: (value) => ({ value }) } };
|
|
34
|
+
if (inputSchema)
|
|
35
|
+
app.registerTool(name, { description, inputSchema, outputSchema: listed, annotations }, run);
|
|
36
|
+
else
|
|
37
|
+
app.registerTool(name, { description, outputSchema: listed, annotations }, extra => run({}, extra));
|
|
38
|
+
}
|
|
39
|
+
// The host sends the call that opened the view once, right after the handshake, so listen before connecting.
|
|
40
|
+
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#data-passing
|
|
41
|
+
const delivered = new Promise((resolve, reject) => {
|
|
42
|
+
let input = {};
|
|
43
|
+
app.addEventListener("toolinput", params => { input = params.arguments ?? {}; });
|
|
44
|
+
app.addEventListener("toolresult", result => resolve({ input, result }));
|
|
45
|
+
app.addEventListener("toolcancelled", ({ reason }) => reject(new Error(`The tool call that opened the view was cancelled${reason ? `: ${reason}` : "."}`)));
|
|
46
|
+
});
|
|
47
|
+
await app.connect(transport);
|
|
48
|
+
// Replaying the delivered result through the app's own client gives exactly what calling the tool would have: the
|
|
49
|
+
// same output validation and ToolCallError. When the host does not say which tool it was, the call comes as delivered.
|
|
50
|
+
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#host-context-in-mcpuiinitializeresult
|
|
51
|
+
const opened = delivered.then(async ({ input, result }) => {
|
|
52
|
+
const tool = app.getHostContext()?.toolInfo?.tool.name;
|
|
53
|
+
const replay = tool && bind({ ...session, callTool: async () => result }).tools[tool];
|
|
54
|
+
return replay ? { tool, input, output: await replay(input) } : { tool: undefined, input, output: result };
|
|
55
|
+
});
|
|
56
|
+
// A page that never reads opened must not see an unhandled rejection.
|
|
57
|
+
opened.catch(() => { });
|
|
58
|
+
const client = bind(session);
|
|
59
|
+
// Closing the view removes its tools from the host.
|
|
60
|
+
return Object.freeze({ tools: client.tools, callTool: client.callTool, resources: client.resources, view: app, opened, close: () => app.close() });
|
|
61
|
+
};
|
|
62
|
+
function toolResult(value) {
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
return { content: [] };
|
|
65
|
+
const structured = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
return { content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value) }], ...(structured && { structuredContent: value }) };
|
|
67
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
2
|
+
import type { Runtime } from "./page.js";
|
|
3
|
+
export { bindApps, ToolCallError };
|
|
4
|
+
export type { AuthProvider, CallMetadata, CallOptions, Connect, ConnectOptions, Contract, CreateOptions, EndpointBinding, Identity, Opened, Page, PageTool, RuntimeClient, ToolClient, ToolResult } from "./page.js";
|
|
5
|
+
/** 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. */
|
|
6
|
+
export declare const connect: Runtime;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// holon-ui/runtime for a web page, a document of its own: package.json resolves to it unless the build sets mcp-app.
|
|
2
|
+
// The page calls its app over HTTP, and the browser's agent, if any, learns every tool through WebMCP, because nothing
|
|
3
|
+
// else tells it about them. https://webmachinelearning.github.io/webmcp/#dom-document-modelcontext
|
|
4
|
+
import { fromJsonSchema, getDisplayName } from "@modelcontextprotocol/client";
|
|
5
|
+
import { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
6
|
+
export { bindApps, ToolCallError };
|
|
7
|
+
/** 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. */
|
|
8
|
+
export const connect = async ({ identity, contracts, own, endpoint }, { tools = {}, batch = false, web = { endpoint } } = {}) => {
|
|
9
|
+
const client = bindApps(identity, contracts, { [own]: { ...web, endpoint: new URL(web.endpoint, location.origin) } })[own];
|
|
10
|
+
const lifetime = new AbortController();
|
|
11
|
+
const context = globalThis.document?.modelContext;
|
|
12
|
+
// Offering tools is secondary to the page working: the page does not wait for it, and a failure is only reported.
|
|
13
|
+
// Aborting the lifetime unregisters every tool. https://webmachinelearning.github.io/webmcp/#dom-modelcontext-registertool
|
|
14
|
+
if (context) {
|
|
15
|
+
const { signal } = lifetime;
|
|
16
|
+
const offered = new Map();
|
|
17
|
+
const register = (tool) => context.registerTool(tool, { signal }).then(() => true, error => console.warn(`WebMCP did not accept the tool ${tool.name}:`, error));
|
|
18
|
+
const offer = async (tool) => await register(tool) && offered.set(tool.name, tool);
|
|
19
|
+
const offers = Object.entries(tools).map(([name, tool]) => offer(pageTool(name, tool)));
|
|
20
|
+
const contracted = (name) => !contracts[own] || contracts[own].tools.some(tool => tool.name === name);
|
|
21
|
+
const listed = client.listTools({ signal }).then(({ tools: listed }) => {
|
|
22
|
+
for (const tool of listed) {
|
|
23
|
+
// MCP Apps: a tool whose visibility omits "model" must not reach the agent; absent means ["model", "app"].
|
|
24
|
+
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#resource-discovery
|
|
25
|
+
// A typed client calls only its contract's tools, and an agent cannot write a file argument.
|
|
26
|
+
if (!visibleToModel(tool) || !contracted(tool.name))
|
|
27
|
+
continue;
|
|
28
|
+
const inputSchema = withoutFiles(tool.inputSchema);
|
|
29
|
+
if (typeof inputSchema === "object" && inputSchema !== null)
|
|
30
|
+
offers.push(offer(serverTool(own, client, tool, inputSchema)));
|
|
31
|
+
}
|
|
32
|
+
}, error => signal.aborted || console.warn(`Could not list the tools of ${own} for WebMCP:`, error));
|
|
33
|
+
if (batch)
|
|
34
|
+
listed.then(() => Promise.all(offers)).then(() => offered.size > 0 && register(batchTool(offered)));
|
|
35
|
+
}
|
|
36
|
+
return Object.freeze({ ...client, view: undefined, opened: undefined, close: async () => { lifetime.abort(); await client.close(); } });
|
|
37
|
+
};
|
|
38
|
+
function visibleToModel(tool) {
|
|
39
|
+
const ui = tool._meta?.ui;
|
|
40
|
+
const visibility = typeof ui === "object" && ui !== null && "visibility" in ui ? ui.visibility ?? ["model"] : ["model"];
|
|
41
|
+
return Array.isArray(visibility) && visibility.includes("model");
|
|
42
|
+
}
|
|
43
|
+
function pageTool(name, { description, inputSchema, outputSchema, annotations, execute }) {
|
|
44
|
+
const standard = inputSchema?.["~standard"];
|
|
45
|
+
const output = outputSchema?.["~standard"];
|
|
46
|
+
return {
|
|
47
|
+
name, title: annotations?.title, description, annotations: hints(annotations),
|
|
48
|
+
inputSchema: standard?.jsonSchema.input({ target: "draft-2020-12" }),
|
|
49
|
+
outputSchema: output?.jsonSchema.output({ target: "draft-2020-12" }),
|
|
50
|
+
execute: async (input, { signal }) => {
|
|
51
|
+
const parsed = standard ? await standard.validate(input) : { value: {} };
|
|
52
|
+
if (parsed.issues)
|
|
53
|
+
throw new Error(`Invalid arguments for ${name}: ${JSON.stringify(parsed.issues)}`);
|
|
54
|
+
const result = await execute(parsed.value, { signal });
|
|
55
|
+
const checked = output ? await output.validate(result) : { value: result };
|
|
56
|
+
if (checked.issues)
|
|
57
|
+
throw new Error(`Invalid output for ${name}: ${JSON.stringify(checked.issues)}`);
|
|
58
|
+
return checked.value;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function serverTool(own, client, tool, inputSchema) {
|
|
63
|
+
return {
|
|
64
|
+
// MCP lets a tool go without a description; WebMCP requires one.
|
|
65
|
+
name: tool.name, title: tool.title ?? tool.annotations?.title, description: tool.description || getDisplayName(tool),
|
|
66
|
+
inputSchema, outputSchema: tool.outputSchema, annotations: hints(tool.annotations),
|
|
67
|
+
execute: async (input, { signal }) => {
|
|
68
|
+
const result = await client.callTool({ name: tool.name, arguments: input }, { signal });
|
|
69
|
+
// An agent can only supply arguments, so it cannot answer a question the server asks back.
|
|
70
|
+
if (result.resultType === "input_required" || result.isError)
|
|
71
|
+
throw new ToolCallError(own, tool.name, result);
|
|
72
|
+
return result.structuredContent ?? result.content;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function batchTool(offered) {
|
|
77
|
+
const call = { type: "object", properties: { tool: { enum: [...offered.keys()] }, input: { type: "object" } }, required: ["tool", "input"] };
|
|
78
|
+
const inputSchema = { type: "object", properties: { calls: { type: "array", items: call } }, required: ["calls"] };
|
|
79
|
+
const { validate } = fromJsonSchema(inputSchema)["~standard"];
|
|
80
|
+
const members = Object.fromEntries(offered);
|
|
81
|
+
const hinted = Object.values(members).map(tool => tool.annotations);
|
|
82
|
+
return {
|
|
83
|
+
name: "call_tools",
|
|
84
|
+
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.",
|
|
85
|
+
inputSchema,
|
|
86
|
+
annotations: {
|
|
87
|
+
readOnlyHint: hinted.every(hint => hint.readOnlyHint),
|
|
88
|
+
consequentialHint: hinted.some(hint => hint.consequentialHint),
|
|
89
|
+
untrustedContentHint: hinted.some(hint => hint.untrustedContentHint),
|
|
90
|
+
},
|
|
91
|
+
execute: async (input, client) => {
|
|
92
|
+
const outputs = [];
|
|
93
|
+
try {
|
|
94
|
+
const parsed = await validate(input);
|
|
95
|
+
if (parsed.issues)
|
|
96
|
+
throw new Error(`Invalid arguments for call_tools: ${JSON.stringify(parsed.issues)}`);
|
|
97
|
+
for (const { tool, input } of parsed.value.calls) {
|
|
98
|
+
client.signal.throwIfAborted();
|
|
99
|
+
outputs.push(await members[tool].execute(input, client));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return { outputs, error: String(error) };
|
|
104
|
+
}
|
|
105
|
+
return { outputs };
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// MCP's hints default to the cautious reading (not read-only, destructive, open-world); WebMCP's all default to false.
|
|
110
|
+
// So each MCP hint is read with its own default, then translated, and an unannotated tool stays consequential.
|
|
111
|
+
// https://modelcontextprotocol.io/specification/2026-07-28/schema#toolannotations
|
|
112
|
+
// https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations
|
|
113
|
+
function hints(annotations) {
|
|
114
|
+
const readOnlyHint = annotations?.readOnlyHint === true;
|
|
115
|
+
return { readOnlyHint, consequentialHint: !readOnlyHint && annotations?.destructiveHint !== false, untrustedContentHint: annotations?.openWorldHint !== false };
|
|
116
|
+
}
|
|
117
|
+
const FILE = Symbol("schema requires a file");
|
|
118
|
+
// An agent writes arguments as tokens, so it is not shown a file argument (x-mcp-file): an anyOf or oneOf branch that
|
|
119
|
+
// holds one is left out, and a tool that still has one is not exposed.
|
|
120
|
+
// https://github.com/modelcontextprotocol/experimental-ext-file-uploads/blob/main/specification/draft/file-uploads.md#file-arguments
|
|
121
|
+
function withoutFiles(node, key) {
|
|
122
|
+
if (Array.isArray(node)) {
|
|
123
|
+
const items = node.map(item => withoutFiles(item));
|
|
124
|
+
if (!items.includes(FILE))
|
|
125
|
+
return items;
|
|
126
|
+
if (key !== "anyOf" && key !== "oneOf")
|
|
127
|
+
return FILE;
|
|
128
|
+
const kept = items.filter(item => item !== FILE);
|
|
129
|
+
return kept.length ? kept : FILE;
|
|
130
|
+
}
|
|
131
|
+
if (typeof node !== "object" || node === null)
|
|
132
|
+
return node;
|
|
133
|
+
if (Object.hasOwn(node, "x-mcp-file"))
|
|
134
|
+
return FILE;
|
|
135
|
+
const entries = Object.entries(node).map(([key, value]) => [key, withoutFiles(value, key)]);
|
|
136
|
+
return entries.some(([, value]) => value === FILE) ? FILE : Object.fromEntries(entries);
|
|
137
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
|
|
3
2
|
/** Builds the page in ui/index.html twice in one vite build: the web page into dist/web, and into dist/mcp the MCP Apps view, one self-contained HTML file whose holon-ui calls its app through the host. A view that would need a file beside it fails the build. */
|
|
4
3
|
export declare function holon(): Plugin;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Builds the page in ui/index.html twice in one vite build: the web page into dist/web, and into dist/mcp the MCP Apps view, one self-contained HTML file whose holon-ui calls its app through the host. A view that would need a file beside it fails the build. */
|
|
2
|
+
export function holon() {
|
|
3
|
+
return {
|
|
4
|
+
name: "holon",
|
|
5
|
+
config: () => ({
|
|
6
|
+
root: "ui",
|
|
7
|
+
base: "./",
|
|
8
|
+
builder: {},
|
|
9
|
+
build: { outDir: "../dist/web", emptyOutDir: true },
|
|
10
|
+
environments: {
|
|
11
|
+
mcp: {
|
|
12
|
+
consumer: "client",
|
|
13
|
+
build: {
|
|
14
|
+
outDir: "../dist/mcp",
|
|
15
|
+
copyPublicDir: false,
|
|
16
|
+
assetsInlineLimit: () => true,
|
|
17
|
+
rolldownOptions: { output: { codeSplitting: false } },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
applyToEnvironment: ({ name }) => name === "mcp",
|
|
23
|
+
resolveId: { order: "pre", handler: id => (id === "holon-ui/runtime" ? `${import.meta.dirname}/runtime.host.js` : null) },
|
|
24
|
+
generateBundle: {
|
|
25
|
+
order: "post",
|
|
26
|
+
handler(_, bundle) {
|
|
27
|
+
const { "index.html": page, ...files } = bundle;
|
|
28
|
+
if (page?.type !== "asset" || typeof page.source !== "string")
|
|
29
|
+
return this.error("holon-ui/vite builds the view from ui/index.html");
|
|
30
|
+
for (const [name, file] of Object.entries(files)) {
|
|
31
|
+
const url = page.source.indexOf(`"./${name}"`);
|
|
32
|
+
const inlined = file.type === "chunk"
|
|
33
|
+
? `<script type="module">${file.code.replaceAll("<!--", "\\x3C!--")}`
|
|
34
|
+
: typeof file.source === "string" ? `<style>${file.source.replaceAll("</", "<\\/")}</style>` : undefined;
|
|
35
|
+
if (url < 0 || inlined === undefined)
|
|
36
|
+
this.error(`holon-ui/vite cannot inline ${name} into the view, which a host loads as one HTML file; import a worker with ?worker&inline`);
|
|
37
|
+
const startTag = page.source.slice(page.source.lastIndexOf("<", url), page.source.indexOf(">", url) + 1);
|
|
38
|
+
page.source = page.source.replace(startTag, () => inlined);
|
|
39
|
+
delete bundle[name];
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
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.24",
|
|
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",
|
|
@@ -14,30 +14,27 @@
|
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
"./runtime": {
|
|
17
|
-
"types": "./runtime.d.ts",
|
|
18
|
-
"mcp-app": "./runtime.host.
|
|
19
|
-
"default": "./runtime.web.
|
|
17
|
+
"types": "./dist/runtime.web.d.ts",
|
|
18
|
+
"mcp-app": "./dist/runtime.host.js",
|
|
19
|
+
"default": "./dist/runtime.web.js"
|
|
20
20
|
},
|
|
21
21
|
"./vite": {
|
|
22
|
-
"types": "./vite.d.ts",
|
|
23
|
-
"default": "./vite.
|
|
22
|
+
"types": "./dist/vite.d.ts",
|
|
23
|
+
"default": "./dist/vite.js"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"runtime.host.mjs",
|
|
29
|
-
"runtime.web.mjs",
|
|
30
|
-
"vite.d.ts",
|
|
31
|
-
"vite.mjs",
|
|
27
|
+
"dist",
|
|
32
28
|
"README.md"
|
|
33
29
|
],
|
|
34
30
|
"scripts": {
|
|
35
|
-
"
|
|
31
|
+
"prepack": "tsc",
|
|
32
|
+
"test": "tsc && node --test --test-timeout=30000 tests/*.test.mjs && node --conditions=mcp-app --test --test-timeout=30000 tests/mcp-app/*.test.mjs",
|
|
36
33
|
"fixtures": "node scripts/fixtures.mjs"
|
|
37
34
|
},
|
|
38
35
|
"dependencies": {
|
|
39
36
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
40
|
-
"holon-sh": "^0.0.1-dev.
|
|
37
|
+
"holon-sh": "^0.0.1-dev.25"
|
|
41
38
|
},
|
|
42
39
|
"peerDependencies": {
|
|
43
40
|
"@modelcontextprotocol/ext-apps": "^2.0.0"
|
package/runtime.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { App, AppOptions } from "@modelcontextprotocol/ext-apps";
|
|
2
|
-
import type { StandardSchemaV1, StandardSchemaWithJSON, ToolAnnotations } from "@modelcontextprotocol/client";
|
|
3
|
-
import type { EndpointBinding, Identity, Contract, RuntimeClient } from "holon-sh/runtime";
|
|
4
|
-
export type { CreateOptions, EndpointBinding, Identity, Contract, RuntimeClient } from "holon-sh/runtime";
|
|
5
|
-
export type { AuthProvider, CallOptions, CallMetadata, ToolResult, ToolClient } from "holon-sh/runtime";
|
|
6
|
-
export { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
7
|
-
|
|
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
|
-
/** Shown to the agent. Required and non-empty. */
|
|
11
|
-
description: string;
|
|
12
|
-
/** Validates the agent's arguments, such as a Zod 4 object. Without one the tool takes no arguments. */
|
|
13
|
-
inputSchema?: S & StandardSchemaWithJSON;
|
|
14
|
-
/** Describes and validates the object execute returns, such as a Zod 4 object. */
|
|
15
|
-
outputSchema?: O & StandardSchemaWithJSON;
|
|
16
|
-
annotations?: ToolAnnotations;
|
|
17
|
-
/** Receives validated input. Returns a JSON value, or a promise of one; throwing reports failure. signal aborts when the agent cancels. */
|
|
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;
|
|
19
|
-
}
|
|
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> = {}> {
|
|
22
|
-
/** Page tools by name, offered to the host's agent in an MCP Apps host and to the browser's agent through WebMCP. */
|
|
23
|
-
tools?: { [K in keyof S]: PageTool<S[K], O[K & keyof O]> } & { [K in keyof O]: { outputSchema?: O[K] & StandardSchemaWithJSON } };
|
|
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. */
|
|
25
|
-
batch?: "call_tools" extends keyof S ? false : boolean;
|
|
26
|
-
/** The ext-apps App's options in an MCP Apps host, and the transport to connect it with; ignored on a web page. */
|
|
27
|
-
view?: AppOptions & { transport?: Parameters<App["connect"]>[0] };
|
|
28
|
-
/** 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. */
|
|
29
|
-
web?: EndpointBinding;
|
|
30
|
-
}
|
|
31
|
-
type Tools<C> = C extends { tools: infer T } ? T : never;
|
|
32
|
-
/** The tool call that opened a view: typed by its tool, or untyped when the host does not say which tool it was. */
|
|
33
|
-
export type Opened<C> =
|
|
34
|
-
| { [K in keyof Tools<C> & string]: Tools<C>[K] extends (input: infer I, ...rest: never[]) => Promise<infer O> ? { tool: K; input: I; output: O } : never }[keyof Tools<C> & string]
|
|
35
|
-
| { tool: undefined; input: Record<string, unknown>; output: unknown };
|
|
36
|
-
type Resources<C> = C extends { readonly resources: infer R } ? R : never;
|
|
37
|
-
/** What a view can do with its app: call its tools and read its resources. */
|
|
38
|
-
type Relayed<C> = Pick<C, Extract<keyof C, "tools" | "callTool" | "close">> & {
|
|
39
|
-
readonly resources: { readonly [U in keyof Resources<C>]: Pick<Resources<C>[U], Extract<keyof Resources<C>[U], "read">> };
|
|
40
|
-
};
|
|
41
|
-
/** The page's own app C, as a view in an MCP Apps host or as a web page, told apart by view. Only a web page can list the app's tools, watch a resource or subscribe to events. close() also unregisters the page's tools and closes the view. */
|
|
42
|
-
export type Page<C> =
|
|
43
|
-
| (Relayed<C> & {
|
|
44
|
-
/** The connected ext-apps App, for host-only features. */
|
|
45
|
-
readonly view: App;
|
|
46
|
-
/** The tool call that opened the view, with the output its tool returns. */
|
|
47
|
-
readonly opened: Promise<Opened<C>>;
|
|
48
|
-
})
|
|
49
|
-
| (C & {
|
|
50
|
-
/** Undefined on a web page. */
|
|
51
|
-
readonly view: undefined;
|
|
52
|
-
readonly opened: undefined;
|
|
53
|
-
});
|
|
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. */
|
|
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>>;
|
|
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. */
|
|
57
|
-
export declare function connect<S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(
|
|
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 },
|
|
59
|
-
options?: ConnectOptions<S, O>,
|
|
60
|
-
): Promise<Page<RuntimeClient>>;
|
package/runtime.host.mjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// holon-ui/runtime for an MCP Apps view in a host's iframe: package.json resolves to it under the mcp-app condition,
|
|
2
|
-
// which the view's build sets. The host is the app's MCP client, so its agent already has the app's tools: the view
|
|
3
|
-
// offers it only the page's own tools, and calls its app through the host.
|
|
4
|
-
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#standard-mcp-messages
|
|
5
|
-
import { App } from "@modelcontextprotocol/ext-apps";
|
|
6
|
-
import { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
7
|
-
|
|
8
|
-
export { bindApps, ToolCallError };
|
|
9
|
-
|
|
10
|
-
export async function connect({ identity, contracts, own }, { tools = {}, view: { transport, ...options } = {} } = {}) {
|
|
11
|
-
const bind = session => bindApps(identity, contracts, { [own]: { session } })[own];
|
|
12
|
-
const app = new App({ name: identity.name, version: identity.version }, {}, options);
|
|
13
|
-
// Registered before connecting, so the view declares the tools capability in ui/initialize.
|
|
14
|
-
for (const [name, { description, inputSchema, outputSchema, annotations, execute }] of Object.entries(tools)) {
|
|
15
|
-
const output = outputSchema?.["~standard"];
|
|
16
|
-
const run = async (input, { mcpReq: { signal } }) => {
|
|
17
|
-
try {
|
|
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);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
// A tool's own failure is a result the agent can read, not a protocol error.
|
|
24
|
-
// https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling
|
|
25
|
-
return { isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }] };
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
// ext-apps validates input against inputSchema first, and calls a tool without one with the request context alone.
|
|
29
|
-
app.registerTool(name, { description, inputSchema, outputSchema: output && { "~standard": { ...output, validate: value => ({ value }) } }, annotations }, inputSchema ? run : extra => run({}, extra));
|
|
30
|
-
}
|
|
31
|
-
// The host sends the call that opened the view once, right after the handshake, so listen before connecting.
|
|
32
|
-
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#data-passing
|
|
33
|
-
const delivered = new Promise((resolve, reject) => {
|
|
34
|
-
let input = {};
|
|
35
|
-
app.addEventListener("toolinput", params => { input = params.arguments ?? {}; });
|
|
36
|
-
app.addEventListener("toolresult", result => resolve({ input, result }));
|
|
37
|
-
app.addEventListener("toolcancelled", ({ reason }) => reject(new Error(`The tool call that opened the view was cancelled${reason ? `: ${reason}` : "."}`)));
|
|
38
|
-
});
|
|
39
|
-
await app.connect(transport);
|
|
40
|
-
// Replaying the delivered result through the app's own client gives exactly what calling the tool would have: the
|
|
41
|
-
// same output validation and ToolCallError. When the host does not say which tool it was, the call comes as delivered.
|
|
42
|
-
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#host-context-in-mcpuiinitializeresult
|
|
43
|
-
const opened = delivered.then(async ({ input, result }) => {
|
|
44
|
-
const tool = app.getHostContext()?.toolInfo?.tool.name;
|
|
45
|
-
const replay = tool && bind({ callTool: async () => result }).tools[tool];
|
|
46
|
-
return replay ? { tool, input, output: await replay(input) } : { tool: undefined, input, output: result };
|
|
47
|
-
});
|
|
48
|
-
// A page that never reads opened must not see an unhandled rejection.
|
|
49
|
-
opened.catch(() => {});
|
|
50
|
-
const client = bind({
|
|
51
|
-
callTool: (request, { signal, timeout }) => app.callServerTool(request, { signal, timeout }),
|
|
52
|
-
readResource: (request, { signal, timeout }) => app.readServerResource(request, { signal, timeout }),
|
|
53
|
-
});
|
|
54
|
-
// Closing the view removes its tools from the host.
|
|
55
|
-
return Object.freeze({ tools: client.tools, callTool: client.callTool, resources: client.resources, view: app, opened, close: () => app.close() });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function toolResult(value) {
|
|
59
|
-
if (value === undefined) return { content: [] };
|
|
60
|
-
const structured = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
61
|
-
return { content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value) }], ...(structured && { structuredContent: value }) };
|
|
62
|
-
}
|
package/runtime.web.mjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
// holon-ui/runtime for a web page, a document of its own: package.json resolves to it unless the build sets mcp-app.
|
|
2
|
-
// The page calls its app over HTTP, and the browser's agent, if any, learns every tool through WebMCP, because nothing
|
|
3
|
-
// else tells it about them. https://webmachinelearning.github.io/webmcp/#dom-document-modelcontext
|
|
4
|
-
import { getDisplayName } from "@modelcontextprotocol/client";
|
|
5
|
-
import { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
6
|
-
|
|
7
|
-
export { bindApps, ToolCallError };
|
|
8
|
-
|
|
9
|
-
export async function connect({ identity, contracts, own, endpoint }, { tools = {}, batch = false, web = { endpoint } } = {}) {
|
|
10
|
-
const client = bindApps(identity, contracts, { [own]: { ...web, endpoint: new URL(web.endpoint, location.origin) } })[own];
|
|
11
|
-
const lifetime = new AbortController();
|
|
12
|
-
const context = globalThis.document?.modelContext;
|
|
13
|
-
// Offering tools is secondary to the page working: the page does not wait for it, and a failure is only reported.
|
|
14
|
-
// Aborting the lifetime unregisters every tool. https://webmachinelearning.github.io/webmcp/#dom-modelcontext-registertool
|
|
15
|
-
if (context) {
|
|
16
|
-
const { signal } = lifetime;
|
|
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
|
-
const offers = Object.entries(tools).map(([name, tool]) => offer(pageTool(name, tool)));
|
|
21
|
-
const contracted = name => !contracts[own] || contracts[own].tools.some(tool => tool.name === name);
|
|
22
|
-
const listed = client.listTools({ signal }).then(
|
|
23
|
-
({ tools: listed }) => {
|
|
24
|
-
for (const tool of listed) {
|
|
25
|
-
// MCP Apps: a tool whose visibility omits "model" must not reach the agent; absent means ["model", "app"].
|
|
26
|
-
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#resource-discovery
|
|
27
|
-
// A typed client calls only its contract's tools, and an agent cannot write a file argument.
|
|
28
|
-
if (!(tool._meta?.ui?.visibility ?? ["model"]).includes("model") || !contracted(tool.name)) continue;
|
|
29
|
-
const inputSchema = withoutFiles(tool.inputSchema);
|
|
30
|
-
if (inputSchema !== FILE) offers.push(offer(serverTool(own, client, tool, inputSchema)));
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
error => signal.aborted || console.warn(`Could not list the tools of ${own} for WebMCP:`, error),
|
|
34
|
-
);
|
|
35
|
-
if (batch) listed.then(() => Promise.all(offers)).then(() => offered.size && register(batchTool(offered)));
|
|
36
|
-
}
|
|
37
|
-
return Object.freeze({ ...client, view: undefined, opened: undefined, close: async () => { lifetime.abort(); await client.close(); } });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function pageTool(name, { description, inputSchema, outputSchema, annotations, execute }) {
|
|
41
|
-
const standard = inputSchema?.["~standard"];
|
|
42
|
-
const output = outputSchema?.["~standard"];
|
|
43
|
-
return {
|
|
44
|
-
name, title: annotations?.title, description, annotations: hints(annotations),
|
|
45
|
-
inputSchema: standard?.jsonSchema.input({ target: "draft-2020-12" }),
|
|
46
|
-
outputSchema: output?.jsonSchema.output({ target: "draft-2020-12" }),
|
|
47
|
-
execute: async (input, { signal }) => {
|
|
48
|
-
const parsed = standard ? await standard.validate(input) : { value: {} };
|
|
49
|
-
if (parsed.issues) throw new Error(`Invalid arguments for ${name}: ${JSON.stringify(parsed.issues)}`);
|
|
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;
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function serverTool(own, client, tool, inputSchema) {
|
|
59
|
-
return {
|
|
60
|
-
// MCP lets a tool go without a description; WebMCP requires one.
|
|
61
|
-
name: tool.name, title: tool.title ?? tool.annotations?.title, description: tool.description || getDisplayName(tool),
|
|
62
|
-
inputSchema, outputSchema: tool.outputSchema, annotations: hints(tool.annotations),
|
|
63
|
-
execute: async (input, { signal }) => {
|
|
64
|
-
const result = await client.callTool({ name: tool.name, arguments: input }, { signal });
|
|
65
|
-
// An agent can only supply arguments, so it cannot answer a question the server asks back.
|
|
66
|
-
if (result.resultType === "input_required" || result.isError) throw new ToolCallError(own, tool.name, result);
|
|
67
|
-
return result.structuredContent ?? result.content;
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function batchTool(offered) {
|
|
73
|
-
const call = { type: "object", properties: { tool: { enum: [...offered.keys()] }, input: { type: "object" } }, required: ["tool", "input"] };
|
|
74
|
-
const members = [...offered.values()].map(tool => tool.annotations);
|
|
75
|
-
return {
|
|
76
|
-
name: "call_tools",
|
|
77
|
-
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.",
|
|
78
|
-
inputSchema: { type: "object", properties: { calls: { type: "array", items: call } }, required: ["calls"] },
|
|
79
|
-
annotations: {
|
|
80
|
-
readOnlyHint: members.every(hint => hint.readOnlyHint),
|
|
81
|
-
consequentialHint: members.some(hint => hint.consequentialHint),
|
|
82
|
-
untrustedContentHint: members.some(hint => hint.untrustedContentHint),
|
|
83
|
-
},
|
|
84
|
-
execute: async ({ calls }, client) => {
|
|
85
|
-
const outputs = [];
|
|
86
|
-
try {
|
|
87
|
-
for (const { tool, input } of calls) {
|
|
88
|
-
client.signal.throwIfAborted();
|
|
89
|
-
outputs.push(await offered.get(tool).execute(input, client));
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
return { outputs, error: String(error) };
|
|
93
|
-
}
|
|
94
|
-
return { outputs };
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// MCP's hints default to the cautious reading (not read-only, destructive, open-world); WebMCP's all default to false.
|
|
100
|
-
// So each MCP hint is read with its own default, then translated, and an unannotated tool stays consequential.
|
|
101
|
-
// https://modelcontextprotocol.io/specification/2026-07-28/schema#toolannotations
|
|
102
|
-
// https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations
|
|
103
|
-
function hints(annotations) {
|
|
104
|
-
const readOnlyHint = annotations?.readOnlyHint === true;
|
|
105
|
-
return { readOnlyHint, consequentialHint: !readOnlyHint && annotations?.destructiveHint !== false, untrustedContentHint: annotations?.openWorldHint !== false };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const FILE = Symbol("schema requires a file");
|
|
109
|
-
|
|
110
|
-
// An agent writes arguments as tokens, so it is not shown a file argument (x-mcp-file): an anyOf or oneOf branch that
|
|
111
|
-
// holds one is left out, and a tool that still has one is not exposed.
|
|
112
|
-
// https://github.com/modelcontextprotocol/experimental-ext-file-uploads/blob/main/specification/draft/file-uploads.md#file-arguments
|
|
113
|
-
function withoutFiles(node, key) {
|
|
114
|
-
if (Array.isArray(node)) {
|
|
115
|
-
const items = node.map(item => withoutFiles(item));
|
|
116
|
-
if (!items.includes(FILE)) return items;
|
|
117
|
-
if (key !== "anyOf" && key !== "oneOf") return FILE;
|
|
118
|
-
const kept = items.filter(item => item !== FILE);
|
|
119
|
-
return kept.length ? kept : FILE;
|
|
120
|
-
}
|
|
121
|
-
if (typeof node !== "object" || node === null) return node;
|
|
122
|
-
if (Object.hasOwn(node, "x-mcp-file")) return FILE;
|
|
123
|
-
const entries = Object.entries(node).map(([key, value]) => [key, withoutFiles(value, key)]);
|
|
124
|
-
return entries.some(([, value]) => value === FILE) ? FILE : Object.fromEntries(entries);
|
|
125
|
-
}
|
package/vite.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function holon() {
|
|
2
|
-
return {
|
|
3
|
-
name: "holon",
|
|
4
|
-
config: () => ({
|
|
5
|
-
root: "ui",
|
|
6
|
-
base: "./",
|
|
7
|
-
builder: {},
|
|
8
|
-
build: { outDir: "../dist/web", emptyOutDir: true },
|
|
9
|
-
environments: {
|
|
10
|
-
mcp: {
|
|
11
|
-
consumer: "client",
|
|
12
|
-
build: {
|
|
13
|
-
outDir: "../dist/mcp",
|
|
14
|
-
copyPublicDir: false,
|
|
15
|
-
assetsInlineLimit: () => true,
|
|
16
|
-
rolldownOptions: { output: { codeSplitting: false } },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
}),
|
|
21
|
-
applyToEnvironment: ({ name }) => name === "mcp",
|
|
22
|
-
resolveId: { order: "pre", handler: id => (id === "holon-ui/runtime" ? `${import.meta.dirname}/runtime.host.mjs` : null) },
|
|
23
|
-
generateBundle: {
|
|
24
|
-
order: "post",
|
|
25
|
-
handler(_, bundle) {
|
|
26
|
-
const { "index.html": page, ...files } = bundle;
|
|
27
|
-
for (const [name, file] of Object.entries(files)) {
|
|
28
|
-
const url = page.source.indexOf(`"./${name}"`);
|
|
29
|
-
if (url < 0) this.error(`holon-ui/vite cannot inline ${name} into the view, which a host loads as one HTML file; import a worker with ?worker&inline`);
|
|
30
|
-
const startTag = page.source.slice(page.source.lastIndexOf("<", url), page.source.indexOf(">", url) + 1);
|
|
31
|
-
page.source = page.source.replace(startTag, () => file.type === "chunk"
|
|
32
|
-
? `<script type="module">${file.code.replaceAll("<!--", "\\x3C!--")}`
|
|
33
|
-
: `<style>${file.source.replaceAll("</", "<\\/")}</style>`);
|
|
34
|
-
delete bundle[name];
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|