@milaboratories/pl-mcp-server 52.0.0 → 53.0.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.
- package/dist/index.d.ts +2 -1
- package/dist/instructions.cjs +28 -0
- package/dist/instructions.cjs.map +1 -0
- package/dist/instructions.js +28 -0
- package/dist/instructions.js.map +1 -0
- package/dist/package.cjs +10 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.js +5 -0
- package/dist/package.js.map +1 -0
- package/dist/server.cjs +45 -41
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +15 -9
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +44 -40
- package/dist/server.js.map +1 -1
- package/dist/tools/await.cjs +8 -5
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +9 -6
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +7 -4
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +8 -5
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +23 -0
- package/dist/tools/block-api.cjs.map +1 -0
- package/dist/tools/block-api.js +22 -0
- package/dist/tools/block-api.js.map +1 -0
- package/dist/tools/block-params.cjs +21 -0
- package/dist/tools/block-params.cjs.map +1 -0
- package/dist/tools/block-params.js +21 -0
- package/dist/tools/block-params.js.map +1 -0
- package/dist/tools/block-state.cjs +18 -11
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +19 -12
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/blocks.cjs +130 -50
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +131 -52
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/connection.cjs +23 -6
- package/dist/tools/connection.cjs.map +1 -1
- package/dist/tools/connection.js +24 -7
- package/dist/tools/connection.js.map +1 -1
- package/dist/tools/data-query.cjs +14 -7
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +15 -8
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/ids.cjs +14 -0
- package/dist/tools/ids.cjs.map +1 -0
- package/dist/tools/ids.js +13 -0
- package/dist/tools/ids.js.map +1 -0
- package/dist/tools/logs.cjs +11 -6
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +12 -7
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/ping.cjs +5 -1
- package/dist/tools/ping.cjs.map +1 -1
- package/dist/tools/ping.js +6 -2
- package/dist/tools/ping.js.map +1 -1
- package/dist/tools/projects.cjs +20 -7
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +21 -8
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/screenshot.cjs +3 -1
- package/dist/tools/screenshot.cjs.map +1 -1
- package/dist/tools/screenshot.js +4 -2
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/types.cjs +51 -0
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +50 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/ui-interaction.cjs +27 -13
- package/dist/tools/ui-interaction.cjs.map +1 -1
- package/dist/tools/ui-interaction.js +28 -14
- package/dist/tools/ui-interaction.js.map +1 -1
- package/package.json +11 -9
- package/src/index.ts +1 -0
- package/src/instructions.ts +24 -0
- package/src/server.test.ts +633 -0
- package/src/server.ts +65 -58
- package/src/tools/await.ts +9 -6
- package/src/tools/block-action-context.ts +9 -6
- package/src/tools/block-api.ts +24 -0
- package/src/tools/block-params.ts +30 -0
- package/src/tools/block-state.ts +21 -14
- package/src/tools/blocks.test.ts +148 -0
- package/src/tools/blocks.ts +216 -65
- package/src/tools/connection.ts +38 -17
- package/src/tools/data-query.ts +17 -10
- package/src/tools/ids.ts +11 -0
- package/src/tools/logs.ts +13 -8
- package/src/tools/ping.ts +14 -5
- package/src/tools/projects.ts +26 -11
- package/src/tools/screenshot.ts +7 -5
- package/src/tools/types.test.ts +19 -0
- package/src/tools/types.ts +71 -3
- package/src/tools/ui-interaction.ts +29 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-state.js","names":[],"sources":["../../src/tools/block-state.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/
|
|
1
|
+
{"version":3,"file":"block-state.js","names":[],"sources":["../../src/tools/block-state.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { ModelAPIVersionMismatchError } from \"@milaboratories/pl-errors\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerBlockStateTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"get_project_overview\",\n {\n title: \"Get Project Overview\",\n annotations: hints.read,\n description:\n \"Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n }),\n },\n async ({ projectId }) => {\n const project = await ctx.getOpenedProject(projectId);\n const overview = await project.overview.getValue();\n if (!overview) return errorResult(\"Project overview not available yet.\");\n return textResult({\n label: overview.meta.label,\n blocks: overview.blocks.map((b) => ({\n id: b.id,\n title: b.title ?? b.label,\n calculationStatus: b.calculationStatus,\n canRun: b.canRun,\n stale: b.stale,\n inputsValid: b.inputsValid,\n outputErrors: b.outputErrors,\n upstreams: b.upstreams,\n downstreams: b.downstreams,\n })),\n });\n },\n );\n\n server.registerTool(\n \"get_block_state\",\n {\n title: \"Get Block State\",\n annotations: hints.read,\n description:\n \"Get block state. Returns block args (data) and a concise output summary with token estimates by default. \" +\n \"Use `transform` to extract specific data server-side without loading full outputs into context.\\n\\n\" +\n \"Default: returns `{ data, outputs: [{ key, ok, hasValue, tokensEstimate }] }`\\n\\n\" +\n \"Transform examples:\\n\" +\n \"- `outputs.logs?.value` — get one specific output value\\n\" +\n \"- `data` — get only block args\\n\" +\n \"- `({ preset: outputs.preset?.value, qc: outputs.qc?.value })` — get specific outputs\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against full block state. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs object). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, transform, transformTimeout }) => {\n const project = await ctx.getOpenedProject(projectId);\n const state = await project.getBlockState(blockId).getValue();\n const data = deriveDataFromStorage(state.blockStorage);\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n { data, outputs: state.outputs },\n transformTimeout,\n );\n return textResult(result);\n } catch (e: unknown) {\n return errorResult(\n `Transform failed: ${e instanceof Error ? e.message : String(e)}`,\n \"Check your JS expression syntax. Available variables: data, outputs.\",\n );\n }\n }\n return textResult({\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n },\n );\n\n server.registerTool(\n \"set_block_data\",\n {\n title: \"Set Block Data\",\n annotations: hints.destructive,\n description: \"Set the user-facing data of a block (triggers args derivation and staging)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n data: z.record(z.string(), z.unknown()).describe(\"Block data object\"),\n }),\n },\n async ({ projectId, blockId, data }) => {\n const project = await ctx.getOpenedProject(projectId);\n\n // V1 state shape: { args, uiState } — callers may pass either the full state\n // or just the args object. Unwrap once for both V2 and V1 paths.\n const value = data.args ?? data;\n\n // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).\n try {\n await project.mutateBlockStorage(\n blockId,\n { operation: \"update-block-data\", value },\n ctx.getAuthorMarker(),\n );\n } catch (e: unknown) {\n if (e instanceof ModelAPIVersionMismatchError) {\n await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());\n } else {\n throw e;\n }\n }\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,wBAAwB,QAAmB,KAAwB;CACjF,OAAO,aACL,wBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,WAAW,eAAe,SAAS,6BAA6B,EAClE,CAAC;CACH,GACA,OAAO,EAAE,gBAAgB;EAEvB,MAAM,WAAW,OAAM,MADD,IAAI,iBAAiB,SAAS,EAAA,CACrB,SAAS,SAAS;EACjD,IAAI,CAAC,UAAU,OAAO,YAAY,qCAAqC;EACvE,OAAO,WAAW;GAChB,OAAO,SAAS,KAAK;GACrB,QAAQ,SAAS,OAAO,KAAK,OAAO;IAClC,IAAI,EAAE;IACN,OAAO,EAAE,SAAS,EAAE;IACpB,mBAAmB,EAAE;IACrB,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,aAAa,EAAE;IACf,cAAc,EAAE;IAChB,WAAW,EAAE;IACb,aAAa,EAAE;GACjB,EAAE;EACJ,CAAC;CACH,CACF;CAEA,OAAO,aACL,mBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAOF,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,UAAU;GACzC,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,2KAGF;GACF,kBAAkB,EACf,OAAO,CAAC,CACR,SAAS,CAAC,CACV,QAAQ,GAAI,CAAC,CACb,SAAS,wDAAwD;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,WAAW,uBAAuB;EAE7D,MAAM,QAAQ,OAAM,MADE,IAAI,iBAAiB,SAAS,EAAA,CACxB,cAAc,OAAO,CAAC,CAAC,SAAS;EAC5D,MAAM,OAAO,sBAAsB,MAAM,YAAY;EACrD,IAAI,WACF,IAAI;GACF,MAAM,SAAS,MAAM,SACnB,WACA;IAAE;IAAM,SAAS,MAAM;GAAQ,GAC/B,gBACF;GACA,OAAO,WAAW,MAAM;EAC1B,SAAS,GAAY;GACnB,OAAO,YACL,qBAAqB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,KAC9D,sEACF;EACF;EAEF,OAAO,WAAW;GAChB;GACA,SAAS,iBAAiB,MAAM,OAA8C;EAChF,CAAC;CACH,CACF;CAEA,OAAO,aACL,kBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aAAa;EACb,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,UAAU;GACzC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,mBAAmB;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,WAAW;EACtC,MAAM,UAAU,MAAM,IAAI,iBAAiB,SAAS;EAIpD,MAAM,QAAQ,KAAK,QAAQ;EAG3B,IAAI;GACF,MAAM,QAAQ,mBACZ,SACA;IAAE,WAAW;IAAqB;GAAM,GACxC,IAAI,gBAAgB,CACtB;EACF,SAAS,GAAY;GACnB,IAAI,aAAa,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;QAEhE,MAAM;EAEV;EACA,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
|
package/dist/tools/blocks.cjs
CHANGED
|
@@ -1,34 +1,96 @@
|
|
|
1
1
|
const require_types = require("./types.cjs");
|
|
2
|
+
const require_ids = require("./ids.cjs");
|
|
3
|
+
const require_block_api = require("./block-api.cjs");
|
|
2
4
|
let zod = require("zod");
|
|
5
|
+
let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
|
|
6
|
+
let _milaboratories_pl_errors = require("@milaboratories/pl-errors");
|
|
3
7
|
// src/tools/blocks.ts
|
|
8
|
+
/** Where a kind is resolved when the caller names no registry. */
|
|
9
|
+
function centralBlockRegistryUrl() {
|
|
10
|
+
if (_milaboratories_pl_middle_layer.CentralBlockRegistry.type !== "remote-v2") throw new Error("The central block registry is expected to be a v2 remote registry.");
|
|
11
|
+
return _milaboratories_pl_middle_layer.CentralBlockRegistry.url;
|
|
12
|
+
}
|
|
13
|
+
function errorMessage(e) {
|
|
14
|
+
return e instanceof Error ? e.message : String(e);
|
|
15
|
+
}
|
|
16
|
+
const addBlockInput = zod.z.object({
|
|
17
|
+
projectId: require_ids.projectIdInput.describe("Project ID (must be opened)"),
|
|
18
|
+
label: zod.z.string().describe("Block label"),
|
|
19
|
+
spec: zod.z.union([
|
|
20
|
+
zod.z.object({
|
|
21
|
+
type: zod.z.literal("kind"),
|
|
22
|
+
kind: zod.z.string().describe("Block kind reference \"<package name>@<version or range>\", e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\""),
|
|
23
|
+
registryUrl: zod.z.string().optional().describe("Registry to resolve the kind in (default: the central block registry)"),
|
|
24
|
+
allowUnstable: zod.z.boolean().optional().describe("Also consider blocks not published to the stable channel")
|
|
25
|
+
}),
|
|
26
|
+
zod.z.object({
|
|
27
|
+
type: zod.z.literal("from-registry-v2"),
|
|
28
|
+
registryUrl: zod.z.string().describe("Registry URL"),
|
|
29
|
+
id: zod.z.object({
|
|
30
|
+
organization: zod.z.string(),
|
|
31
|
+
name: zod.z.string(),
|
|
32
|
+
version: zod.z.string()
|
|
33
|
+
})
|
|
34
|
+
}),
|
|
35
|
+
zod.z.object({
|
|
36
|
+
type: zod.z.literal("dev-v2"),
|
|
37
|
+
folder: zod.z.string().describe("Path to block folder")
|
|
38
|
+
})
|
|
39
|
+
]).describe("Which block to add"),
|
|
40
|
+
params: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Initialization params of the block's kind. Omit for the default state."),
|
|
41
|
+
blockIds: zod.z.record(zod.z.string(), require_ids.blockIdInput).optional().describe("Ids used inside `params` in place of block ids, each mapped to a block id of this project. Needed only when `params` do not already hold ids of this project."),
|
|
42
|
+
before: require_ids.blockIdInput.optional().describe("ID of the block to insert the new block before (default: add at the end)")
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Adds the block the input describes, started from its params when it carries them. Every way the
|
|
46
|
+
* block can be refused comes back as an error result saying nothing was created.
|
|
47
|
+
*/
|
|
48
|
+
async function addBlock(deps, input) {
|
|
49
|
+
const { label, spec, params, blockIds, before } = input;
|
|
50
|
+
let blockPackSpec;
|
|
51
|
+
if (spec.type === "kind") try {
|
|
52
|
+
blockPackSpec = await deps.resolveKind(_milaboratories_pl_middle_layer.BlockKindRef.parse(spec.kind), spec.registryUrl, spec.allowUnstable ?? false);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return require_types.errorResult(`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`, "Check the kind name and version. Pass allowUnstable: true if the block is not published to the stable channel, or registryUrl if it lives in another registry.");
|
|
55
|
+
}
|
|
56
|
+
else blockPackSpec = spec;
|
|
57
|
+
try {
|
|
58
|
+
const blockId = await deps.project.addBlock(label, blockPackSpec, before, deps.author, void 0, {
|
|
59
|
+
init: params === void 0 ? void 0 : {
|
|
60
|
+
params,
|
|
61
|
+
blockIds
|
|
62
|
+
},
|
|
63
|
+
requireModelAPIVersion: require_block_api.SUPPORTED_BLOCK_API
|
|
64
|
+
});
|
|
65
|
+
return require_types.textResult({ blockId });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const unsupported = require_block_api.unsupportedBlockApiResult(e);
|
|
68
|
+
if (unsupported) return unsupported;
|
|
69
|
+
if (e instanceof _milaboratories_pl_errors.BlockInitParamsRejectedError) return require_types.errorResult(`The block did not accept the params: ${e.reason}. Nothing was created.`, "Fix the params and call add_block again. get_block_params on a configured block of the same kind shows the expected shape.");
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
4
73
|
function registerBlockTools(server, ctx) {
|
|
5
74
|
server.registerTool("add_block", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
}), zod.z.object({
|
|
19
|
-
type: zod.z.literal("dev-v2"),
|
|
20
|
-
folder: zod.z.string().describe("Path to block folder")
|
|
21
|
-
})]).describe("Block pack specification")
|
|
22
|
-
}
|
|
23
|
-
}, async ({ projectId, label, spec }) => {
|
|
24
|
-
const blockId = await (await ctx.getOpenedProject(projectId)).addBlock(label, spec, void 0, ctx.getAuthorMarker());
|
|
25
|
-
return require_types.textResult({ blockId });
|
|
75
|
+
title: "Add Block",
|
|
76
|
+
annotations: require_types.hints.additive,
|
|
77
|
+
description: "Add a block to an opened project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_params shows the params of an existing block.\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.",
|
|
78
|
+
inputSchema: addBlockInput
|
|
79
|
+
}, async (input) => {
|
|
80
|
+
const ml = ctx.requireMl();
|
|
81
|
+
return await addBlock({
|
|
82
|
+
project: await ctx.getOpenedProject(input.projectId),
|
|
83
|
+
resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
|
|
84
|
+
author: ctx.getAuthorMarker()
|
|
85
|
+
}, input);
|
|
26
86
|
});
|
|
27
87
|
server.registerTool("update_block", {
|
|
88
|
+
title: "Update Block",
|
|
89
|
+
annotations: require_types.hints.destructive,
|
|
28
90
|
description: "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.",
|
|
29
|
-
inputSchema: {
|
|
30
|
-
projectId:
|
|
31
|
-
blockId:
|
|
91
|
+
inputSchema: zod.z.object({
|
|
92
|
+
projectId: require_ids.projectIdInput.describe("Project ID (must be opened)"),
|
|
93
|
+
blockId: require_ids.blockIdInput.describe("Block ID to update"),
|
|
32
94
|
spec: zod.z.union([zod.z.object({
|
|
33
95
|
type: zod.z.literal("from-registry-v2"),
|
|
34
96
|
registryUrl: zod.z.string().describe("Registry URL"),
|
|
@@ -42,84 +104,102 @@ function registerBlockTools(server, ctx) {
|
|
|
42
104
|
folder: zod.z.string().describe("Path to block folder")
|
|
43
105
|
})]).describe("Block pack specification"),
|
|
44
106
|
resetArgs: zod.z.boolean().optional().describe("Reset block arguments to initial values (default: false)")
|
|
45
|
-
}
|
|
107
|
+
})
|
|
46
108
|
}, async ({ projectId, blockId, spec, resetArgs }) => {
|
|
47
109
|
await (await ctx.getOpenedProject(projectId)).updateBlockPack(blockId, spec, resetArgs ?? false, ctx.getAuthorMarker());
|
|
48
110
|
return require_types.textResult({ ok: true });
|
|
49
111
|
});
|
|
50
112
|
server.registerTool("remove_block", {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
113
|
+
title: "Remove Block",
|
|
114
|
+
annotations: require_types.hints.destructive,
|
|
115
|
+
description: "Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
|
|
116
|
+
inputSchema: zod.z.object({
|
|
117
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
118
|
+
blockId: require_ids.blockIdInput.describe("Block ID to remove")
|
|
119
|
+
})
|
|
56
120
|
}, async ({ projectId, blockId }) => {
|
|
57
121
|
await (await ctx.getOpenedProject(projectId)).deleteBlock(blockId, ctx.getAuthorMarker());
|
|
58
122
|
return require_types.textResult({ ok: true });
|
|
59
123
|
});
|
|
60
124
|
server.registerTool("run_block", {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
125
|
+
title: "Run Block",
|
|
126
|
+
annotations: {
|
|
127
|
+
...require_types.hints.additive,
|
|
128
|
+
destructiveHint: true
|
|
129
|
+
},
|
|
130
|
+
description: "Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.",
|
|
131
|
+
inputSchema: zod.z.object({
|
|
132
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
133
|
+
blockId: require_ids.blockIdInput.describe("Block ID to run")
|
|
134
|
+
})
|
|
66
135
|
}, async ({ projectId, blockId }) => {
|
|
67
136
|
await (await ctx.getOpenedProject(projectId)).runBlock(blockId);
|
|
68
137
|
return require_types.textResult({ ok: true });
|
|
69
138
|
});
|
|
70
139
|
server.registerTool("stop_block", {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
140
|
+
title: "Stop Block",
|
|
141
|
+
annotations: require_types.hints.destructive,
|
|
142
|
+
description: "Stop the computation of a running block. Use run_block to start it again.",
|
|
143
|
+
inputSchema: zod.z.object({
|
|
144
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
145
|
+
blockId: require_ids.blockIdInput.describe("Block ID to stop")
|
|
146
|
+
})
|
|
76
147
|
}, async ({ projectId, blockId }) => {
|
|
77
148
|
await (await ctx.getOpenedProject(projectId)).stopBlock(blockId);
|
|
78
149
|
return require_types.textResult({ ok: true });
|
|
79
150
|
});
|
|
80
151
|
server.registerTool("reorder_blocks", {
|
|
152
|
+
title: "Reorder Blocks",
|
|
153
|
+
annotations: require_types.hints.destructive,
|
|
81
154
|
description: "Reorder blocks in a project. Must provide ALL block IDs in the desired order.",
|
|
82
|
-
inputSchema: {
|
|
83
|
-
projectId:
|
|
84
|
-
blockIds: zod.z.array(
|
|
85
|
-
}
|
|
155
|
+
inputSchema: zod.z.object({
|
|
156
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
157
|
+
blockIds: zod.z.array(require_ids.blockIdInput).describe("All block IDs in the desired order")
|
|
158
|
+
})
|
|
86
159
|
}, async ({ projectId, blockIds }) => {
|
|
87
160
|
await (await ctx.getOpenedProject(projectId)).reorderBlocks(blockIds);
|
|
88
161
|
return require_types.textResult({ ok: true });
|
|
89
162
|
});
|
|
90
163
|
server.registerTool("list_available_blocks", {
|
|
164
|
+
title: "List Available Blocks",
|
|
165
|
+
annotations: require_types.hints.read,
|
|
91
166
|
description: "List available blocks from configured registries. Optional query to filter by name.",
|
|
92
|
-
inputSchema: { query: zod.z.string().optional().describe("Filter blocks by name (case-insensitive substring match)") }
|
|
167
|
+
inputSchema: zod.z.object({ query: zod.z.string().optional().describe("Filter blocks by name (case-insensitive substring match)") })
|
|
93
168
|
}, async ({ query }) => {
|
|
94
169
|
if (!ctx.callbacks.listAvailableBlocks) return require_types.errorResult("Block registry is not available.", "This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.");
|
|
95
170
|
const blocks = await ctx.callbacks.listAvailableBlocks(query);
|
|
96
171
|
return require_types.textResult(blocks);
|
|
97
172
|
});
|
|
98
173
|
server.registerTool("get_block_info", {
|
|
174
|
+
title: "Get Block Info",
|
|
175
|
+
annotations: require_types.hints.read,
|
|
99
176
|
description: "Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.",
|
|
100
|
-
inputSchema: {
|
|
177
|
+
inputSchema: zod.z.object({
|
|
101
178
|
registryUrl: zod.z.string().describe("Registry URL (from list_available_blocks)"),
|
|
102
179
|
organization: zod.z.string().describe("Organization name"),
|
|
103
180
|
name: zod.z.string().describe("Block package name"),
|
|
104
181
|
version: zod.z.string().describe("Block version")
|
|
105
|
-
}
|
|
182
|
+
})
|
|
106
183
|
}, async ({ registryUrl, organization, name, version }) => {
|
|
107
184
|
if (!ctx.callbacks.getBlockInfo) return require_types.errorResult("Block info is not available in this environment.", "Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel");
|
|
108
185
|
const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);
|
|
109
186
|
return require_types.textResult(info);
|
|
110
187
|
});
|
|
111
188
|
server.registerTool("select_block", {
|
|
189
|
+
title: "Show Block in the Application",
|
|
190
|
+
annotations: require_types.hints.idempotent,
|
|
112
191
|
description: "Navigate the desktop UI to show a specific block's interface",
|
|
113
|
-
inputSchema: {
|
|
114
|
-
projectId:
|
|
115
|
-
blockId:
|
|
116
|
-
}
|
|
192
|
+
inputSchema: zod.z.object({
|
|
193
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
194
|
+
blockId: require_ids.blockIdInput.describe("Block ID to display")
|
|
195
|
+
})
|
|
117
196
|
}, async ({ projectId, blockId }) => {
|
|
118
197
|
if (!ctx.callbacks.selectBlock) return require_types.errorResult("Failed to select the block.", "This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.");
|
|
119
198
|
await ctx.callbacks.selectBlock(projectId, blockId);
|
|
120
199
|
return require_types.textResult({ ok: true });
|
|
121
200
|
});
|
|
122
201
|
}
|
|
202
|
+
exports.addBlock = addBlock;
|
|
123
203
|
exports.registerBlockTools = registerBlockTools;
|
|
124
204
|
|
|
125
205
|
//# sourceMappingURL=blocks.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.cjs","names":["z","textResult","errorResult"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { BlockPackSpecAny } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, textResult } from \"./types\";\n\nexport function registerBlockTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"add_block\",\n {\n description:\n \"Add a block to an opened project. Spec can be from-registry-v2 (for published blocks) or dev-v2 (for local dev blocks).\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID (must be opened)\"),\n label: z.string().describe(\"Block label\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Block pack specification\"),\n },\n },\n async ({ projectId, label, spec }) => {\n const project = await ctx.getOpenedProject(projectId);\n const blockId = await project.addBlock(\n label,\n spec as BlockPackSpecAny,\n undefined,\n ctx.getAuthorMarker(),\n );\n return textResult({ blockId });\n },\n );\n\n server.registerTool(\n \"update_block\",\n {\n description:\n \"Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID (must be opened)\"),\n blockId: z.string().describe(\"Block ID to update\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Block pack specification\"),\n resetArgs: z\n .boolean()\n .optional()\n .describe(\"Reset block arguments to initial values (default: false)\"),\n },\n },\n async ({ projectId, blockId, spec, resetArgs }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.updateBlockPack(\n blockId,\n spec as BlockPackSpecAny,\n resetArgs ?? false,\n ctx.getAuthorMarker(),\n );\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"remove_block\",\n {\n description: \"Remove a block from an opened project\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID\"),\n blockId: z.string().describe(\"Block ID to remove\"),\n },\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.deleteBlock(blockId, ctx.getAuthorMarker());\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"run_block\",\n {\n description: \"Run a block. Stale upstream blocks are started automatically.\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID\"),\n blockId: z.string().describe(\"Block ID to run\"),\n },\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.runBlock(blockId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"stop_block\",\n {\n description: \"Stop a running block\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID\"),\n blockId: z.string().describe(\"Block ID to stop\"),\n },\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.stopBlock(blockId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"reorder_blocks\",\n {\n description: \"Reorder blocks in a project. Must provide ALL block IDs in the desired order.\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID\"),\n blockIds: z.array(z.string()).describe(\"All block IDs in the desired order\"),\n },\n },\n async ({ projectId, blockIds }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.reorderBlocks(blockIds);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"list_available_blocks\",\n {\n description:\n \"List available blocks from configured registries. Optional query to filter by name.\",\n inputSchema: {\n query: z\n .string()\n .optional()\n .describe(\"Filter blocks by name (case-insensitive substring match)\"),\n },\n },\n async ({ query }) => {\n if (!ctx.callbacks.listAvailableBlocks) {\n return errorResult(\n \"Block registry is not available.\",\n \"This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.\",\n );\n }\n const blocks = await ctx.callbacks.listAvailableBlocks(query);\n return textResult(blocks);\n },\n );\n\n server.registerTool(\n \"get_block_info\",\n {\n description:\n \"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.\",\n inputSchema: {\n registryUrl: z.string().describe(\"Registry URL (from list_available_blocks)\"),\n organization: z.string().describe(\"Organization name\"),\n name: z.string().describe(\"Block package name\"),\n version: z.string().describe(\"Block version\"),\n },\n },\n async ({ registryUrl, organization, name, version }) => {\n if (!ctx.callbacks.getBlockInfo) {\n return errorResult(\n \"Block info is not available in this environment.\",\n 'Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel',\n );\n }\n const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);\n return textResult(info);\n },\n );\n\n server.registerTool(\n \"select_block\",\n {\n description: \"Navigate the desktop UI to show a specific block's interface\",\n inputSchema: {\n projectId: z.string().describe(\"Project ID\"),\n blockId: z.string().describe(\"Block ID to display\"),\n },\n },\n async ({ projectId, blockId }) => {\n if (!ctx.callbacks.selectBlock) {\n return errorResult(\n \"Failed to select the block.\",\n \"This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.\",\n );\n }\n await ctx.callbacks.selectBlock(projectId, blockId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;AAMA,SAAgB,mBAAmB,QAAmB,KAAwB;CAC5E,OAAO,aACL,aACA;EACE,aACE;EACF,aAAa;GACX,WAAWA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,6BAA6B;GAC5D,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,aAAa;GACxC,MAAMA,IAAAA,EACH,MAAM,CACLA,IAAAA,EAAE,OAAO;IACP,MAAMA,IAAAA,EAAE,QAAQ,kBAAkB;IAClC,aAAaA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;IAC/C,IAAIA,IAAAA,EAAE,OAAO;KACX,cAAcA,IAAAA,EAAE,OAAO;KACvB,MAAMA,IAAAA,EAAE,OAAO;KACf,SAASA,IAAAA,EAAE,OAAO;IACpB,CAAC;GACH,CAAC,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AI,UAAU,aACjB,OAAOE,cAAAA,YACL,+BACA,oMACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAOD,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"blocks.cjs","names":["CentralBlockRegistry","z","projectIdInput","blockIdInput","BlockKindRef","errorResult","SUPPORTED_BLOCK_API","textResult","unsupportedBlockApiResult","BlockInitParamsRejectedError","hints"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport type { BlockPackSpecAny, Project } from \"@milaboratories/pl-middle-layer\";\nimport { BlockKindRef, CentralBlockRegistry } from \"@milaboratories/pl-middle-layer\";\nimport { BlockInitParamsRejectedError } from \"@milaboratories/pl-errors\";\nimport type { BlockKindReference } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { AuthorMarker, ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from \"./block-api\";\n\n/** Where a kind is resolved when the caller names no registry. */\nfunction centralBlockRegistryUrl(): string {\n if (CentralBlockRegistry.type !== \"remote-v2\")\n throw new Error(\"The central block registry is expected to be a v2 remote registry.\");\n return CentralBlockRegistry.url;\n}\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n\nconst addBlockInput = z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n label: z.string().describe(\"Block label\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"kind\"),\n kind: z\n .string()\n .describe(\n 'Block kind reference \"<package name>@<version or range>\", ' +\n 'e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\"',\n ),\n registryUrl: z\n .string()\n .optional()\n .describe(\"Registry to resolve the kind in (default: the central block registry)\"),\n allowUnstable: z\n .boolean()\n .optional()\n .describe(\"Also consider blocks not published to the stable channel\"),\n }),\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Which block to add\"),\n params: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Initialization params of the block's kind. Omit for the default state.\"),\n blockIds: z\n .record(z.string(), blockIdInput)\n .optional()\n .describe(\n \"Ids used inside `params` in place of block ids, each mapped to a block id of this \" +\n \"project. Needed only when `params` do not already hold ids of this project.\",\n ),\n before: blockIdInput\n .optional()\n .describe(\"ID of the block to insert the new block before (default: add at the end)\"),\n});\n\n/** Input of the `add_block` tool. */\nexport type AddBlockInput = z.infer<typeof addBlockInput>;\n\n/** What `add_block` needs from the application. */\nexport type AddBlockDeps = {\n project: Pick<Project, \"addBlock\">;\n /** Resolves a kind reference to the block implementing it; throws when there is none. */\n resolveKind: (\n kind: BlockKindReference,\n registryUrl: string | undefined,\n allowUnstable: boolean,\n ) => Promise<BlockPackSpecAny>;\n author: AuthorMarker;\n};\n\n/**\n * Adds the block the input describes, started from its params when it carries them. Every way the\n * block can be refused comes back as an error result saying nothing was created.\n */\nexport async function addBlock(deps: AddBlockDeps, input: AddBlockInput) {\n const { label, spec, params, blockIds, before } = input;\n\n let blockPackSpec: BlockPackSpecAny;\n if (spec.type === \"kind\") {\n try {\n blockPackSpec = await deps.resolveKind(\n BlockKindRef.parse(spec.kind),\n spec.registryUrl,\n spec.allowUnstable ?? false,\n );\n } catch (e: unknown) {\n return errorResult(\n `Kind \"${spec.kind}\" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`,\n \"Check the kind name and version. Pass allowUnstable: true if the block is not \" +\n \"published to the stable channel, or registryUrl if it lives in another registry.\",\n );\n }\n } else {\n blockPackSpec = spec;\n }\n\n try {\n const blockId = await deps.project.addBlock(\n label,\n blockPackSpec,\n before,\n deps.author,\n undefined,\n {\n init: params === undefined ? undefined : { params, blockIds },\n requireModelAPIVersion: SUPPORTED_BLOCK_API,\n },\n );\n return textResult({ blockId });\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return unsupported;\n if (e instanceof BlockInitParamsRejectedError)\n return errorResult(\n `The block did not accept the params: ${e.reason}. Nothing was created.`,\n \"Fix the params and call add_block again. get_block_params on a configured block \" +\n \"of the same kind shows the expected shape.\",\n );\n throw e;\n }\n}\n\nexport function registerBlockTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"add_block\",\n {\n title: \"Add Block\",\n annotations: hints.additive,\n description:\n \"Add a block to an opened project, optionally configured from initialization params.\\n\\n\" +\n \"`spec` names the block: `kind` (a block kind reference, resolved to the newest block \" +\n \"implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev \" +\n \"block folder).\\n\\n\" +\n \"`params` are the initialization params of the block's kind: the block's own model checks \" +\n \"them and builds its initial state from them. Without `params` the block starts in its \" +\n \"default state. get_block_params shows the params of an existing block.\\n\\n\" +\n \"References to other blocks inside `params` must hold real block ids of this project, \" +\n \"copied from tool results. Params copied from another project or a template hold other \" +\n \"ids: map each of them to a block of this project with `blockIds`.\\n\\n\" +\n \"Only blocks on the current block API can be added. On any error nothing is created.\",\n inputSchema: addBlockInput,\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await addBlock(\n {\n project: await ctx.getOpenedProject(input.projectId),\n resolveKind: (kind, registryUrl, allowUnstable) =>\n ml.blockRegistryProvider\n .getRegistry(registryUrl ?? centralBlockRegistryUrl())\n .resolveKind(kind, { allowUnstable }),\n author: ctx.getAuthorMarker(),\n },\n input,\n );\n },\n );\n\n server.registerTool(\n \"update_block\",\n {\n title: \"Update Block\",\n annotations: hints.destructive,\n description:\n \"Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n blockId: blockIdInput.describe(\"Block ID to update\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Block pack specification\"),\n resetArgs: z\n .boolean()\n .optional()\n .describe(\"Reset block arguments to initial values (default: false)\"),\n }),\n },\n async ({ projectId, blockId, spec, resetArgs }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.updateBlockPack(\n blockId,\n spec as BlockPackSpecAny,\n resetArgs ?? false,\n ctx.getAuthorMarker(),\n );\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"remove_block\",\n {\n title: \"Remove Block\",\n annotations: hints.destructive,\n description:\n \"Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to remove\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.deleteBlock(blockId, ctx.getAuthorMarker());\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"run_block\",\n {\n title: \"Run Block\",\n // Starts work like an additive tool, but replaces results and stops blocks computing below.\n annotations: { ...hints.additive, destructiveHint: true },\n description:\n \"Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to run\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.runBlock(blockId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"stop_block\",\n {\n title: \"Stop Block\",\n annotations: hints.destructive,\n description: \"Stop the computation of a running block. Use run_block to start it again.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to stop\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.stopBlock(blockId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"reorder_blocks\",\n {\n title: \"Reorder Blocks\",\n annotations: hints.destructive,\n description: \"Reorder blocks in a project. Must provide ALL block IDs in the desired order.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockIds: z.array(blockIdInput).describe(\"All block IDs in the desired order\"),\n }),\n },\n async ({ projectId, blockIds }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.reorderBlocks(blockIds);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"list_available_blocks\",\n {\n title: \"List Available Blocks\",\n annotations: hints.read,\n description:\n \"List available blocks from configured registries. Optional query to filter by name.\",\n inputSchema: z.object({\n query: z\n .string()\n .optional()\n .describe(\"Filter blocks by name (case-insensitive substring match)\"),\n }),\n },\n async ({ query }) => {\n if (!ctx.callbacks.listAvailableBlocks) {\n return errorResult(\n \"Block registry is not available.\",\n \"This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.\",\n );\n }\n const blocks = await ctx.callbacks.listAvailableBlocks(query);\n return textResult(blocks);\n },\n );\n\n server.registerTool(\n \"get_block_info\",\n {\n title: \"Get Block Info\",\n annotations: hints.read,\n description:\n \"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.\",\n inputSchema: z.object({\n registryUrl: z.string().describe(\"Registry URL (from list_available_blocks)\"),\n organization: z.string().describe(\"Organization name\"),\n name: z.string().describe(\"Block package name\"),\n version: z.string().describe(\"Block version\"),\n }),\n },\n async ({ registryUrl, organization, name, version }) => {\n if (!ctx.callbacks.getBlockInfo) {\n return errorResult(\n \"Block info is not available in this environment.\",\n 'Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel',\n );\n }\n const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);\n return textResult(info);\n },\n );\n\n server.registerTool(\n \"select_block\",\n {\n title: \"Show Block in the Application\",\n annotations: hints.idempotent,\n description: \"Navigate the desktop UI to show a specific block's interface\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to display\"),\n }),\n },\n async ({ projectId, blockId }) => {\n if (!ctx.callbacks.selectBlock) {\n return errorResult(\n \"Failed to select the block.\",\n \"This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.\",\n );\n }\n await ctx.callbacks.selectBlock(projectId, blockId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAYA,SAAS,0BAAkC;CACzC,IAAIA,gCAAAA,qBAAqB,SAAS,aAChC,MAAM,IAAI,MAAM,oEAAoE;CACtF,OAAOA,gCAAAA,qBAAqB;AAC9B;AAEA,SAAS,aAAa,GAAoB;CACxC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD;AAEA,MAAM,gBAAgBC,IAAAA,EAAE,OAAO;CAC7B,WAAWC,YAAAA,eAAe,SAAS,6BAA6B;CAChE,OAAOD,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,aAAa;CACxC,MAAMA,IAAAA,EACH,MAAM;EACLA,IAAAA,EAAE,OAAO;GACP,MAAMA,IAAAA,EAAE,QAAQ,MAAM;GACtB,MAAMA,IAAAA,EACH,OAAO,CAAC,CACR,SACC,iIAEF;GACF,aAAaA,IAAAA,EACV,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,uEAAuE;GACnF,eAAeA,IAAAA,EACZ,QAAQ,CAAC,CACT,SAAS,CAAC,CACV,SAAS,0DAA0D;EACxE,CAAC;EACDA,IAAAA,EAAE,OAAO;GACP,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,EAAE,OAAO,CAAC,CAAC,SAAS,mBAAmB;GACrD,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,oBAAoB;GAC9C,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,eAAe;EAC9C,CAAC;CACH,GACA,OAAO,EAAE,aAAa,cAAc,MAAM,cAAc;EACtD,IAAI,CAAC,IAAI,UAAU,cACjB,OAAOI,cAAAA,YACL,oDACA,2KACF;EAEF,MAAM,OAAO,MAAM,IAAI,UAAU,aAAa,aAAa,cAAc,MAAM,OAAO;EACtF,OAAOE,cAAAA,WAAW,IAAI;CACxB,CACF;CAEA,OAAO,aACL,gBACA;EACE,OAAO;EACP,aAAaG,cAAAA,MAAM;EACnB,aAAa;EACb,aAAaT,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,qBAAqB;EACtD,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAOE,cAAAA,YACL,+BACA,oMACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAOE,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
|
package/dist/tools/blocks.js
CHANGED
|
@@ -1,34 +1,96 @@
|
|
|
1
|
-
import { errorResult, textResult } from "./types.js";
|
|
1
|
+
import { errorResult, hints, textResult } from "./types.js";
|
|
2
|
+
import { blockIdInput, projectIdInput } from "./ids.js";
|
|
3
|
+
import { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from "./block-api.js";
|
|
2
4
|
import { z } from "zod";
|
|
5
|
+
import { BlockKindRef, CentralBlockRegistry } from "@milaboratories/pl-middle-layer";
|
|
6
|
+
import { BlockInitParamsRejectedError } from "@milaboratories/pl-errors";
|
|
3
7
|
// src/tools/blocks.ts
|
|
8
|
+
/** Where a kind is resolved when the caller names no registry. */
|
|
9
|
+
function centralBlockRegistryUrl() {
|
|
10
|
+
if (CentralBlockRegistry.type !== "remote-v2") throw new Error("The central block registry is expected to be a v2 remote registry.");
|
|
11
|
+
return CentralBlockRegistry.url;
|
|
12
|
+
}
|
|
13
|
+
function errorMessage(e) {
|
|
14
|
+
return e instanceof Error ? e.message : String(e);
|
|
15
|
+
}
|
|
16
|
+
const addBlockInput = z.object({
|
|
17
|
+
projectId: projectIdInput.describe("Project ID (must be opened)"),
|
|
18
|
+
label: z.string().describe("Block label"),
|
|
19
|
+
spec: z.union([
|
|
20
|
+
z.object({
|
|
21
|
+
type: z.literal("kind"),
|
|
22
|
+
kind: z.string().describe("Block kind reference \"<package name>@<version or range>\", e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\""),
|
|
23
|
+
registryUrl: z.string().optional().describe("Registry to resolve the kind in (default: the central block registry)"),
|
|
24
|
+
allowUnstable: z.boolean().optional().describe("Also consider blocks not published to the stable channel")
|
|
25
|
+
}),
|
|
26
|
+
z.object({
|
|
27
|
+
type: z.literal("from-registry-v2"),
|
|
28
|
+
registryUrl: z.string().describe("Registry URL"),
|
|
29
|
+
id: z.object({
|
|
30
|
+
organization: z.string(),
|
|
31
|
+
name: z.string(),
|
|
32
|
+
version: z.string()
|
|
33
|
+
})
|
|
34
|
+
}),
|
|
35
|
+
z.object({
|
|
36
|
+
type: z.literal("dev-v2"),
|
|
37
|
+
folder: z.string().describe("Path to block folder")
|
|
38
|
+
})
|
|
39
|
+
]).describe("Which block to add"),
|
|
40
|
+
params: z.record(z.string(), z.unknown()).optional().describe("Initialization params of the block's kind. Omit for the default state."),
|
|
41
|
+
blockIds: z.record(z.string(), blockIdInput).optional().describe("Ids used inside `params` in place of block ids, each mapped to a block id of this project. Needed only when `params` do not already hold ids of this project."),
|
|
42
|
+
before: blockIdInput.optional().describe("ID of the block to insert the new block before (default: add at the end)")
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Adds the block the input describes, started from its params when it carries them. Every way the
|
|
46
|
+
* block can be refused comes back as an error result saying nothing was created.
|
|
47
|
+
*/
|
|
48
|
+
async function addBlock(deps, input) {
|
|
49
|
+
const { label, spec, params, blockIds, before } = input;
|
|
50
|
+
let blockPackSpec;
|
|
51
|
+
if (spec.type === "kind") try {
|
|
52
|
+
blockPackSpec = await deps.resolveKind(BlockKindRef.parse(spec.kind), spec.registryUrl, spec.allowUnstable ?? false);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return errorResult(`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`, "Check the kind name and version. Pass allowUnstable: true if the block is not published to the stable channel, or registryUrl if it lives in another registry.");
|
|
55
|
+
}
|
|
56
|
+
else blockPackSpec = spec;
|
|
57
|
+
try {
|
|
58
|
+
const blockId = await deps.project.addBlock(label, blockPackSpec, before, deps.author, void 0, {
|
|
59
|
+
init: params === void 0 ? void 0 : {
|
|
60
|
+
params,
|
|
61
|
+
blockIds
|
|
62
|
+
},
|
|
63
|
+
requireModelAPIVersion: SUPPORTED_BLOCK_API
|
|
64
|
+
});
|
|
65
|
+
return textResult({ blockId });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const unsupported = unsupportedBlockApiResult(e);
|
|
68
|
+
if (unsupported) return unsupported;
|
|
69
|
+
if (e instanceof BlockInitParamsRejectedError) return errorResult(`The block did not accept the params: ${e.reason}. Nothing was created.`, "Fix the params and call add_block again. get_block_params on a configured block of the same kind shows the expected shape.");
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
4
73
|
function registerBlockTools(server, ctx) {
|
|
5
74
|
server.registerTool("add_block", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
}), z.object({
|
|
19
|
-
type: z.literal("dev-v2"),
|
|
20
|
-
folder: z.string().describe("Path to block folder")
|
|
21
|
-
})]).describe("Block pack specification")
|
|
22
|
-
}
|
|
23
|
-
}, async ({ projectId, label, spec }) => {
|
|
24
|
-
const blockId = await (await ctx.getOpenedProject(projectId)).addBlock(label, spec, void 0, ctx.getAuthorMarker());
|
|
25
|
-
return textResult({ blockId });
|
|
75
|
+
title: "Add Block",
|
|
76
|
+
annotations: hints.additive,
|
|
77
|
+
description: "Add a block to an opened project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_params shows the params of an existing block.\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.",
|
|
78
|
+
inputSchema: addBlockInput
|
|
79
|
+
}, async (input) => {
|
|
80
|
+
const ml = ctx.requireMl();
|
|
81
|
+
return await addBlock({
|
|
82
|
+
project: await ctx.getOpenedProject(input.projectId),
|
|
83
|
+
resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
|
|
84
|
+
author: ctx.getAuthorMarker()
|
|
85
|
+
}, input);
|
|
26
86
|
});
|
|
27
87
|
server.registerTool("update_block", {
|
|
88
|
+
title: "Update Block",
|
|
89
|
+
annotations: hints.destructive,
|
|
28
90
|
description: "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.",
|
|
29
|
-
inputSchema: {
|
|
30
|
-
projectId:
|
|
31
|
-
blockId:
|
|
91
|
+
inputSchema: z.object({
|
|
92
|
+
projectId: projectIdInput.describe("Project ID (must be opened)"),
|
|
93
|
+
blockId: blockIdInput.describe("Block ID to update"),
|
|
32
94
|
spec: z.union([z.object({
|
|
33
95
|
type: z.literal("from-registry-v2"),
|
|
34
96
|
registryUrl: z.string().describe("Registry URL"),
|
|
@@ -42,84 +104,101 @@ function registerBlockTools(server, ctx) {
|
|
|
42
104
|
folder: z.string().describe("Path to block folder")
|
|
43
105
|
})]).describe("Block pack specification"),
|
|
44
106
|
resetArgs: z.boolean().optional().describe("Reset block arguments to initial values (default: false)")
|
|
45
|
-
}
|
|
107
|
+
})
|
|
46
108
|
}, async ({ projectId, blockId, spec, resetArgs }) => {
|
|
47
109
|
await (await ctx.getOpenedProject(projectId)).updateBlockPack(blockId, spec, resetArgs ?? false, ctx.getAuthorMarker());
|
|
48
110
|
return textResult({ ok: true });
|
|
49
111
|
});
|
|
50
112
|
server.registerTool("remove_block", {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
113
|
+
title: "Remove Block",
|
|
114
|
+
annotations: hints.destructive,
|
|
115
|
+
description: "Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
|
|
116
|
+
inputSchema: z.object({
|
|
117
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
118
|
+
blockId: blockIdInput.describe("Block ID to remove")
|
|
119
|
+
})
|
|
56
120
|
}, async ({ projectId, blockId }) => {
|
|
57
121
|
await (await ctx.getOpenedProject(projectId)).deleteBlock(blockId, ctx.getAuthorMarker());
|
|
58
122
|
return textResult({ ok: true });
|
|
59
123
|
});
|
|
60
124
|
server.registerTool("run_block", {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
125
|
+
title: "Run Block",
|
|
126
|
+
annotations: {
|
|
127
|
+
...hints.additive,
|
|
128
|
+
destructiveHint: true
|
|
129
|
+
},
|
|
130
|
+
description: "Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.",
|
|
131
|
+
inputSchema: z.object({
|
|
132
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
133
|
+
blockId: blockIdInput.describe("Block ID to run")
|
|
134
|
+
})
|
|
66
135
|
}, async ({ projectId, blockId }) => {
|
|
67
136
|
await (await ctx.getOpenedProject(projectId)).runBlock(blockId);
|
|
68
137
|
return textResult({ ok: true });
|
|
69
138
|
});
|
|
70
139
|
server.registerTool("stop_block", {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
140
|
+
title: "Stop Block",
|
|
141
|
+
annotations: hints.destructive,
|
|
142
|
+
description: "Stop the computation of a running block. Use run_block to start it again.",
|
|
143
|
+
inputSchema: z.object({
|
|
144
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
145
|
+
blockId: blockIdInput.describe("Block ID to stop")
|
|
146
|
+
})
|
|
76
147
|
}, async ({ projectId, blockId }) => {
|
|
77
148
|
await (await ctx.getOpenedProject(projectId)).stopBlock(blockId);
|
|
78
149
|
return textResult({ ok: true });
|
|
79
150
|
});
|
|
80
151
|
server.registerTool("reorder_blocks", {
|
|
152
|
+
title: "Reorder Blocks",
|
|
153
|
+
annotations: hints.destructive,
|
|
81
154
|
description: "Reorder blocks in a project. Must provide ALL block IDs in the desired order.",
|
|
82
|
-
inputSchema: {
|
|
83
|
-
projectId:
|
|
84
|
-
blockIds: z.array(
|
|
85
|
-
}
|
|
155
|
+
inputSchema: z.object({
|
|
156
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
157
|
+
blockIds: z.array(blockIdInput).describe("All block IDs in the desired order")
|
|
158
|
+
})
|
|
86
159
|
}, async ({ projectId, blockIds }) => {
|
|
87
160
|
await (await ctx.getOpenedProject(projectId)).reorderBlocks(blockIds);
|
|
88
161
|
return textResult({ ok: true });
|
|
89
162
|
});
|
|
90
163
|
server.registerTool("list_available_blocks", {
|
|
164
|
+
title: "List Available Blocks",
|
|
165
|
+
annotations: hints.read,
|
|
91
166
|
description: "List available blocks from configured registries. Optional query to filter by name.",
|
|
92
|
-
inputSchema: { query: z.string().optional().describe("Filter blocks by name (case-insensitive substring match)") }
|
|
167
|
+
inputSchema: z.object({ query: z.string().optional().describe("Filter blocks by name (case-insensitive substring match)") })
|
|
93
168
|
}, async ({ query }) => {
|
|
94
169
|
if (!ctx.callbacks.listAvailableBlocks) return errorResult("Block registry is not available.", "This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.");
|
|
95
170
|
const blocks = await ctx.callbacks.listAvailableBlocks(query);
|
|
96
171
|
return textResult(blocks);
|
|
97
172
|
});
|
|
98
173
|
server.registerTool("get_block_info", {
|
|
174
|
+
title: "Get Block Info",
|
|
175
|
+
annotations: hints.read,
|
|
99
176
|
description: "Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.",
|
|
100
|
-
inputSchema: {
|
|
177
|
+
inputSchema: z.object({
|
|
101
178
|
registryUrl: z.string().describe("Registry URL (from list_available_blocks)"),
|
|
102
179
|
organization: z.string().describe("Organization name"),
|
|
103
180
|
name: z.string().describe("Block package name"),
|
|
104
181
|
version: z.string().describe("Block version")
|
|
105
|
-
}
|
|
182
|
+
})
|
|
106
183
|
}, async ({ registryUrl, organization, name, version }) => {
|
|
107
184
|
if (!ctx.callbacks.getBlockInfo) return errorResult("Block info is not available in this environment.", "Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel");
|
|
108
185
|
const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);
|
|
109
186
|
return textResult(info);
|
|
110
187
|
});
|
|
111
188
|
server.registerTool("select_block", {
|
|
189
|
+
title: "Show Block in the Application",
|
|
190
|
+
annotations: hints.idempotent,
|
|
112
191
|
description: "Navigate the desktop UI to show a specific block's interface",
|
|
113
|
-
inputSchema: {
|
|
114
|
-
projectId:
|
|
115
|
-
blockId:
|
|
116
|
-
}
|
|
192
|
+
inputSchema: z.object({
|
|
193
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
194
|
+
blockId: blockIdInput.describe("Block ID to display")
|
|
195
|
+
})
|
|
117
196
|
}, async ({ projectId, blockId }) => {
|
|
118
197
|
if (!ctx.callbacks.selectBlock) return errorResult("Failed to select the block.", "This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.");
|
|
119
198
|
await ctx.callbacks.selectBlock(projectId, blockId);
|
|
120
199
|
return textResult({ ok: true });
|
|
121
200
|
});
|
|
122
201
|
}
|
|
123
|
-
export { registerBlockTools };
|
|
202
|
+
export { addBlock, registerBlockTools };
|
|
124
203
|
|
|
125
204
|
//# sourceMappingURL=blocks.js.map
|