@mcpview/compose 0.11.0 → 0.12.0

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +60 -0
  3. package/esm/_dnt.polyfills.d.ts +6 -6
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/src/code-mode/board.d.ts +62 -0
  6. package/esm/src/code-mode/board.d.ts.map +1 -0
  7. package/esm/src/code-mode/board.js +86 -0
  8. package/esm/src/code-mode/chain.d.ts +20 -0
  9. package/esm/src/code-mode/chain.d.ts.map +1 -0
  10. package/esm/src/code-mode/chain.js +240 -0
  11. package/esm/src/code-mode/connections.d.ts +33 -0
  12. package/esm/src/code-mode/connections.d.ts.map +1 -0
  13. package/esm/src/code-mode/connections.js +120 -0
  14. package/esm/src/code-mode/mod.d.ts +8 -0
  15. package/esm/src/code-mode/mod.d.ts.map +1 -0
  16. package/esm/src/code-mode/mod.js +6 -0
  17. package/esm/src/code-mode/provider-tools.d.ts +38 -0
  18. package/esm/src/code-mode/provider-tools.d.ts.map +1 -0
  19. package/esm/src/code-mode/provider-tools.js +113 -0
  20. package/esm/src/code-mode/providers.d.ts +20 -0
  21. package/esm/src/code-mode/providers.d.ts.map +1 -0
  22. package/esm/src/code-mode/providers.js +9 -0
  23. package/esm/src/code-mode/sandbox.d.ts +10 -0
  24. package/esm/src/code-mode/sandbox.d.ts.map +1 -0
  25. package/esm/src/code-mode/sandbox.js +147 -0
  26. package/esm/src/code-mode/tool.d.ts +13 -0
  27. package/esm/src/code-mode/tool.d.ts.map +1 -0
  28. package/esm/src/code-mode/tool.js +54 -0
  29. package/esm/src/version.d.ts +1 -1
  30. package/esm/src/version.js +1 -1
  31. package/package.json +13 -2
  32. package/script/_dnt.polyfills.d.ts +6 -6
  33. package/script/_dnt.polyfills.d.ts.map +1 -1
  34. package/script/src/code-mode/board.d.ts +62 -0
  35. package/script/src/code-mode/board.d.ts.map +1 -0
  36. package/script/src/code-mode/board.js +91 -0
  37. package/script/src/code-mode/chain.d.ts +20 -0
  38. package/script/src/code-mode/chain.d.ts.map +1 -0
  39. package/script/src/code-mode/chain.js +243 -0
  40. package/script/src/code-mode/connections.d.ts +33 -0
  41. package/script/src/code-mode/connections.d.ts.map +1 -0
  42. package/script/src/code-mode/connections.js +123 -0
  43. package/script/src/code-mode/mod.d.ts +8 -0
  44. package/script/src/code-mode/mod.d.ts.map +1 -0
  45. package/script/src/code-mode/mod.js +13 -0
  46. package/script/src/code-mode/provider-tools.d.ts +38 -0
  47. package/script/src/code-mode/provider-tools.d.ts.map +1 -0
  48. package/script/src/code-mode/provider-tools.js +116 -0
  49. package/script/src/code-mode/providers.d.ts +20 -0
  50. package/script/src/code-mode/providers.d.ts.map +1 -0
  51. package/script/src/code-mode/providers.js +13 -0
  52. package/script/src/code-mode/sandbox.d.ts +10 -0
  53. package/script/src/code-mode/sandbox.d.ts.map +1 -0
  54. package/script/src/code-mode/sandbox.js +152 -0
  55. package/script/src/code-mode/tool.d.ts +13 -0
  56. package/script/src/code-mode/tool.d.ts.map +1 -0
  57. package/script/src/code-mode/tool.js +57 -0
  58. package/script/src/version.d.ts +1 -1
  59. package/script/src/version.js +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-tools.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/provider-tools.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAI3E,+FAA+F;AAC/F,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAE,CACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,kBAAkB,KACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACjE;AAED,uEAAuE;AACvE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,SAAS,yBAAyB,EAAE,CAAC;IACxD,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChG,8EAA8E;IAC9E,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACjD,iFAAiF;IACjF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAcD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAAC,EACrD,OAAO,EAAE,sBAAsB,GAC9B,IAAI,CA6EN"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSnippetProvider = registerSnippetProvider;
4
+ /** Register the discovery and replay protocol on a snippet-owning MCP server. @module */
5
+ const _2020_js_1 = require("ajv/dist/2020.js");
6
+ const extractor_js_1 = require("../core/collector/extractor.js");
7
+ const providers_js_1 = require("./providers.js");
8
+ function failure(code, text) {
9
+ return {
10
+ isError: true,
11
+ content: [{ type: "text", text }],
12
+ structuredContent: { error: { code } },
13
+ };
14
+ }
15
+ function object(input) {
16
+ return typeof input === "object" && input !== null && !Array.isArray(input);
17
+ }
18
+ /**
19
+ * Register `list_snippets` and `run_snippet`. Expose selected saved programs by name.
20
+ * A successful runner returns its native MCP response with a JSON projection at
21
+ * `structuredContent.value`. Provider-only view metadata is forwarded intact.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * registerSnippetProvider(app, {
26
+ * snippets: [{
27
+ * name: "overdue", description: "List overdue invoices",
28
+ * inputSchema: { type: "object" },
29
+ * run: (input, context) => replayInvoiceSnippet("overdue", input, context),
30
+ * }],
31
+ * requiredScopes: ["invoices:read"],
32
+ * });
33
+ * ```
34
+ */
35
+ function registerSnippetProvider(server, options) {
36
+ if (server.getToolNames().some((name) => name === "list_snippets" || name === "run_snippet")) {
37
+ throw new Error("Snippet discovery or replay tools are already registered.");
38
+ }
39
+ const resourceUri = options.runResourceUri;
40
+ const schemas = new _2020_js_1.Ajv2020({ strict: false, useDefaults: true });
41
+ const definitions = options.snippets.map(({ name, description, inputSchema, run }) => {
42
+ if (!(0, providers_js_1.isSnippetName)(name) || !object(inputSchema) || inputSchema.type !== "object") {
43
+ throw new TypeError("Each snippet needs a valid name and an object input schema.");
44
+ }
45
+ const schema = structuredClone(inputSchema);
46
+ const validate = schemas.compile(schema);
47
+ if ("$async" in validate)
48
+ throw new TypeError("Snippet input schemas must be synchronous.");
49
+ return { descriptor: { name, description, inputSchema: schema }, validate, run };
50
+ });
51
+ const byName = new Map(definitions.map((def) => [def.descriptor.name, def]));
52
+ if (byName.size !== definitions.length)
53
+ throw new Error("Snippet names must be unique.");
54
+ const authorized = async (name, context) => !options.authorize || (await options.authorize(name, context)) === true;
55
+ const scopes = options.requiredScopes ? [...options.requiredScopes] : undefined;
56
+ server.registerTool({
57
+ name: "list_snippets",
58
+ description: "List the saved snippets available to this caller and their input schemas.",
59
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
60
+ requiredScopes: scopes,
61
+ annotations: {
62
+ readOnlyHint: true,
63
+ destructiveHint: false,
64
+ openWorldHint: false,
65
+ idempotentHint: true,
66
+ },
67
+ }, async (_args, context) => {
68
+ const snippets = [];
69
+ for (const { descriptor } of definitions) {
70
+ if (await authorized(descriptor.name, context))
71
+ snippets.push(descriptor);
72
+ }
73
+ return {
74
+ content: snippets.map(({ name }) => name).join(", "),
75
+ structuredContent: { snippets },
76
+ };
77
+ });
78
+ server.registerTool({
79
+ name: "run_snippet",
80
+ description: "Replay a saved snippet using its declared input.",
81
+ inputSchema: {
82
+ type: "object",
83
+ properties: { name: { type: "string" }, input: { type: "object" } },
84
+ required: ["name", "input"],
85
+ additionalProperties: false,
86
+ },
87
+ annotations: {
88
+ readOnlyHint: false,
89
+ destructiveHint: true,
90
+ openWorldHint: true,
91
+ idempotentHint: false,
92
+ ...options.runAnnotations,
93
+ },
94
+ requiredScopes: scopes,
95
+ ...(resourceUri ? { _meta: { ui: { resourceUri } } } : {}),
96
+ }, async (args, context) => {
97
+ const def = typeof args.name === "string" ? byName.get(args.name) : undefined;
98
+ if (!def || !await authorized(def.descriptor.name, context)) {
99
+ return failure("UNAVAILABLE", "The requested snippet is unavailable.");
100
+ }
101
+ if (!object(args.input) || Object.keys(args).length !== 2 || !def.validate(args.input)) {
102
+ return failure("INVALID_INPUT", "Supply the snippet's declared input.");
103
+ }
104
+ const result = await def.run(args.input, context);
105
+ if (result.isError === true)
106
+ return result;
107
+ if (!object(result.structuredContent) || !Object.hasOwn(result.structuredContent, "value")) {
108
+ return failure("UPSTREAM_ERROR", "The saved snippet returned no value.");
109
+ }
110
+ if (!resourceUri || (0, extractor_js_1.extractUiMeta)(result))
111
+ return result;
112
+ const meta = object(result._meta) ? result._meta : {};
113
+ const ui = object(meta.ui) ? meta.ui : {};
114
+ return { ...result, _meta: { ...meta, ui: { ...ui, resourceUri } } };
115
+ });
116
+ }
@@ -0,0 +1,20 @@
1
+ import type { CallToolResult } from "@modelcontextprotocol/client";
2
+ /** Trusted, per-request server context, supplied by the host rather than guest code. */
3
+ export interface SnippetChainContext {
4
+ /** Catalog partition derived from the authenticated principal and integration. */
5
+ readonly scope?: string;
6
+ /** Cancellation of the incoming MCP request. */
7
+ readonly signal?: AbortSignal;
8
+ }
9
+ /** A configured MCP binding. The host resolves the caller's upstream authority on every call. */
10
+ export interface SnippetProvider {
11
+ /** The subset of this provider's snippets reachable by a program. */
12
+ readonly names: readonly string[];
13
+ /** Forward only these protocol operations with host-owned transport credentials. */
14
+ call(tool: "list_snippets" | "run_snippet", args: Record<string, unknown>, signal: AbortSignal, context: SnippetChainContext): Promise<CallToolResult>;
15
+ }
16
+ /** Configured aliases identifying providers in a program. */
17
+ export declare function isSnippetIdentifier(value: unknown): value is string;
18
+ /** MCPView catalog names are exact, nonblank strings of at most 256 UTF-8 bytes. */
19
+ export declare function isSnippetName(value: unknown): value is string;
20
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,iGAAiG;AACjG,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,oFAAoF;IACpF,IAAI,CACF,IAAI,EAAE,eAAe,GAAG,aAAa,EACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEnE;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAG7D"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSnippetIdentifier = isSnippetIdentifier;
4
+ exports.isSnippetName = isSnippetName;
5
+ /** Configured aliases identifying providers in a program. */
6
+ function isSnippetIdentifier(value) {
7
+ return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(value);
8
+ }
9
+ /** MCPView catalog names are exact, nonblank strings of at most 256 UTF-8 bytes. */
10
+ function isSnippetName(value) {
11
+ return typeof value === "string" && value.length > 0 && value.length <= 256 &&
12
+ value === value.trim() && new TextEncoder().encode(value).byteLength <= 256;
13
+ }
@@ -0,0 +1,10 @@
1
+ /** Maximum source length accepted by the code-mode execute tool. */
2
+ export declare const maxCodeLength = 16384;
3
+ /** Serialize data crossing the QuickJS boundary within the supplied limit. */
4
+ export declare function encodeValue(value: unknown, limit?: number): string;
5
+ /**
6
+ * Run a function body in an isolated QuickJS context. Only JSON and explicit snippet
7
+ * operations cross into the host. Execute host requests when the guest yields.
8
+ */
9
+ export declare function runProgram(code: string, params: Record<string, unknown>, invoke: (operation: string, args: unknown[], signal: AbortSignal) => Promise<unknown>, callerSignal?: AbortSignal): Promise<unknown>;
10
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/sandbox.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,eAAO,MAAM,aAAa,QAAS,CAAC;AAIpC,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAiB,GAAG,MAAM,CAM1E;AAkBD;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,EACrF,YAAY,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,OAAO,CAAC,CA4HlB"}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maxCodeLength = void 0;
4
+ exports.encodeValue = encodeValue;
5
+ exports.runProgram = runProgram;
6
+ const quickjs_emscripten_1 = require("quickjs-emscripten");
7
+ /** Maximum source length accepted by the code-mode execute tool. */
8
+ exports.maxCodeLength = 16_384;
9
+ const maxValueLength = 128 * 1024;
10
+ const maxOperations = 16;
11
+ /** Serialize data crossing the QuickJS boundary within the supplied limit. */
12
+ function encodeValue(value, limit = maxValueLength) {
13
+ const text = JSON.stringify(value);
14
+ if (text === undefined || text.length > limit) {
15
+ throw new Error("Expected a JSON value within the size limit.");
16
+ }
17
+ return text;
18
+ }
19
+ /** Wait for host I/O without allowing a provider that ignores cancellation to hold the VM open. */
20
+ function waitForOperation(invoke, signal) {
21
+ signal.throwIfAborted();
22
+ return new Promise((resolve, reject) => {
23
+ const abort = () => reject(signal.reason);
24
+ signal.addEventListener("abort", abort, { once: true });
25
+ Promise.resolve().then(() => {
26
+ signal.throwIfAborted();
27
+ return invoke();
28
+ }).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
29
+ });
30
+ }
31
+ /**
32
+ * Run a function body in an isolated QuickJS context. Only JSON and explicit snippet
33
+ * operations cross into the host. Execute host requests when the guest yields.
34
+ */
35
+ async function runProgram(code, params, invoke, callerSignal) {
36
+ if (typeof code !== "string" || !code.trim() || code.length > exports.maxCodeLength) {
37
+ throw new Error("Supply a JavaScript function body of at most 16 KiB.");
38
+ }
39
+ callerSignal?.throwIfAborted();
40
+ const wasm = await (0, quickjs_emscripten_1.getQuickJS)();
41
+ callerSignal?.throwIfAborted();
42
+ const controller = new AbortController();
43
+ const signal = controller.signal;
44
+ const abort = () => controller.abort(callerSignal?.reason);
45
+ callerSignal?.addEventListener("abort", abort, { once: true });
46
+ const timer = setTimeout(() => controller.abort(new Error("JavaScript exceeded its time limit.")), 30_000);
47
+ try {
48
+ return await quickjs_emscripten_1.Scope.withScopeAsync(async (scope) => {
49
+ const vm = scope.manage(wasm.newContext());
50
+ let cpuDeadline = performance.now() + 2000;
51
+ vm.runtime.setMemoryLimit(12 * 1024 * 1024);
52
+ vm.runtime.setMaxStackSize(192 * 1024);
53
+ vm.runtime.setInterruptHandler(() => signal.aborted || performance.now() >= cpuDeadline);
54
+ const stringify = scope.manage(vm.unwrapResult(vm.evalCode("JSON.stringify.bind(JSON)")));
55
+ const parse = scope.manage(vm.unwrapResult(vm.evalCode("JSON.parse.bind(JSON)")));
56
+ const pending = [];
57
+ let calls = 0;
58
+ function read(handle) {
59
+ const encoded = vm.unwrapResult(vm.callFunction(stringify, vm.undefined, handle));
60
+ try {
61
+ if (vm.typeof(encoded) !== "string")
62
+ throw new Error("Expected a JSON value.");
63
+ const text = vm.getString(encoded);
64
+ if (text.length > maxValueLength)
65
+ throw new Error("JSON value exceeds the size limit.");
66
+ return JSON.parse(text);
67
+ }
68
+ finally {
69
+ encoded.dispose();
70
+ }
71
+ }
72
+ function decode(value) {
73
+ const encoded = vm.newString(encodeValue(value));
74
+ try {
75
+ return scope.manage(vm.unwrapResult(vm.callFunction(parse, vm.undefined, encoded)));
76
+ }
77
+ finally {
78
+ encoded.dispose();
79
+ }
80
+ }
81
+ const dispatch = scope.manage(vm.newFunction("dispatch", (name, args) => {
82
+ if (++calls > maxOperations || vm.typeof(name) !== "string") {
83
+ throw new Error("Snippet operation limit exceeded.");
84
+ }
85
+ const operation = vm.getString(name);
86
+ const arguments_ = read(args);
87
+ if (!Array.isArray(arguments_))
88
+ throw new Error("Expected snippet arguments.");
89
+ const deferred = scope.manage(vm.newPromise());
90
+ pending.push(async () => {
91
+ try {
92
+ const result = await waitForOperation(() => invoke(operation, arguments_, signal), signal);
93
+ signal.throwIfAborted();
94
+ deferred.resolve(decode(result));
95
+ }
96
+ catch (error) {
97
+ const message = scope.manage(vm.newString(error instanceof Error ? error.message : "Snippet failed."));
98
+ deferred.reject(message);
99
+ }
100
+ });
101
+ return deferred.handle.dup();
102
+ }));
103
+ vm.setProp(vm.global, "dispatch", dispatch);
104
+ vm.setProp(vm.global, "params", decode(params));
105
+ const promise = scope.manage(vm.unwrapResult(vm.evalCode(`(() => {
106
+ const call = globalThis.dispatch, params = globalThis.params;
107
+ delete globalThis.dispatch;
108
+ delete globalThis.params;
109
+ const api = Object.freeze({
110
+ params,
111
+ listSnippets: (...args) => call("listSnippets", args),
112
+ runSnippet: (...args) => call("runSnippet", args),
113
+ panel: (...args) => call("panel", args),
114
+ });
115
+ return (async function(api) { "use strict";\n${code}\n})(api);
116
+ })()`, "mcpview-code-mode.js", { type: "global" })));
117
+ for (;;) {
118
+ signal.throwIfAborted();
119
+ if (performance.now() >= cpuDeadline) {
120
+ throw new Error("JavaScript exceeded its time limit.");
121
+ }
122
+ const state = vm.getPromiseState(promise);
123
+ if (state.type === "fulfilled") {
124
+ const value = scope.manage(state.value);
125
+ if (pending.length) {
126
+ throw new Error("Await every snippet operation, including api.panel().");
127
+ }
128
+ return vm.typeof(value) === "undefined" ? null : read(value);
129
+ }
130
+ if (state.type === "rejected") {
131
+ const reason = scope.manage(state.error);
132
+ throw new Error(vm.typeof(reason) === "string" ? vm.getString(reason) : "JavaScript failed.");
133
+ }
134
+ if (vm.runtime.hasPendingJob()) {
135
+ vm.unwrapResult(vm.runtime.executePendingJobs(1));
136
+ }
137
+ else if (pending.length) {
138
+ const before = performance.now();
139
+ await pending.shift()();
140
+ cpuDeadline += performance.now() - before;
141
+ }
142
+ else {
143
+ throw new Error("JavaScript is waiting on an unresolved promise.");
144
+ }
145
+ }
146
+ });
147
+ }
148
+ finally {
149
+ clearTimeout(timer);
150
+ callerSignal?.removeEventListener("abort", abort);
151
+ }
152
+ }
@@ -0,0 +1,13 @@
1
+ import type { MCPTool } from "@mcpview/server";
2
+ import type { SnippetProvider } from "./providers.js";
3
+ /** Configure the single model-facing tool and its MCP Apps board resource. */
4
+ export interface SnippetExecuteToolOptions {
5
+ readonly resourceUri: string;
6
+ readonly providers: ReadonlyMap<string, Pick<SnippetProvider, "names">>;
7
+ /** Enable this when the chain uses a catalog and the host supplies a trusted scope. */
8
+ readonly savedChains?: boolean;
9
+ readonly annotations?: MCPTool["annotations"];
10
+ }
11
+ /** Build the tool declaration for registration with an MCPView server. */
12
+ export declare function createSnippetExecuteTool(options: SnippetExecuteToolOptions): MCPTool;
13
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,8EAA8E;AAC9E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,uFAAuF;IACvF,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAqDpF"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSnippetExecuteTool = createSnippetExecuteTool;
4
+ const sandbox_js_1 = require("./sandbox.js");
5
+ /** Build the tool declaration for registration with an MCPView server. */
6
+ function createSnippetExecuteTool(options) {
7
+ if (!options.resourceUri.startsWith("ui://") || !URL.canParse(options.resourceUri) ||
8
+ !new URL(options.resourceUri).host) {
9
+ throw new Error("Supply a ui:// resource URI for the board.");
10
+ }
11
+ const available = [...options.providers.keys()];
12
+ return {
13
+ name: "execute",
14
+ description: [
15
+ "Run a JavaScript function body with api.params (the supplied JSON object).",
16
+ "Use await api.listSnippets(provider) to discover approved snippets.",
17
+ "Configured provider aliases: " + JSON.stringify(available) + ".",
18
+ "await api.runSnippet(provider, name, input) returns a receipt {id, value}.",
19
+ "Pass values between calls. Use await api.panel(receipt.id, optionalTitle) for each result to display, in display order. Return a JSON summary.",
20
+ ...(options.savedChains
21
+ ? [
22
+ "Use saveAs to save a successful chain, listSaved to list your saved chains, or replay with the saved name and new params.",
23
+ ]
24
+ : []),
25
+ ].join(" "),
26
+ inputSchema: {
27
+ type: "object",
28
+ additionalProperties: false,
29
+ properties: {
30
+ code: { type: "string", minLength: 1, maxLength: sandbox_js_1.maxCodeLength },
31
+ params: { type: "object" },
32
+ ...(options.savedChains
33
+ ? {
34
+ saveAs: { type: "string", minLength: 1, maxLength: 256 },
35
+ replay: { type: "string", minLength: 1, maxLength: 256 },
36
+ listSaved: { type: "boolean", const: true },
37
+ }
38
+ : {}),
39
+ },
40
+ ...(options.savedChains
41
+ ? { oneOf: [{ required: ["code"] }, { required: ["replay"] }, { required: ["listSaved"] }] }
42
+ : { required: ["code"] }),
43
+ },
44
+ annotations: {
45
+ readOnlyHint: false,
46
+ destructiveHint: true,
47
+ idempotentHint: false,
48
+ openWorldHint: true,
49
+ ...options.annotations,
50
+ ...(options.savedChains ? { readOnlyHint: false } : {}),
51
+ },
52
+ _meta: {
53
+ ui: { resourceUri: options.resourceUri, visibility: ["model"] },
54
+ ...{ "openai/outputTemplate": options.resourceUri },
55
+ },
56
+ };
57
+ }
@@ -17,7 +17,7 @@
17
17
  * @module lib/version
18
18
  */
19
19
  /** @mcpview/compose package version. */
20
- export declare const COMPOSE_VERSION: "0.11.0";
20
+ export declare const COMPOSE_VERSION: "0.12.0";
21
21
  /**
22
22
  * MCP Apps protocol version targeted by compose.
23
23
  *
@@ -20,7 +20,7 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.MCP_APPS_PROTOCOL_VERSION = exports.COMPOSE_VERSION = void 0;
22
22
  /** @mcpview/compose package version. */
23
- exports.COMPOSE_VERSION = "0.11.0";
23
+ exports.COMPOSE_VERSION = "0.12.0";
24
24
  /**
25
25
  * MCP Apps protocol version targeted by compose.
26
26
  *